Commit 629af0f0 authored by Matija Obreza's avatar Matija Obreza
Browse files

PDCI for Organizations and Networks

parent 3706e0f6
......@@ -105,4 +105,32 @@ public class PDCIStatistics implements Serializable {
histogram[index] = count;
}
}
public void updateMin(Float updateMin) {
if (updateMin == null)
return;
this.min = this.min == null || this.min.floatValue() > updateMin ? updateMin : this.min;
}
public void updateMax(Float updateMax) {
if (updateMax == null)
return;
this.max = this.max == null || this.max.floatValue() < updateMax ? updateMax : this.max;
}
public void updateCountAndAvg(Long count, Double avg) {
if (count == null || count == 0 || avg == null)
return;
this.avg = this.avg == null || this.count == null || this.count == 0 ? avg : (this.avg * this.count + avg * count) / (this.count + count);
this.count = count;
}
/**
* Return object array to be used for i18n
*
* @return
*/
public Object[] getElStats() {
return new Object[] { count, avg, min, max };
}
}
......@@ -241,4 +241,6 @@ public interface GenesysService {
int generateMissingPDCI(int count);
PDCIStatistics statisticsPDCI(Organization organization);
}
......@@ -18,6 +18,7 @@ package org.genesys2.server.service;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
public interface StatisticsService {
......@@ -29,4 +30,6 @@ public interface StatisticsService {
PDCIStatistics statisticsPDCI(FaoInstitute faoInstitute);
PDCIStatistics statisticsPDCI(Organization organization);
}
......@@ -1671,4 +1671,25 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return stats;
}
@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) {
LOG.warn("No PDCI statistics for " + organization);
continue;
}
stats.updateMin((Float) overall[0]);
stats.updateMax((Float) overall[1]);
stats.updateCountAndAvg((Long) overall[3], (Double) overall[2]);
List<Object[]> hist = repoPdci.histogram(faoInstitute);
stats.makeHistogram(hist);
}
return stats;
}
}
......@@ -20,6 +20,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
......@@ -69,4 +70,13 @@ 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) {
if (LOG.isDebugEnabled()) {
LOG.debug("Regenerating PDCI statistics for " + organization);
}
return genesysService.statisticsPDCI(organization);
}
}
......@@ -32,6 +32,7 @@ import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.StatisticsService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
......@@ -66,6 +67,9 @@ public class OrganizationController extends BaseController {
@Autowired
private GeoService geoService;
@Autowired
private StatisticsService statisticsService;
@RequestMapping("/")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
model.addAttribute("pagedData", organizationService.list(new PageRequest(page - 1, 50, new Sort("title"))));
......@@ -97,6 +101,7 @@ public class OrganizationController extends BaseController {
model.addAttribute("members", members);
model.addAttribute("blurp", contentService.getArticle(organization, "blurp", getLocale()));
model.addAttribute("statisticsPDCI", statisticsService.statisticsPDCI(organization));
return "/organization/details";
}
......
......@@ -627,6 +627,7 @@ accession.pdci.institute-avg=Average PDCI score for this institute is {0,number,
accession.pdci.about-link=Read about Passport Data Completeness Index
accession.pdci.independent-items=Independent of the population type
accession.pdci.dependent-items=Depending on the population type
accession.pdci.stats-text=Average PDCI score for {0} accessions is {1,number,0.00}, with minimum score of {2,number,0.00} and maximum score of {3,number,0.00}.
accession.donorNumb=Donor institute code
accession.acqDate=Acquisition date
......
......@@ -4,72 +4,112 @@
<html>
<head>
<title><spring:message code="organization.page.profile.title" arguments="${organization.slug}" argumentSeparator="|" /></title>
<title><spring:message code="organization.page.profile.title" arguments="${organization.slug}"
argumentSeparator="|"
/></title>
</head>
<body>
<h1>
<c:out value="${organization.title}" />
<small><c:out value="${organization.slug}" /></small>
</h1>
<div class="main-col-header text-right">
<a class="btn btn-default" href="<c:url value="/org/${organization.slug}/data" />"><spring:message code="view.accessions" /></a>
<a class="btn btn-default" href="<c:url value="/org/${organization.slug}/overview" />"><span class="glyphicon glyphicon-eye-open"></span><span style="margin-left: 0.5em;"><spring:message code="data-overview.short" /></span></a>
<a class="btn btn-default" href="<c:url value="/org/${organization.slug}/map" />"><span class="glyphicon glyphicon-globe"></span><span style="margin-left: 0.5em;"><spring:message code="maps.view-map" /></span></a>
</div>
<h1>
<c:out value="${organization.title}" />
<small><c:out value="${organization.slug}" /></small>
</h1>
<security:authorize access="hasRole('ADMINISTRATOR')">
<a href="<c:url value="/org/${organization.slug}/edit" />" class="close"> <spring:message code="edit" />
</a>
</security:authorize>
<div class="main-col-header text-right">
<a class="btn btn-default" href="<c:url value="/org/${organization.slug}/data" />"><spring:message
code="view.accessions"
/></a> <a class="btn btn-default" href="<c:url value="/org/${organization.slug}/overview" />"><span
class="glyphicon glyphicon-eye-open"
></span><span style="margin-left: 0.5em;"><spring:message code="data-overview.short" /></span></a> <a class="btn btn-default"
href="<c:url value="/org/${organization.slug}/map" />"
><span class="glyphicon glyphicon-globe"></span><span style="margin-left: 0.5em;"><spring:message
code="maps.view-map"
/></span></a>
</div>
<%@include file="/WEB-INF/jsp/content/include/blurp-display.jsp"%>
<security:authorize access="hasRole('ADMINISTRATOR')">
<a href="<c:url value="/org/${organization.slug}/edit" />" class="close"> <spring:message code="edit" />
</a>
</security:authorize>
<c:set value="" var="countryName" />
<div class="form-horizontal">
<div class="form-group">
<label class="col-lg-2 control-label"> <spring:message code="select-country" /></label>
<div class="col-lg-3">
<select id="countryNavigation" class="form-control">
<c:forEach items="${members}" var="faoInstitute" varStatus="status">
<c:if test="${countryName ne faoInstitute.country.getName(pageContext.response.locale)}">
<c:set var="countryName" value="${faoInstitute.country.getName(pageContext.response.locale)}" />
<option value="${faoInstitute.country.code3}">
<c:out value="${faoInstitute.country.getName(pageContext.response.locale)}" />
</option>
</c:if>
</c:forEach>
</select>
</div>
</div>
<c:remove var="countryName" />
</div>
<%@include file="/WEB-INF/jsp/content/include/blurp-display.jsp"%>
<c:set value="" var="countryName" />
<ul class="funny-list">
<c:forEach items="${members}" var="faoInstitute" varStatus="status">
<c:if test="${countryName ne faoInstitute.country.getName(pageContext.response.locale)}">
<c:set var="countryName" value="${faoInstitute.country.getName(pageContext.response.locale)}" />
<li class="hoofdleter" id="nav-${faoInstitute.country.code3}"><c:out value="${countryName}" /> <small><a href="#"><spring:message code="jump-to-top" /></a></small></li>
</c:if>
<li class="clearfix ${status.count % 2 == 0 ? 'even' : 'odd'}"><a class="show pull-left" href="<c:url value="/wiews/${faoInstitute.code}" />"><b><c:out value="${faoInstitute.code}" /></b> <c:out value="${faoInstitute.fullName}" /></a>
<div class="pull-right">
<spring:message code="faoInstitute.accessionCount" arguments="${faoInstitute.accessionCount}" />
</div></li>
</c:forEach>
</ul>
<content tag="javascript">
<script type="text/javascript">
<c:set value="" var="countryName" />
<div class="form-horizontal">
<div class="form-group">
<label class="col-lg-2 control-label"> <spring:message code="select-country" /></label>
<div class="col-lg-3">
<select id="countryNavigation" class="form-control">
<c:forEach items="${members}" var="faoInstitute" varStatus="status">
<c:if test="${countryName ne faoInstitute.country.getName(pageContext.response.locale)}">
<c:set var="countryName" value="${faoInstitute.country.getName(pageContext.response.locale)}" />
<option value="${faoInstitute.country.code3}">
<c:out value="${faoInstitute.country.getName(pageContext.response.locale)}" />
</option>
</c:if>
</c:forEach>
</select>
</div>
</div>
<c:remove var="countryName" />
</div>
<c:set value="" var="countryName" />
<ul class="funny-list">
<c:forEach items="${members}" var="faoInstitute" varStatus="status">
<c:if test="${countryName ne faoInstitute.country.getName(pageContext.response.locale)}">
<c:set var="countryName" value="${faoInstitute.country.getName(pageContext.response.locale)}" />
<li class="hoofdleter" id="nav-${faoInstitute.country.code3}"><c:out value="${countryName}" /> <small><a
href="#"
><spring:message code="jump-to-top" /></a></small></li>
</c:if>
<li class="clearfix ${status.count % 2 == 0 ? 'even' : 'odd'}"><a class="show pull-left"
href="<c:url value="/wiews/${faoInstitute.code}" />"
><b><c:out value="${faoInstitute.code}" /></b> <c:out value="${faoInstitute.fullName}" /></a>
<div class="pull-right">
<spring:message code="faoInstitute.accessionCount" arguments="${faoInstitute.accessionCount}" />
</div></li>
</c:forEach>
</ul>
<security:authorize access="isAuthenticated()">
<c:if test="${statisticsPDCI.count gt 0}">
<h3>
<spring:message code="accession.pdci" />
</h3>
<p><spring:message code="accession.pdci.stats-text" arguments="${statisticsPDCI.elStats}" /></p>
<div class="chart chart-histogram">
<div id="chartPDCI" style="height: 200px"></div>
</div>
<p>
<a href="<c:url value="/content/passport-data-completeness-index" />"><spring:message
code="accession.pdci.about-link"
/></a>
</p>
<%-- <div class="row">
<c:forEach items="${statisticsPDCI.histogram}" var="item" varStatus="index">
<div class="col-xs-1">${index.count}=${item}</div>
</c:forEach>
</div> --%>
</c:if>
</security:authorize>
<content tag="javascript"> <script type="text/javascript">
jQuery(document).ready(function() {
$("#countryNavigation").on("change", function() {
window.location.hash="nav-" + this.value;
});
<security:authorize access="isAuthenticated()">
<c:if test="${statisticsPDCI.count gt 0}">
GenesysChart.histogram("#chartPDCI", <c:out value="${statisticsPDCI.histogramJson}" escapeXml="false" /> );
</c:if>
</security:authorize>
});
</script>
</content>
</script> </content>
</body>
</html>
\ No newline at end of file
......@@ -213,17 +213,17 @@
<h3>
<spring:message code="accession.pdci" />
</h3>
<p>
<a href="<c:url value="/content/passport-data-completeness-index" />"><spring:message
code="accession.pdci.about-link"
/></a>
</p>
<%-- <p>min=${statisticsPDCI.min} max=${statisticsPDCI.max} avg=${statisticsPDCI.avg} count=${statisticsPDCI.count}</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>
</div>
<p>
<a href="<c:url value="/content/passport-data-completeness-index" />"><spring:message
code="accession.pdci.about-link"
/></a>
</p>
<%-- <c:forEach items="${statisticsPDCI.histogram}" var="item" varStatus="index">
<div>${index.count}=${item}</div>
</c:forEach> --%>
......
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