From 0e3dbd7e053ce9387e288a8c7a8b689c957ff96a Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 26 May 2021 02:06:15 +0200 Subject: [PATCH] Added service stats page. --- .../devinsy/statoolinfos/core/Services.java | 22 ++++ .../statoolinfos/htmlize/ChartHtmlizer.java | 83 +++++++++----- .../htmlize/ServiceMetricMenuView.java | 6 + .../statoolinfos/htmlize/ServicePage.java | 5 + .../htmlize/ServiceStatsPage.java | 104 ++++++++++++++++++ .../htmlize/serviceMetricMenuView.xhtml | 6 + .../statoolinfos/htmlize/serviceStats.xhtml | 48 ++++++++ 7 files changed, 248 insertions(+), 26 deletions(-) create mode 100644 src/fr/devinsy/statoolinfos/htmlize/ServiceStatsPage.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/serviceStats.xhtml diff --git a/src/fr/devinsy/statoolinfos/core/Services.java b/src/fr/devinsy/statoolinfos/core/Services.java index e955298..b8a7f01 100644 --- a/src/fr/devinsy/statoolinfos/core/Services.java +++ b/src/fr/devinsy/statoolinfos/core/Services.java @@ -140,4 +140,26 @@ public class Services extends ArrayList // return result; } + + /** + * Of. + * + * @param service + * the service + * @return the services + */ + public static Services of(final Service service) + { + Services result; + + result = new Services(); + + if (service != null) + { + result.add(service); + } + + // + return result; + } } diff --git a/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java index dd76142..70a0711 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java @@ -587,6 +587,34 @@ public class ChartHtmlizer return result; } + /** + * Htmlize organization turnout chart. + * + * @param service + * the service + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlizeOrganizationTurnoutChart(final Service service) throws StatoolInfosException + { + String result; + + OrganizationTurnoutStats stats = StatAgent.statsOrganizationTurnout(service); + + PieChart pie = new PieChart("Participation"); + pie.add("1 fichier", stats.getWithSelfFileCount(), ChartColor.ORANGE); + pie.add("n fichiers", stats.getWithServiceFileCount(), ChartColor.YELLOW); + pie.add("Métriques", stats.getWithServiceMetricCount(), ChartColor.GREEN); + pie.add("Passive", stats.getPassiveCount(), ChartColor.BLUE); + pie.setLegendPosition(Position.RIGHT); + + result = PieChartView.build(pie); + + // + return result; + } + /** * Htmlize registration chart. * @@ -988,7 +1016,7 @@ public class ChartHtmlizer * @throws StatoolInfosException * the statool infos exception */ - public static String htmlizeServiceCountYearChart(final Services services, final int first) throws StatoolInfosException + public static String htmlizeServiceCountYearChart(final Services services, final Integer first) throws StatoolInfosException { String result; @@ -997,39 +1025,42 @@ public class ChartHtmlizer chart = new BarChart("Nombre de services"); chart.addDataset("Services"); - int now = LocalDate.now().getYear(); - int current = first; - while (current <= now) + if (first != null) { - long count = 0; - for (Service service : services) + int now = LocalDate.now().getYear(); + int current = first; + while (current <= now) { - LocalDate startDate = StatoolInfosUtils.parseDate(service.getStartDate()); - LocalDate endDate = StatoolInfosUtils.parseDate(service.getEndDate()); - - if (startDate != null) + long count = 0; + for (Service service : services) { - int start = startDate.getYear(); - int end; - if (endDate == null) - { - end = now; - } - else - { - end = endDate.getYear(); - } + LocalDate startDate = StatoolInfosUtils.parseDate(service.getStartDate()); + LocalDate endDate = StatoolInfosUtils.parseDate(service.getEndDate()); - if ((current >= start) && (current <= end)) + if (startDate != null) { - count += 1; + 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; } - - chart.add(String.valueOf(current), count, ChartColor.VIOLET); - - current += 1; } result = BarChartView.build(chart); diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricMenuView.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricMenuView.java index 5a6bab0..395074e 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricMenuView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricMenuView.java @@ -38,6 +38,7 @@ public class ServiceMetricMenuView public enum MenuItem { SUMMARY, + GENERAL, GENERIC, WEB, SPECIFIC @@ -61,6 +62,7 @@ public class ServiceMetricMenuView TagDataManager data = new TagDataManager(); data.setAttribute("summaryTypeButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + data.setAttribute("generalTypeButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-general.xhtml"); data.setAttribute("genericTypeButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-generic.xhtml"); data.setAttribute("webTypeButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-web.xhtml"); data.setAttribute("specificTypeButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-specific.xhtml"); @@ -69,6 +71,10 @@ public class ServiceMetricMenuView { data.appendAttribute("summaryTypeButton", "class", "button selected"); } + else if (item == MenuItem.GENERAL) + { + data.appendAttribute("generalTypeButton", "class", "button selected"); + } else if (item == MenuItem.GENERIC) { data.appendAttribute("genericTypeButton", "class", "button selected"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java index 54aca11..bcad7dc 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java @@ -79,6 +79,11 @@ public class ServicePage String page = ServicePage.htmlize(service); FileUtils.write(new File(htmlizeDirectory, service.getLocalFileBaseName() + ".xhtml"), page, StandardCharsets.UTF_8); + // + logger.info("Htmlize service general metric page: {}.", service.getName()); + page = ServiceStatsPage.htmlize(service); + FileUtils.write(new File(htmlizeDirectory, service.getLocalFileBaseName() + "-metrics-general.xhtml"), page, StandardCharsets.UTF_8); + // logger.info("Htmlize service generic metric page: {}.", service.getName()); page = ServiceGenericMetricPage.htmlize(service); diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceStatsPage.java new file mode 100644 index 0000000..b988e2a --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceStatsPage.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2020-2021 Christian Pierre MOMON + * + * This file is part of StatoolInfos, simple service statistics tool. + * + * StatoolInfos is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * StatoolInfos is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with StatoolInfos. If not, see . + */ +package fr.devinsy.statoolinfos.htmlize; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.core.Service; +import fr.devinsy.statoolinfos.core.Services; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem; +import fr.devinsy.statoolinfos.stats.StatAgent; +import fr.devinsy.statoolinfos.stats.services.RegistrationStats; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class ServiceStatsPage. + */ +public class ServiceStatsPage +{ + private static Logger logger = LoggerFactory.getLogger(ServiceStatsPage.class); + + /** + * Builds the. + * + * @param service + * the service + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Service service) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building service stats page {}…", service.get("service.name")); + + TagDataManager data = new TagDataManager(); + + // + data.setContent("headerView", ServiceHeaderView.htmlize(service)); + data.setContent("serviceMetricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.GENERAL)); + + // + data.setContent("turnoutChart", ChartHtmlizer.htmlizeOrganizationTurnoutChart(service)); + + Services mock = Services.of(service); + + data.setContent("hostServerTypeChart", ChartHtmlizer.htmlizeHostServerTypeChart(mock)); + data.setContent("hostProviderTypeChart", ChartHtmlizer.htmlizeHostProviderTypeChart(mock)); + data.setContent("serviceInstallTypeChart", ChartHtmlizer.htmlizeServiceInstallTypeChart(mock)); + data.setContent("serviceCountryChart", ChartHtmlizer.htmlizeServiceCountryChart(mock)); + + // + { + RegistrationStats stats = StatAgent.statRegistrationTypes(mock); + + data.setContent("registrationTypeChart", ChartHtmlizer.htmlizeRegistrationBarChart(stats)); + data.setContent("registrationNoneTypeChart", ChartHtmlizer.htmlizeRegistrationNonePieChart(stats)); + data.setContent("registrationFreeTypeChart", ChartHtmlizer.htmlizeRegistrationFreePieChart(stats)); + data.setContent("registrationMemberTypeChart", ChartHtmlizer.htmlizeRegistrationMemberPieChart(stats)); + data.setContent("registrationClientTypeChart", ChartHtmlizer.htmlizeRegistrationClientPieChart(stats)); + } + + data.setContent("serviceCountYearChart", ChartHtmlizer.htmlizeServiceCountYearChart(mock)); + data.setContent("serviceDateStatusChart", ChartHtmlizer.htmlizeServiceDateStatusChart(mock)); + + // + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceStats.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml"); + trail.add(service.getName(), service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/serviceMetricMenuView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/serviceMetricMenuView.xhtml index d278452..1a66e88 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/serviceMetricMenuView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/serviceMetricMenuView.xhtml @@ -15,6 +15,7 @@
Type Résumé + Général Génériques Web Spécifiques @@ -39,6 +40,7 @@ function selectTypeMenu(selection) { document.getElementById ('summaryTypeButton').classList.remove('selected'); + document.getElementById ('generalTypeButton').classList.remove('selected'); document.getElementById ('genericTypeButton').classList.remove('selected'); document.getElementById ('webTypeButton').classList.remove('selected'); document.getElementById ('specificTypeButton').classList.remove('selected'); @@ -51,6 +53,10 @@ function selectTypeMenu(selection) { document.getElementById ('genericTypeButton').classList.add('selected'); } + else if (selection == 'general') + { + document.getElementById ('generalTypeButton').classList.add('selected'); + } else if (selection == 'web') { document.getElementById ('webTypeButton').classList.add('selected'); diff --git a/src/fr/devinsy/statoolinfos/htmlize/serviceStats.xhtml b/src/fr/devinsy/statoolinfos/htmlize/serviceStats.xhtml new file mode 100644 index 0000000..d39fb61 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/serviceStats.xhtml @@ -0,0 +1,48 @@ + + + + + StatoolInfos + + + + + + + +
+
+

Statistiques

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +