From 6cfc5a9184f5190c5d3d99eb6285fbd5e1ace326 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 3 Jun 2021 04:50:51 +0200 Subject: [PATCH] Added visit count and user count in federation page. --- .../statoolinfos/core/Organization.java | 38 ++++++++++++++++ src/fr/devinsy/statoolinfos/core/Service.java | 45 +++++++++++++++++++ .../statoolinfos/htmlize/FederationPage.java | 20 +++++++++ .../htmlize/charts/MonthValues.java | 19 ++++++++ .../statoolinfos/htmlize/federation.xhtml | 2 + 5 files changed, 124 insertions(+) diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index decc441..8cc7bc1 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -585,6 +585,44 @@ public class Organization extends PathPropertyList return result; } + /** + * Gets the previous month user count. + * + * @return the previous month user count + */ + public long getPreviousMonthUserCount() + { + long result; + + result = 0; + for (Service service : this.services) + { + result += service.getPreviousMonthUserCount(); + } + + // + return result; + } + + /** + * Gets the previous month visit count. + * + * @return the previous month visit count + */ + public long getPreviousMonthVisitCount() + { + long result; + + result = 0; + for (Service service : this.services) + { + result += service.getPreviousMonthVisitCount(); + } + + // + return result; + } + /** * Gets the service count. * diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index f96206f..6f615fe 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -23,6 +23,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.YearMonth; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; @@ -31,6 +32,7 @@ import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.checker.PropertyChecks; import fr.devinsy.statoolinfos.crawl.CrawlJournal; +import fr.devinsy.statoolinfos.htmlize.charts.MonthValues; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathPropertyList; @@ -473,11 +475,54 @@ public class Service extends PathPropertyList return result; } + /** + * Gets the organization. + * + * @return the organization + */ public Organization getOrganization() { return this.organization; } + /** + * Gets the previous month user count. + * + * @return the previous month user count + */ + public long getPreviousMonthUserCount() + { + long result; + + MonthValues values = getMetricMonthValues("metrics.users.count"); + + values = values.extract(YearMonth.now().minusMonths(1), YearMonth.now().minusMonths(1)); + + result = (long) values.sum(); + + // + return result; + } + + /** + * Gets the previous month visit count. + * + * @return the previous month visit count + */ + public long getPreviousMonthVisitCount() + { + long result; + + MonthValues values = getMetricMonthValues("metrics.http.visits.visitors"); + + values = values.extract(YearMonth.now().minusMonths(1), YearMonth.now().minusMonths(1)); + + result = (long) values.sum(); + + // + return result; + } + /** * Gets the registration load. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java index 5f05d14..c7d62f4 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java @@ -129,6 +129,26 @@ public class FederationPage data.setContent("organizationListLine", index, "organizationListLineServiceCount", organization.getServiceCount()); + long count = organization.getPreviousMonthUserCount(); + if (count == 0) + { + data.setContent("organizationListLine", index, "organizationListLineUserCount", "n/a"); + } + else + { + data.setContent("organizationListLine", index, "organizationListLineUserCount", count); + } + + count = organization.getPreviousMonthVisitCount(); + if (count == 0) + { + data.setContent("organizationListLine", index, "organizationListLineVisitCount", "n/a"); + } + else + { + data.setContent("organizationListLine", index, "organizationListLineVisitCount", count); + } + data.setContent("organizationListLine", index, "organizationListLineDate", organization.getCrawledDate().format(DateTimeFormatter.ofPattern("dd/MM/YYYY"))); data.setAttribute("organizationListLine", index, "organizationListLineDate", "title", organization.getCrawledDate().format(DateTimeFormatter.ofPattern("HH:mm:ss"))); diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/MonthValues.java b/src/fr/devinsy/statoolinfos/htmlize/charts/MonthValues.java index 4ae8a4d..e474fa8 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/MonthValues.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/MonthValues.java @@ -281,6 +281,25 @@ public class MonthValues extends HashMap this.label = label; } + /** + * Sum. + * + * @return the double + */ + public double sum() + { + double result; + + result = 0; + for (Double value : this.values()) + { + result += value; + } + + // + return result; + } + /** * Gets the normalized values. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml index c433ba5..678412d 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml @@ -23,6 +23,7 @@ URL Services Utilisateurs mensuels + Visites mensuelles Date @@ -37,6 +38,7 @@ n/a n/a n/a + n/a n/a