From 9caf349639368f450fa7e89c33a5255daa3794a3 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 20 Feb 2021 04:32:56 +0100 Subject: [PATCH] Improved service count federation chart and added organization ones. --- .../htmlize/FederationStatsPage.java | 4 +- .../statoolinfos/htmlize/Htmlizer.java | 226 +++++++++++++++++- .../htmlize/OrganizationStatsPage.java | 4 + .../htmlize/federationStats.xhtml | 3 +- .../htmlize/organizationStats.xhtml | 5 + 5 files changed, 235 insertions(+), 7 deletions(-) diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java index dc7b7d8..03f1b9d 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java @@ -66,8 +66,10 @@ public class FederationStatsPage File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); TagDataManager data = new TagDataManager(); + + data.setContent("serviceCountMonthChart", Htmlizer.htmlizeServiceCountMonthChart(federation)); + data.setContent("serviceCountYearChart", Htmlizer.htmlizeServiceCountYearChart(federation)); data.setContent("serviceDateStatusChart", Htmlizer.htmlizeServiceDateStatusChart(federation.getAllServices())); - data.setContent("serviceCountChart", Htmlizer.htmlizeServiceCountChart(federation)); data.setContent("turnoutChart", Htmlizer.htmlizeOrganizationTurnoutChart(federation.getOrganizations())); data.setContent("organizationCountryChart", Htmlizer.htmlizeOrganizationCountryChart(federation.getOrganizations())); diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 8303c93..fab0d0c 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -425,21 +425,104 @@ public class Htmlizer * @throws StatoolInfosException * the statool infos exception */ - public static String htmlizeServiceCountChart(final Federation federation) throws StatoolInfosException + public static String htmlizeServiceCountMonthChart(final Federation federation) throws StatoolInfosException + { + String result; + + result = htmlizeServiceCountMonthChart(federation.getAllServices(), + YearMonth.from(StatoolInfosUtils.parseDate(federation.getStartDate()))); + + // + return result; + } + + /** + * Htmlize service count chart. + * + * @param organization + * the organization + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlizeServiceCountMonthChart(final Organization organization) throws StatoolInfosException + { + String result; + + LocalDate startDate = StatoolInfosUtils.parseDate(organization.getStartDate()); + + if (startDate == null) + { + result = null; + } + else + { + result = htmlizeServiceCountMonthChart(organization.getServices(), YearMonth.from(startDate)); + } + + // + return result; + } + + /** + * Htmlize service count chart. + * + * @param services + * the services + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlizeServiceCountMonthChart(final Services services) throws StatoolInfosException + { + String result; + + YearMonth first = null; + for (Service service : services) + { + LocalDate date = StatoolInfosUtils.parseDate(service.getStartDate()); + if (date != null) + { + YearMonth current = YearMonth.from(date); + if ((first == null) || (first.isBefore(current))) + { + first = current; + } + } + } + + result = htmlizeServiceCountMonthChart(services, first); + + // + return result; + } + + /** + * Htmlize service count chart. + * + * @param services + * the services + * @param start + * the start + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlizeServiceCountMonthChart(final Services services, final YearMonth first) throws StatoolInfosException { String result; BarChart chart; - chart = new BarChart("Nombre des services"); + chart = new BarChart("Nombre de services (mois)"); chart.addDataset("Services"); YearMonth now = YearMonth.now(); - YearMonth current = YearMonth.from(StatoolInfosUtils.parseDate(federation.getStartDate())); + YearMonth current = first; while (current.compareTo(now) <= 0) { long count = 0; - for (Service service : federation.getAllServices()) + for (Service service : services) { LocalDate startDate = StatoolInfosUtils.parseDate(service.getStartDate()); LocalDate endDate = StatoolInfosUtils.parseDate(service.getEndDate()); @@ -454,7 +537,7 @@ public class Htmlizer } else { - end = YearMonth.of(endDate.getYear(), endDate.getMonth()); + end = YearMonth.from(endDate); } if ((current.compareTo(start) >= 0) && (current.compareTo(end) <= 0)) @@ -519,6 +602,139 @@ public class Htmlizer return result; } + public static String htmlizeServiceCountYearChart(final Federation federation) throws StatoolInfosException + { + String result; + + result = htmlizeServiceCountYearChart(federation.getAllServices(), + StatoolInfosUtils.parseDate(federation.getStartDate()).getYear()); + + // + return result; + } + + /** + * Htmlize service count year chart. + * + * @param organization + * the organization + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlizeServiceCountYearChart(final Organization organization) throws StatoolInfosException + { + String result; + + LocalDate startDate = StatoolInfosUtils.parseDate(organization.getStartDate()); + + if (startDate == null) + { + result = null; + } + else + { + result = htmlizeServiceCountYearChart(organization.getServices(), startDate.getYear()); + } + + // + return result; + } + + /** + * Htmlize service count year chart. + * + * @param services + * the services + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlizeServiceCountYearChart(final Services services) throws StatoolInfosException + { + String result; + + Integer first = null; + for (Service service : services) + { + LocalDate date = StatoolInfosUtils.parseDate(service.getStartDate()); + if (date != null) + { + int current = date.getYear(); + if ((first == null) || (first < current)) + { + first = current; + } + } + } + + result = htmlizeServiceCountYearChart(services, first); + + // + return result; + } + + /** + * Htmlize service count chart. + * + * @param services + * the services + * @param first + * the first + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlizeServiceCountYearChart(final Services services, final int first) throws StatoolInfosException + { + String result; + + BarChart chart; + + chart = new BarChart("Nombre de services"); + chart.addDataset("Services"); + + int now = LocalDate.now().getYear(); + int current = first; + while (current <= now) + { + long count = 0; + for (Service service : services) + { + LocalDate startDate = StatoolInfosUtils.parseDate(service.getStartDate()); + LocalDate endDate = StatoolInfosUtils.parseDate(service.getEndDate()); + + if (startDate != null) + { + int start = startDate.getYear(); + int end; + if (endDate == null) + { + end = now; + } + else + { + end = endDate.getYear(); + } + + if ((current >= start) && (current <= end)) + { + count += 1; + } + } + } + + chart.add(String.valueOf(current), count, ChartColor.VIOLET); + + current += 1; + } + + result = BarChartView.build(chart); + + // + return result; + } + /** * Htmlize service date status chart. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java index 5abeeeb..8af29ad 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java @@ -84,6 +84,10 @@ public class OrganizationStatsPage TagDataManager data = new TagDataManager(); + data.setContent("serviceCountMonthChart", Htmlizer.htmlizeServiceCountMonthChart(organization)); + data.setContent("serviceCountYearChart", Htmlizer.htmlizeServiceCountYearChart(organization)); + data.setContent("serviceDateStatusChart", Htmlizer.htmlizeServiceDateStatusChart(organization.getServices())); + data.setContent("turnoutChart", Htmlizer.htmlizeOrganizationTurnoutChart(organization)); data.setContent("hostServerTypeChart", Htmlizer.htmlizeHostServerTypeChart(organization.getServices())); diff --git a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml index 17e95e3..d5c836a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml @@ -16,8 +16,9 @@

Statistiques

-
+
+
diff --git a/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml b/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml index 268cb68..92484a8 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml @@ -15,6 +15,11 @@

Statistiques

+
+
+
+
+