Commit 2a7dd795 authored by Matija Obreza's avatar Matija Obreza

Institute statistics updated, working on issue #8

parent 2fe4a23d
......@@ -17,14 +17,18 @@
package org.genesys2.server.model.genesys;
import java.text.MessageFormat;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
......@@ -32,8 +36,7 @@ import org.hibernate.search.annotations.Store;
@Entity
// Add index on genus, genus+species
@Table(name = "all_taxonomy", uniqueConstraints = { @UniqueConstraint(columnNames = {
"Taxon_Name" }) })
@Table(name = "all_taxonomy", uniqueConstraints = { @UniqueConstraint(columnNames = { "Taxon_Name" }) })
@Indexed
public class Taxonomy implements java.io.Serializable {
......@@ -42,19 +45,22 @@ public class Taxonomy implements java.io.Serializable {
@Id
@DocumentId
@GeneratedValue
@Column(name="Taxon_Code", unique = true, nullable = false)
@Column(name = "Taxon_Code", unique = true, nullable = false)
private Long id;
@Column(nullable = false, length = 64)
private String genus;
@Column(nullable = false, length = 64)
private String species;
@Column(name="Taxon_Name", nullable = false, length = 200)
@Field(name="title", store=Store.NO)
@Column(name = "Taxon_Name", nullable = false, length = 200)
@Field(name = "title", store = Store.NO)
private String taxonName;
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "taxonomy")
private List<CropTaxonomy> cropTaxonomies;
public Taxonomy() {
}
......@@ -63,7 +69,6 @@ public class Taxonomy implements java.io.Serializable {
this.species = species;
}
public Long getId() {
return this.id;
}
......@@ -96,10 +101,17 @@ public class Taxonomy implements java.io.Serializable {
this.taxonName = taxonName;
}
public List<CropTaxonomy> getCropTaxonomies() {
return cropTaxonomies;
}
public void setCropTaxonomies(List<CropTaxonomy> cropTaxonomies) {
this.cropTaxonomies = cropTaxonomies;
}
@Override
public String toString() {
return MessageFormat.format("Tax id={0} genus={1} sp={2}, full={3}",
id, genus, species, taxonName);
return MessageFormat.format("Tax id={0} genus={1} sp={2}, full={3}", id, genus, species, taxonName);
}
}
......@@ -43,6 +43,10 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select taxonomy, count(a) from Accession a where a.institute = ?1 group by a.taxonomy order by count(a) desc")
Page<Object[]> statisticsTaxonomyInInstitute(FaoInstitute institute, Pageable pageable);
// FIXME Slow query
@Query("select ct.crop, count(a) from Accession a join a.taxonomy t join t.cropTaxonomies ct where a.institute = ?1 group by ct.crop order by count(a) desc")
Page<Object[]> statisticsCropInInstitute(FaoInstitute institute, Pageable pageable);
@Query("select count(a) from Accession a where a.origin = ?1")
long countByOrigin(String isoCode3);
......
......@@ -90,6 +90,8 @@ public interface GenesysService {
Page<Object[]> statisticsTaxonomyByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Object[]> statisticsCropByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Accession> listAccessionsByInstituteAndTaxonomy(FaoInstitute institute, Taxonomy taxonomy, Pageable pageable);
Page<Accession> listAccessionsByTaxonomy(Taxonomy taxonomy, Pageable pageable);
......
......@@ -253,6 +253,11 @@ public class GenesysServiceImpl implements GenesysService, TraitService {
public Page<Object[]> statisticsTaxonomyByInstitute(FaoInstitute institute, Pageable pageable) {
return accessionRepository.statisticsTaxonomyInInstitute(institute, pageable);
}
@Override
public Page<Object[]> statisticsCropByInstitute(FaoInstitute institute, Pageable pageable) {
return accessionRepository.statisticsCropInInstitute(institute, pageable);
}
@Override
public Page<Accession> listAccessionsByInstituteAndTaxonomy(FaoInstitute institute, Taxonomy taxonomy, Pageable pageable) {
......
......@@ -84,6 +84,9 @@ public class WiewsController extends BaseController {
model.addAttribute("blurp", contentService.getArticle(faoInstitute, "blurp", getLocale()));
model.addAttribute("countByInstitute", genesysService.countByInstitute(faoInstitute));
// model.addAttribute("statisticsCrop",
// genesysService.statisticsCropByInstitute(faoInstitute, new
// PageRequest(0, 30)));
model.addAttribute("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute, new PageRequest(0, 30)));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsTaxonomyByInstitute(faoInstitute, new PageRequest(0, 30)));
......
......@@ -111,6 +111,9 @@ country.more-information=More information:
faoInstitutes.page.list.title=WIEWS Institutes
faoInstitutes.page.profile.title=WIEWS {0}
faoInstitutes.stat.accessionCount=Accessions in Genesys: {0}.
faoInstitute.stat-by-crop=Most represented Crops
faoInstitute.stat-by-genus=Most represented Genera
faoInstitute.stat-by-species=Most represented Species
faoInstitute.accessionCount={0} accessions
faoInstitute.statistics=Institute statistics
faoInstitutes.page.data.title=Accessions in {0}
......
......@@ -86,17 +86,19 @@
<div class="row" style="margin-top: 2em;">
<c:if test="${statisticsCrop ne null}">
<div class="col-sm-4">
<h4>Top ${statisticsTaxonomy.numberOfElements} by Crop</h4>
<h4><spring:message code="faoInstitute.stat-by-crop" arguments="${statisticsCrop.numberOfElements}" /></h4>
<ul class="funny-list statistics">
<%-- <c:forEach items="${statisticsTaxonomy.content}" var="stat" varStatus="status">
<li class="clearfix ${status.count % 2 == 0 ? 'even' : 'odd'}"><span class="stats-number"><fmt:formatNumber value="${stat[1]}" /></span> <a href="<c:url value="/wiews/${faoInstitute.code.toLowerCase()}/t/${stat[0].genus}/${stat[0].species}" />"><c:out value="${stat[0].taxonName}" /></a></li>
</c:forEach> --%>
<c:forEach items="${statisticsCrop.content}" var="stat" varStatus="status">
<li class="clearfix ${status.count % 2 == 0 ? 'even' : 'odd'}"><span class="stats-number"><fmt:formatNumber value="${stat[1]}" /></span> <a href="<c:url value="/wiews/${faoInstitute.code.toLowerCase()}/" />"><c:out value="${stat[0].getName(pageContext.response.locale)}" /></a></li>
</c:forEach>
</ul>
</div>
</c:if>
<div class="col-sm-4">
<h4>Top ${statisticsGenus.numberOfElements} by Genus</h4>
<h4><spring:message code="faoInstitute.stat-by-genus" arguments="${statisticsGenus.numberOfElements}" /></h4>
<ul class="funny-list statistics">
<c:forEach items="${statisticsGenus.content}" var="stat" varStatus="status">
<li class="clearfix ${status.count % 2 == 0 ? 'even' : 'odd'}"><span class="stats-number"><fmt:formatNumber value="${stat[1]}" /></span> <c:out value="${stat[0]}" /></li>
......@@ -105,7 +107,7 @@
</div>
<div class="col-sm-4">
<h4>Top ${statisticsTaxonomy.numberOfElements} by Species</h4>
<h4><spring:message code="faoInstitute.stat-by-species" arguments="${statisticsTaxonomy.numberOfElements}" /></h4>
<ul class="funny-list statistics">
<c:forEach items="${statisticsTaxonomy.content}" var="stat" varStatus="status">
<li class="clearfix ${status.count % 2 == 0 ? 'even' : 'odd'}"><span class="stats-number"><fmt:formatNumber value="${stat[1]}" /></span> <a href="<c:url value="/wiews/${faoInstitute.code.toLowerCase()}/t/${stat[0].genus}/${stat[0].species}" />"><c:out value="${stat[0].taxonName}" /></a></li>
......
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