diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index fe7c8fa..2ecc2a2 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -92,6 +92,21 @@ public class Organization extends PathPropertyList return result; } + /** + * Gets the country code. + * + * @return the country code + */ + public String getCountryCode() + { + String result; + + result = get("organization.country.code"); + + // + return result; + } + /** * Gets the crawled date. * diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index c9aa07a..7a77fbd 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -149,6 +149,21 @@ public class Service extends PathPropertyList return result; } + /** + * Gets the country code. + * + * @return the country code + */ + public String getCountryCode() + { + String result; + + result = get("organization.country.code"); + + // + return result; + } + public LocalDateTime getCrawledDate() { LocalDateTime result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java index 0788168..e04d8c7 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java @@ -41,7 +41,7 @@ import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; /** - * The Class SocialNetworksPage. + * The Class FederationStatsPage. */ public class FederationStatsPage { @@ -68,9 +68,12 @@ public class FederationStatsPage TagDataManager data = new TagDataManager(); data.setContent("turnoutChart", Htmlizer.htmlizeOrganizationTurnoutChart(federation.getOrganizations())); + data.setContent("organizationCountryChart", Htmlizer.htmlizeOrganizationCountryChart(federation.getOrganizations())); + data.setContent("hostServerTypeChart", Htmlizer.htmlizeHostServerTypeChart(federation.getAllServices())); data.setContent("hostProviderTypeChart", Htmlizer.htmlizeHostProviderTypeChart(federation.getAllServices())); data.setContent("serviceInstallTypeChart", Htmlizer.htmlizeServiceInstallTypeChart(federation.getAllServices())); + data.setContent("serviceCountryChart", Htmlizer.htmlizeServiceCountryChart(federation.getAllServices())); // { diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 074e81f..7ac5da4 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -41,6 +41,7 @@ import fr.devinsy.statoolinfos.htmlize.charts.PieChart; import fr.devinsy.statoolinfos.htmlize.charts.PieChart.Position; import fr.devinsy.statoolinfos.htmlize.charts.PieChartView; import fr.devinsy.statoolinfos.stats.StatAgent; +import fr.devinsy.statoolinfos.stats.country.CountryStats; import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats; import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats; import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats; @@ -247,6 +248,31 @@ public class Htmlizer return result; } + /** + * @param organizations + * @return + * @throws StatoolInfosException + */ + public static String htmlizeOrganizationCountryChart(final Organizations organizations) throws StatoolInfosException + { + String result; + + CountryStats stats = StatAgent.statsCountry(organizations); + + PieChart pie = new PieChart("Pays des membres"); + int index = 0; + for (String country : stats.keySet()) + { + pie.add(country, stats.get(country), ChartColor.values()[index]); + } + pie.setLegendPosition(Position.RIGHT); + + result = PieChartView.build(pie); + + // + return result; + } + /** * Htmlize organization turnout chart. * @@ -296,6 +322,35 @@ public class Htmlizer return result; } + /** + * Htmlize service country chart. + * + * @param services + * the services + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlizeServiceCountryChart(final Services services) throws StatoolInfosException + { + String result; + + CountryStats stats = StatAgent.statsCountry(services); + + PieChart pie = new PieChart("Pays des services"); + int index = 0; + for (String country : stats.keySet()) + { + pie.add(country, stats.get(country), ChartColor.values()[index]); + } + pie.setLegendPosition(Position.RIGHT); + + result = PieChartView.build(pie); + + // + return result; + } + /** * Htmlize service install type chart. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java index bf2899f..0178606 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationStatsPage.java @@ -89,6 +89,7 @@ public class OrganizationStatsPage data.setContent("hostServerTypeChart", Htmlizer.htmlizeHostServerTypeChart(organization.getServices())); data.setContent("hostProviderTypeChart", Htmlizer.htmlizeHostProviderTypeChart(organization.getServices())); data.setContent("serviceInstallTypeChart", Htmlizer.htmlizeServiceInstallTypeChart(organization.getServices())); + data.setContent("serviceCountryChart", Htmlizer.htmlizeServiceCountryChart(organization.getServices())); // { diff --git a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml index f670c81..16e79d3 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml @@ -17,11 +17,13 @@
+
+
diff --git a/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml b/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml index f670c81..ba27cd1 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/organizationStats.xhtml @@ -22,6 +22,7 @@
+
diff --git a/src/fr/devinsy/statoolinfos/stats/StatAgent.java b/src/fr/devinsy/statoolinfos/stats/StatAgent.java index fa119ee..f2b828c 100644 --- a/src/fr/devinsy/statoolinfos/stats/StatAgent.java +++ b/src/fr/devinsy/statoolinfos/stats/StatAgent.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. * @@ -40,6 +40,7 @@ import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.statoolinfos.properties.PathPropertyList; import fr.devinsy.statoolinfos.stats.categories.CategoryStat; import fr.devinsy.statoolinfos.stats.categories.CategoryStats; +import fr.devinsy.statoolinfos.stats.country.CountryStats; import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats; import fr.devinsy.statoolinfos.stats.properties.PropertyStats; import fr.devinsy.statoolinfos.stats.propertyfiles.PropertiesFileStats; @@ -330,6 +331,52 @@ public class StatAgent return result; } + /** + * Stats country. + * + * @param organizations + * the organizations + * @return the country stats + */ + public static CountryStats statsCountry(final Organizations organizations) + { + CountryStats result; + + result = new CountryStats(); + + // + for (Organization organization : organizations) + { + result.inc(organization.getCountryCode()); + } + + // + return result; + } + + /** + * Stats country. + * + * @param services + * the services + * @return the country stats + */ + public static CountryStats statsCountry(final Services services) + { + CountryStats result; + + result = new CountryStats(); + + // + for (Service service : services) + { + result.inc(service.getCountryCode()); + } + + // + return result; + } + /** * Stat service install type. * diff --git a/src/fr/devinsy/statoolinfos/stats/country/CountryStats.java b/src/fr/devinsy/statoolinfos/stats/country/CountryStats.java new file mode 100644 index 0000000..c3385d1 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/country/CountryStats.java @@ -0,0 +1,83 @@ +/* + * 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.country; + +import java.util.HashMap; + +import org.apache.commons.lang3.StringUtils; + +/** + * The Class CountryStats. + */ +public class CountryStats extends HashMap +{ + private static final long serialVersionUID = -8177123413128556290L; + + /** + * Instantiates a new country stats. + */ + public CountryStats() + { + super(); + } + + /** + * Gets the total count. + * + * @return the total count + */ + public long getTotalCount() + { + long result; + + result = 0; + for (long value : this.values()) + { + result += value; + } + + // + return result; + } + + /** + * Inc. + * + * @param country + * the country + */ + public void inc(final String country) + { + if (StringUtils.isBlank(country)) + { + inc("Inconnu"); + } + else + { + Integer currentValue = get(country); + if (currentValue == null) + { + currentValue = 0; + } + + currentValue += 1; + put(country, currentValue); + } + } +}