From a4b4516f61f5029a829fe596530e87da4e34f263 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 13 Jan 2021 02:33:51 +0100 Subject: [PATCH] Added service install type stats. --- src/fr/devinsy/statoolinfos/core/Service.java | 38 +++++- .../htmlize/FederationStatsPage.java | 3 +- .../statoolinfos/htmlize/Htmlizer.java | 35 ++++- .../htmlize/OrganizationStatsPage.java | 4 +- .../htmlize/charts/ChartColor.java | 2 + .../htmlize/federationStats.xhtml | 1 + .../htmlize/organizationStats.xhtml | 1 + .../devinsy/statoolinfos/stats/StatAgent.java | 24 ++++ .../services/ServiceInstallTypeStats.java | 127 ++++++++++++++++++ 9 files changed, 231 insertions(+), 4 deletions(-) create mode 100644 src/fr/devinsy/statoolinfos/stats/services/ServiceInstallTypeStats.java diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index ed24c80..b9aa710 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -73,6 +73,18 @@ public class Service extends PathPropertyList UNKNOWN } + public enum ServiceInstallType + { + DISTRIBUTION, + PROVIDER, + PACKAGE, + CLONEREPO, + ARCHIVE, + SOURCES, + CONTAINER, + UNKNOWN + } + public enum Status { OK, @@ -405,6 +417,30 @@ public class Service extends PathPropertyList return result; } + /** + * Gets the service install type. + * + * @return the service install type + */ + public ServiceInstallType getServiceInstallType() + { + ServiceInstallType result; + + try + { + String value = StringUtils.toRootUpperCase(get("service.install.type")); + + result = ServiceInstallType.valueOf(value); + } + catch (IllegalArgumentException | NullPointerException exception) + { + result = ServiceInstallType.UNKNOWN; + } + + // + return result; + } + /** * Gets the software description. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java index 428d6ca..0788168 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -70,6 +70,7 @@ public class FederationStatsPage data.setContent("turnoutChart", Htmlizer.htmlizeOrganizationTurnoutChart(federation.getOrganizations())); data.setContent("hostServerTypeChart", Htmlizer.htmlizeHostServerTypeChart(federation.getAllServices())); data.setContent("hostProviderTypeChart", Htmlizer.htmlizeHostProviderTypeChart(federation.getAllServices())); + data.setContent("serviceInstallTypeChart", Htmlizer.htmlizeServiceInstallTypeChart(federation.getAllServices())); // { diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 38ca31c..329dbac 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -45,6 +45,7 @@ import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats; import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats; import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats; import fr.devinsy.statoolinfos.stats.services.RegistrationStats; +import fr.devinsy.statoolinfos.stats.services.ServiceInstallTypeStats; import fr.devinsy.statoolinfos.util.URLUtils; /** @@ -295,6 +296,38 @@ public class Htmlizer return result; } + /** + * Htmlize service install type chart. + * + * @param services + * the services + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlizeServiceInstallTypeChart(final Services services) throws StatoolInfosException + { + String result; + + ServiceInstallTypeStats stats = StatAgent.statServiceInstallType(services); + + PieChart pie = new PieChart("Types d'installation du service"); + pie.add("Distribution", stats.getDistributionCount(), ChartColor.PURPLE); + pie.add("Fournisseur", stats.getProviderCount(), ChartColor.GREEN); + pie.add("Paquet", stats.getPackageCount(), ChartColor.YELLOW); + pie.add("Dépôt cloné", stats.getClonerepoCount(), ChartColor.ORANGE); + pie.add("Archive", stats.getArchiveCount(), ChartColor.RED); + pie.add("Sources", stats.getSourcesCount(), ChartColor.GREY); + pie.add("Containeur", stats.getContainerCount(), ChartColor.CYAN); + pie.add("Inconnu", stats.getUnknownCount(), ChartColor.BLUE); + pie.setLegendPosition(Position.RIGHT); + + result = DoughnutChartView.build(pie); + + // + return result; + } + /** * To bar chart. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java index bf79b5d..bf2899f 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -85,8 +85,10 @@ public class OrganizationStatsPage TagDataManager data = new TagDataManager(); data.setContent("turnoutChart", Htmlizer.htmlizeOrganizationTurnoutChart(organization)); + data.setContent("hostServerTypeChart", Htmlizer.htmlizeHostServerTypeChart(organization.getServices())); data.setContent("hostProviderTypeChart", Htmlizer.htmlizeHostProviderTypeChart(organization.getServices())); + data.setContent("serviceInstallTypeChart", Htmlizer.htmlizeServiceInstallTypeChart(organization.getServices())); // { diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/ChartColor.java b/src/fr/devinsy/statoolinfos/htmlize/charts/ChartColor.java index fae95fb..6510bd1 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/ChartColor.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/ChartColor.java @@ -23,10 +23,12 @@ package fr.devinsy.statoolinfos.htmlize.charts; */ public enum ChartColor { + // https://html-color-codes.info/ RED("rgb(255, 99, 132)"), ORANGE("rgb(255, 159, 64)"), YELLOW("rgb(255, 205, 86)"), GREEN("rgb(75, 192, 192)"), + CYAN("rgb(00, 255, 255)"), BLUE("rgb(54, 162, 235)"), PURPLE("rgb(153, 102, 255)"), GREY("rgb(201, 203, 207)"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml index 493f174..f670c81 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml @@ -21,6 +21,7 @@
+
diff --git a/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml b/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml index 493f174..f670c81 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml @@ -21,6 +21,7 @@
+
diff --git a/src/fr/devinsy/statoolinfos/stats/StatAgent.java b/src/fr/devinsy/statoolinfos/stats/StatAgent.java index 1ddbbec..fa119ee 100644 --- a/src/fr/devinsy/statoolinfos/stats/StatAgent.java +++ b/src/fr/devinsy/statoolinfos/stats/StatAgent.java @@ -46,6 +46,7 @@ import fr.devinsy.statoolinfos.stats.propertyfiles.PropertiesFileStats; import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats; import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats; import fr.devinsy.statoolinfos.stats.services.RegistrationStats; +import fr.devinsy.statoolinfos.stats.services.ServiceInstallTypeStats; import fr.devinsy.statoolinfos.stats.softwares.SoftwareStat; import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats; import fr.devinsy.strings.StringSet; @@ -329,6 +330,29 @@ public class StatAgent return result; } + /** + * Stat service install type. + * + * @param services + * the services + * @return the service install type stats + */ + public static ServiceInstallTypeStats statServiceInstallType(final Services services) + { + ServiceInstallTypeStats result; + + result = new ServiceInstallTypeStats(); + + // + for (Service service : services) + { + result.inc(service.getServiceInstallType()); + } + + // + return result; + } + /** * @param services * @return diff --git a/src/fr/devinsy/statoolinfos/stats/services/ServiceInstallTypeStats.java b/src/fr/devinsy/statoolinfos/stats/services/ServiceInstallTypeStats.java new file mode 100644 index 0000000..f3af014 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/services/ServiceInstallTypeStats.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 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.stats.services; + +import fr.devinsy.statoolinfos.core.Service.ServiceInstallType; + +/** + * The Class ServiceInstallTypeStats. + */ +public class ServiceInstallTypeStats +{ + private long distributionCount; + private long providerCount; + private long packageCount; + private long clonerepoCount; + private long archiveCount; + private long sourcesCount; + private long containerCount; + private long unknownCount; + + /** + * Instantiates a new host provider type stats. + */ + public ServiceInstallTypeStats() + { + this.distributionCount = 0; + this.providerCount = 0; + this.packageCount = 0; + this.clonerepoCount = 0; + this.archiveCount = 0; + this.sourcesCount = 0; + this.containerCount = 0; + this.unknownCount = 0; + } + + public long getArchiveCount() + { + return this.archiveCount; + } + + public long getClonerepoCount() + { + return this.clonerepoCount; + } + + public long getContainerCount() + { + return this.containerCount; + } + + public long getDistributionCount() + { + return this.distributionCount; + } + + public long getPackageCount() + { + return this.packageCount; + } + + public long getProviderCount() + { + return this.providerCount; + } + + public long getSourcesCount() + { + return this.sourcesCount; + } + + public long getUnknownCount() + { + return this.unknownCount; + } + + /** + * Inc. + * + * @param type + * the type + */ + public void inc(final ServiceInstallType type) + { + switch (type) + { + case DISTRIBUTION: + this.distributionCount += 1; + break; + case PROVIDER: + this.providerCount += 1; + break; + case PACKAGE: + this.packageCount += 1; + break; + case CLONEREPO: + this.clonerepoCount += 1; + break; + case ARCHIVE: + this.archiveCount += 1; + break; + case SOURCES: + this.sourcesCount += 1; + break; + case CONTAINER: + this.containerCount += 1; + break; + default: + this.unknownCount += 1; + } + } +}