Commit a57b7db2 authored by Matija Obreza's avatar Matija Obreza
Browse files

Stats on pheno

parent 629af0f0
......@@ -16,6 +16,7 @@
package org.genesys2.server.model.genesys;
import java.util.List;
import java.util.UUID;
import javax.persistence.Column;
......@@ -23,6 +24,7 @@ import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;
......@@ -45,6 +47,9 @@ public class AccessionId extends VersionedAuditedModel implements IdUUID {
@OneToOne(cascade = {}, fetch = FetchType.LAZY, mappedBy = "accession", optional = true, orphanRemoval = true)
private PDCI pdci;
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "accession", orphanRemoval = false)
private List<AccessionTrait> traits;
@PrePersist
private void prepersist() {
if (uuid == null) {
......@@ -68,4 +73,12 @@ public class AccessionId extends VersionedAuditedModel implements IdUUID {
public void setPdci(PDCI pdci) {
this.pdci = pdci;
}
//
// public List<AccessionTrait> getTraits() {
// return traits;
// }
//
// public void setTraits(List<AccessionTrait> traits) {
// this.traits = traits;
// }
}
/**
* Copyright 2015 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.model.genesys;
import java.io.Serializable;
/**
* Statistics for phenotypic data
*/
public class PhenoStatistics implements Serializable {
private long count;
private long withMethod;
private long witMetadata;
private float avgMethods;
private float avgMetadatas;
public void setCount(long count) {
this.count = count;
}
public long getCount() {
return count;
}
public void setWithMethod(long withMethod) {
this.withMethod = withMethod;
}
public long getWithMethod() {
return withMethod;
}
public float getWithMethodPercent() {
return (float) withMethod / count;
}
public void setWithMetadata(long withMetadata) {
this.witMetadata = withMetadata;
}
public long getWitMetadata() {
return witMetadata;
}
public float getWithMetadataPercent() {
return (float) witMetadata / count;
}
public void setAvgMethods(float avg) {
this.avgMethods = avg;
}
public float getAvgMethods() {
return avgMethods;
}
public void setAvgMetadatas(float avg) {
this.avgMetadatas = avg;
}
public float getAvgMetadatas() {
return avgMetadatas;
}
public Object[] getElStats() {
return new Object[] { count, withMethod, getWithMethodPercent(), avgMethods, avgMetadatas };
}
}
......@@ -21,6 +21,7 @@ import java.util.List;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.genesys.AccessionTrait;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
......@@ -49,4 +50,10 @@ public interface AccessionTraitRepository extends JpaRepository<AccessionTrait,
@Query("delete from AccessionTrait where accession = ?1 and metadataId= ?2 and methodId = ?3")
void deleteByAccessionAndMetadataIdAndMethodId(AccessionId accession, long metadataId, long methodId);
@Query("select a.id, count(distinct at.methodId) from Accession a join a.accessionId.traits at where a.institute = ?1 group by a.id")
List<Object[]> statisticsAccessionMethod(FaoInstitute faoInstitute);
@Query("select a.id, count(distinct at.metadataId) from Accession a join a.accessionId.traits at where a.institute = ?1 group by a.id")
List<Object[]> statisticsAccessionMetadata(FaoInstitute faoInstitute);
}
......@@ -41,6 +41,7 @@ import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.PDCI;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.genesys.PhenoStatistics;
import org.genesys2.server.model.genesys.SvalbardData;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.AccessionIdentifier3;
......@@ -243,4 +244,6 @@ public interface GenesysService {
PDCIStatistics statisticsPDCI(Organization organization);
PhenoStatistics statisticsPheno(FaoInstitute faoInstitute);
}
......@@ -16,7 +16,10 @@
package org.genesys2.server.service;
import java.util.List;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.genesys.PhenoStatistics;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
......@@ -32,4 +35,6 @@ public interface StatisticsService {
PDCIStatistics statisticsPDCI(Organization organization);
PhenoStatistics statisticsPheno(FaoInstitute faoInstitute);
}
......@@ -62,6 +62,7 @@ import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.PDCI;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.genesys.PhenoStatistics;
import org.genesys2.server.model.genesys.SelfCopy;
import org.genesys2.server.model.genesys.SvalbardData;
import org.genesys2.server.model.genesys.Taxonomy2;
......@@ -1675,7 +1676,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
public PDCIStatistics statisticsPDCI(Organization organization) {
PDCIStatistics stats = new PDCIStatistics();
for (FaoInstitute faoInstitute : organizationService.getMembers(organization)) {
Object[] overall = (Object[]) repoPdci.statistics(faoInstitute);
if (overall == null) {
......@@ -1692,4 +1693,42 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
return stats;
}
@Override
public PhenoStatistics statisticsPheno(FaoInstitute faoInstitute) {
List<Object[]> metadatas = accessionTraitRepository.statisticsAccessionMetadata(faoInstitute);
List<Object[]> methods = accessionTraitRepository.statisticsAccessionMethod(faoInstitute);
long count = countByInstitute(faoInstitute);
PhenoStatistics stats = new PhenoStatistics();
stats.setCount(count);
{
long withMetadata = 0, metadatasTotal = 0;
for (Object[] m : metadatas) {
// Long accessionId = (Long) m[0];
Long metadataCount = (Long) m[1];
if (metadataCount != null && metadataCount > 0) {
withMetadata++;
metadatasTotal += metadataCount;
}
}
stats.setWithMetadata(withMetadata);
stats.setAvgMetadatas((float) metadatasTotal / withMetadata);
}
{
long withMethod = 0, methodsTotal = 0;
for (Object[] m : methods) {
// Long accessionId = (Long) m[0];
Long methodCount = (Long) m[1];
if (methodCount != null && methodCount > 0) {
withMethod++;
methodsTotal += methodCount;
}
}
stats.setWithMethod(withMethod);
stats.setAvgMethods((float) methodsTotal / withMethod);
}
return stats;
}
}
......@@ -19,6 +19,7 @@ package org.genesys2.server.service.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.genesys.PhenoStatistics;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.GenesysService;
......@@ -70,7 +71,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
return genesysService.statisticsPDCI(faoInstitute);
}
@Override
@Cacheable(unless = "#result == null", value = "statistics", key = "'stats.' + #root.methodName + '-org' + #organization.id")
public PDCIStatistics statisticsPDCI(Organization organization) {
......@@ -79,4 +80,14 @@ public class StatisticsServiceImpl implements StatisticsService {
}
return genesysService.statisticsPDCI(organization);
}
@Override
@Cacheable(unless = "#result == null", value = "statistics", key = "'stats.' + #root.methodName + '-' + #faoInstitute.id")
public PhenoStatistics statisticsPheno(FaoInstitute faoInstitute) {
if (LOG.isDebugEnabled()) {
LOG.debug("Regenerating C&E statistics for " + faoInstitute);
}
return genesysService.statisticsPheno(faoInstitute);
}
}
......@@ -125,15 +125,17 @@ public class WiewsController extends BaseController {
model.addAttribute("blurp", contentService.getArticle(faoInstitute, "blurp", getLocale()));
model.addAttribute("countByInstitute", genesysService.countByInstitute(faoInstitute));
model.addAttribute("datasetCount", genesysService.countDatasets(faoInstitute));
// model.addAttribute("statisticsCrop",
// genesysService.statisticsCropByInstitute(faoInstitute, new
// PageRequest(0, 30)));
long datasetCount = genesysService.countDatasets(faoInstitute);
model.addAttribute("datasetCount", datasetCount);
model.addAttribute("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute, new PageRequest(0, 30)));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsSpeciesByInstitute(faoInstitute, new PageRequest(0, 30)));
model.addAttribute("statisticsPDCI", statisticsService.statisticsPDCI(faoInstitute));
if (datasetCount > 0) {
model.addAttribute("statisticsPheno", statisticsService.statisticsPheno(faoInstitute));
}
return "/wiews/details";
}
......
......@@ -637,3 +637,4 @@ accession.svalbard-data.url-title=Deposit information in SGSV database
accession.svalbard-data.url-text=View SGSV deposit information for {0}
filter.download-pdci=Download PDCI data
statistics.phenotypic.stats-text=Of the {0} accessions, {1} accessions ({2,number,0.##%}) have at least one additional trait recorded in a dataset available on Genesys (on average {3,number,0.##} traits in {4,number,0.##} datasets).
......@@ -48,6 +48,7 @@
<br />
<spring:message code="faoInstitutes.stat.datasetCount" arguments="${datasetCount}" />
<c:if test="${datasetCount gt 0}">
<spring:message code="statistics.phenotypic.stats-text" arguments="${statisticsPheno.elStats}" />
<a title="<spring:message code="faoInstitute.datasets-title" arguments="${faoInstitute.fullName}" />"
href="<c:url value="/wiews/${faoInstitute.code}/datasets" />"
><spring:message code="view.datasets" /></a>
......@@ -213,7 +214,9 @@
<h3>
<spring:message code="accession.pdci" />
</h3>
<p><spring:message code="accession.pdci.stats-text" arguments="${statisticsPDCI.elStats}" /></p>
<p>
<spring:message code="accession.pdci.stats-text" arguments="${statisticsPDCI.elStats}" />
</p>
<div class="chart chart-histogram">
<div id="chartPDCI" style="height: 200px"></div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment