diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index c39f06b..6143f96 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -45,6 +45,25 @@ public class Service extends PathPropertyList private static Logger logger = LoggerFactory.getLogger(Service.class); + public enum HostProviderType + { + HOME, + HOSTEDBAY, + HOSTEDSERVER, + OUTSOURCED, + UNKNOWN + } + + public enum HostServerType + { + NANO, + PHYSICAL, + VIRTUAL, + SHARED, + CLOUD, + UNKNOWN + } + public enum Status { OK, @@ -149,6 +168,54 @@ public class Service extends PathPropertyList return result; } + /** + * Gets the host provider type. + * + * @return the host provider type + */ + public HostProviderType getHostProviderType() + { + HostProviderType result; + + try + { + String value = StringUtils.toRootUpperCase(get("host.provider.type")); + + result = HostProviderType.valueOf(value); + } + catch (IllegalArgumentException | NullPointerException exception) + { + result = HostProviderType.UNKNOWN; + } + + // + return result; + } + + /** + * Gets the host server type. + * + * @return the host server type + */ + public HostServerType getHostServerType() + { + HostServerType result; + + try + { + String value = StringUtils.toRootUpperCase(get("host.server.type")); + + result = HostServerType.valueOf(value); + } + catch (IllegalArgumentException | NullPointerException exception) + { + result = HostServerType.UNKNOWN; + } + + // + return result; + } + public File getInputFile() { return this.inputFile; diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java new file mode 100644 index 0000000..afe06f6 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2020 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 java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Federation; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; +import fr.devinsy.statoolinfos.htmlize.charts.PieChart; +import fr.devinsy.statoolinfos.htmlize.charts.PieChartView; +import fr.devinsy.statoolinfos.stats.StatAgent; +import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats; +import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats; +import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class SocialNetworksPage. + */ +public class FederationStatsPage +{ + private static Logger logger = LoggerFactory.getLogger(FederationStatsPage.class); + + /** + * Builds the. + * + * @param title + * the title + * @param organizations + * the organizations + * @return the string + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + */ + public static void build() throws StatoolInfosException, IOException + { + try + { + logger.debug("Building federation stats page {}…"); + + Federation federation = HtmlizerContext.instance().getFederation(); + // CrawlCache cache = HtmlizerContext.instance().getCache(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + TagDataManager data = new TagDataManager(); + + // + { + OrganizationTurnoutStats turnout = StatAgent.statsOrganizationTurnout(federation); + PieChart pie = new PieChart("Participation"); + pie.add("Active", turnout.getActiveCount(), ChartColor.GREEN); + pie.add("Passive", turnout.getPassiveCount(), ChartColor.ORANGE); + data.setContent("turnoutChart", PieChartView.build(pie)); + } + + // + { + HostServerTypeStats stats = StatAgent.statHostServerType(federation); + PieChart pie = Htmlizer.toPieChart(stats); + data.setContent("hostServerTypeChart", PieChartView.build(pie)); + } + + // + { + HostProviderTypeStats stats = StatAgent.statHostProviderType(federation); + PieChart pie = Htmlizer.toPieChart(stats); + data.setContent("hostProviderTypeChart", PieChartView.build(pie)); + } + + // + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml", data).toString(); + + // + BreadcrumbTrail trail = new BreadcrumbTrail(); + String page = WebCharterView.build(content, trail); + + FileUtils.write(new File(htmlizeDirectory, "federationStats.xhtml"), page, StandardCharsets.UTF_8); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building federation stats page: " + exception.getMessage(), exception); + } + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 3e30fff..0a3d8b1 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -31,6 +31,11 @@ import fr.devinsy.statoolinfos.core.Category; import fr.devinsy.statoolinfos.core.Configuration; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosUtils; +import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; +import fr.devinsy.statoolinfos.htmlize.charts.PieChart; +import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats; +import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats; +import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats; /** * The Class Htmlizer. @@ -254,6 +259,7 @@ public class Htmlizer AboutPage.build(); EditoPage.build(); + FederationStatsPage.build(); FederationPage.build(); OrganizationPage.buildAll(); ServicePage.buildAll(); @@ -267,4 +273,68 @@ public class Htmlizer SoftwarePage.buildAll(); SocialNetworksPage.buildAll(); } + + /** + * To pie chart. + * + * @param stats + * the stats + * @return the pie chart + */ + public static PieChart toPieChart(final HostProviderTypeStats stats) + { + PieChart result; + + result = new PieChart("Types d'hébergement"); + result.add("Home", stats.getHomeCount(), ChartColor.GREEN); + result.add("Baie", stats.getHostedBayCount(), ChartColor.YELLOW); + result.add("Serveur", stats.getHostedServerCount(), ChartColor.ORANGE); + result.add("Externalisé", stats.getOutsourcedCount(), ChartColor.RED); + result.add("Inconnu", stats.getUnknownCount(), ChartColor.BLUE); + + // + return result; + } + + /** + * To pie chart. + * + * @param source + * the source + * @return the pie chart + */ + public static PieChart toPieChart(final HostServerTypeStats stats) + { + PieChart result; + + result = new PieChart("Types de serveur"); + result.add("Nano", stats.getNanoCount(), ChartColor.GREEN); + result.add("Physique", stats.getPhysicalCount(), ChartColor.PURPLE); + result.add("Virtuel", stats.getVirtualCount(), ChartColor.YELLOW); + result.add("Mutualisé", stats.getSharedCount(), ChartColor.ORANGE); + result.add("Cloud", stats.getCloudCount(), ChartColor.RED); + result.add("Inconnu", stats.getUnknownCount(), ChartColor.BLUE); + + // + return result; + } + + /** + * To pie chart. + * + * @param stats + * the stats + * @return the pie chart + */ + public static PieChart toPieChart(final OrganizationTurnoutStats stats) + { + PieChart result; + + result = new PieChart("Participation"); + result.add("Active", stats.getActiveCount(), ChartColor.GREEN); + result.add("Passive", stats.getPassiveCount(), ChartColor.ORANGE); + + // + return result; + } } diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java index 9f76bd8..486a5bb 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java @@ -35,7 +35,7 @@ import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.statoolinfos.htmlize.charts.BarMonthsChartView; -import fr.devinsy.statoolinfos.htmlize.charts.ChartColors; +import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.DisplayMode; import fr.devinsy.xidyn.data.TagDataManager; @@ -219,7 +219,7 @@ public class ServicePage metric = service.getMetric("metrics.http.errors"); if ((metric != null) && (!metric.isEmpty())) { - data.setContent("fooChart", graphicIndex++, BarMonthsChartView.build(metric, ChartColors.RED)); + data.setContent("fooChart", graphicIndex++, BarMonthsChartView.build(metric, ChartColor.RED)); } // diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java index b8edc65..3cbb424 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarMonthsChartView.java @@ -50,7 +50,7 @@ public class BarMonthsChartView { String result; - result = build(metric, ChartColors.BLUE); + result = build(metric, ChartColor.BLUE); // return result; @@ -64,7 +64,7 @@ public class BarMonthsChartView * @return the string * @throws StatoolInfosException */ - public static String build(final Metric metric, final ChartColors color) throws StatoolInfosException + public static String build(final Metric metric, final ChartColor color) throws StatoolInfosException { String result; @@ -95,7 +95,7 @@ public class BarMonthsChartView * @throws StatoolInfosException * the statool infos exception */ - public static String build(final String title, final String description, final StringList labels, final StringList values, final ChartColors color) throws StatoolInfosException + public static String build(final String title, final String description, final StringList labels, final StringList values, final ChartColor color) throws StatoolInfosException { String result; try diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/BarTimeChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarTimeChartView.java index 1595101..6b2bcff 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/BarTimeChartView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarTimeChartView.java @@ -29,7 +29,7 @@ import fr.devinsy.strings.StringList; import fr.devinsy.xidyn.utils.XidynUtils; /** - * The Class projectsRawPageBuilder. + * The Class BarTimeChartView. */ public class BarTimeChartView { diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/ChartColors.java b/src/fr/devinsy/statoolinfos/htmlize/charts/ChartColor.java similarity index 92% rename from src/fr/devinsy/statoolinfos/htmlize/charts/ChartColors.java rename to src/fr/devinsy/statoolinfos/htmlize/charts/ChartColor.java index d4e7dd4..fae95fb 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/ChartColors.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/ChartColor.java @@ -19,16 +19,16 @@ package fr.devinsy.statoolinfos.htmlize.charts; /** - * The Enum ChartColors. + * The Enum ChartColor. */ -public enum ChartColors +public enum ChartColor { RED("rgb(255, 99, 132)"), ORANGE("rgb(255, 159, 64)"), YELLOW("rgb(255, 205, 86)"), GREEN("rgb(75, 192, 192)"), BLUE("rgb(54, 162, 235)"), - PURPLE("'rgb(153, 102, 255)"), + PURPLE("rgb(153, 102, 255)"), GREY("rgb(201, 203, 207)"); private String code; @@ -40,7 +40,7 @@ public enum ChartColors * @param code * the code */ - ChartColors(final String code) + ChartColor(final String code) { this.code = code; this.light = code.replace(")", ", 0.2)"); @@ -62,7 +62,7 @@ public enum ChartColors } /** - * Gamma. + * Light. * * @return the string */ diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/PieChart.java b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChart.java new file mode 100644 index 0000000..f8d97ea --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChart.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2020 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.charts; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.strings.StringList; + +/** + * The Class PieChart. + */ +public class PieChart +{ + private static Logger logger = LoggerFactory.getLogger(PieChart.class); + + private String title; + private boolean displayTitle; + private PieChartDatas datas; + + /** + * Instantiates a new pie chart. + */ + public PieChart(final String title) + { + this.title = title; + this.displayTitle = true; + this.datas = new PieChartDatas(); + } + + /** + * Adds the. + * + * @param label + * the label + * @param value + * the value + * @param color + * the color + */ + public void add(final String label, final double value, final ChartColor color) + { + this.datas.add(new PieChartData(label, value, color)); + } + + /** + * Gets the colors. + * + * @return the colors + */ + public StringList getColors() + { + StringList result; + + result = new StringList(); + + for (PieChartData data : this.datas) + { + result.add(data.getColor().code()); + } + + // + return result; + } + + public PieChartDatas getDatas() + { + return this.datas; + } + + /** + * Gets the labels. + * + * @return the labels + */ + public StringList getLabels() + { + StringList result; + + result = new StringList(); + + for (PieChartData data : this.datas) + { + result.add(data.getLabel()); + } + + // + return result; + } + + public String getTitle() + { + return this.title; + } + + /** + * Gets the values. + * + * @return the values + */ + public double[] getValues() + { + double[] result; + + result = new double[this.datas.size()]; + + int index = 0; + for (PieChartData data : this.datas) + { + result[index] = data.getValue(); + index += 1; + } + + // + return result; + } + + public boolean isDisplayTitle() + { + return this.displayTitle; + } + + public void setDisplayTitle(final boolean displayTitle) + { + this.displayTitle = displayTitle; + } + + public void setTitle(final String title) + { + this.title = title; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartData.java b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartData.java new file mode 100644 index 0000000..78f21c4 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartData.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2020 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.charts; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class PieChartData. + */ +public class PieChartData +{ + private static Logger logger = LoggerFactory.getLogger(PieChartData.class); + + private String label; + private double value; + private ChartColor color; + + /** + * Instantiates a new pie chart data. + * + * @param label + * the label + * @param value + * the value + * @param color + * the color + */ + public PieChartData(final String label, final double value, final ChartColor color) + { + this.label = label; + this.value = value; + this.color = color; + } + + public ChartColor getColor() + { + return this.color; + } + + public String getLabel() + { + return this.label; + } + + public double getValue() + { + return this.value; + } + + public void setColor(final ChartColor color) + { + this.color = color; + } + + public void setLabel(final String label) + { + this.label = label; + } + + public void setValue(final double value) + { + this.value = value; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartDatas.java b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartDatas.java new file mode 100644 index 0000000..ef23276 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartDatas.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2020 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.charts; + +import java.util.ArrayList; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class PieChartDatas. + */ +public class PieChartDatas extends ArrayList +{ + private static final long serialVersionUID = 6300072061870020566L; + + private static Logger logger = LoggerFactory.getLogger(PieChartDatas.class); + + /** + * Instantiates a new pie chart datas. + */ + public PieChartDatas() + { + super(); + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java new file mode 100644 index 0000000..3e8c28f --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2020 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.charts; + +import java.io.IOException; + +import org.apache.commons.codec.digest.DigestUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.strings.StringList; +import fr.devinsy.xidyn.utils.XidynUtils; + +/** + * The Class PieChartView. + */ +public class PieChartView +{ + private static Logger logger = LoggerFactory.getLogger(PieChartView.class); + + /** + * Builds the. + * + * @param pie + * the pie + * @return the string + * @throws StatoolInfosException + */ + public static String build(final PieChart pie) throws StatoolInfosException + { + String result; + + result = build(pie.getTitle(), pie.getLabels(), new StringList(pie.getValues()), pie.getColors()); + + // + return result; + } + + /** + * Builds the. + * + * @param title + * the title + * @param description + * the description + * @param labels + * the labels + * @param values + * the values + * @param color + * the color + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final String title, final StringList labels, final StringList values, final StringList colors) throws StatoolInfosException + { + String result; + try + { + String source = XidynUtils.load(PieChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml")); + result = XidynUtils.extractBodyContent(source); + + result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(title + "PieChart")); + result = result.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(values)); + result = result.replaceFirst("backgroundColor: \\[.*\\]", "backgroundColor: " + ChabuUtils.toJSonStrings(colors)); + result = result.replaceFirst("text: '.*'", "text: '" + title.replace("'", "\\\\'") + "'"); + result = result.replaceFirst("labels: \\[.*\\]", "labels: " + ChabuUtils.toJSonStrings(labels)); + } + catch (IOException exception) + { + throw new StatoolInfosException("Error building bar months chart view: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml new file mode 100644 index 0000000..6137b0c --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml @@ -0,0 +1,49 @@ + + + + + StatoolInfos + + + + + + + + + + + + + + diff --git a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml new file mode 100644 index 0000000..004072b --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml @@ -0,0 +1,28 @@ + + + + + StatoolInfos + + + + + + + +
+ +

Statistiques

+
+
+
+
+
+
+
+
+
+
+ + diff --git a/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml index 2e87188..ad501c1 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml @@ -30,6 +30,7 @@ Réseaux sociaux Fichiers Propriétés + Statistiques
diff --git a/src/fr/devinsy/statoolinfos/stats/StatAgent.java b/src/fr/devinsy/statoolinfos/stats/StatAgent.java index 93c0351..eb6a421 100644 --- a/src/fr/devinsy/statoolinfos/stats/StatAgent.java +++ b/src/fr/devinsy/statoolinfos/stats/StatAgent.java @@ -21,6 +21,7 @@ package fr.devinsy.statoolinfos.stats; import java.io.IOException; import java.net.MalformedURLException; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,8 +37,11 @@ import fr.devinsy.statoolinfos.core.Softwares; import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.statoolinfos.stats.categories.CategoryStat; import fr.devinsy.statoolinfos.stats.categories.CategoryStats; +import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats; import fr.devinsy.statoolinfos.stats.properties.PropertyStats; 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.softwares.SoftwareStat; import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats; import fr.devinsy.strings.StringSet; @@ -211,6 +215,52 @@ public class StatAgent return result; } + /** + * Stat host provider type. + * + * @param federation + * the federation + * @return the host provider type stats + */ + public static HostProviderTypeStats statHostProviderType(final Federation federation) + { + HostProviderTypeStats result; + + result = new HostProviderTypeStats(); + + // + for (Service service : federation.getAllServices()) + { + result.inc(service.getHostProviderType()); + } + + // + return result; + } + + /** + * Stat host server type. + * + * @param federation + * the federation + * @return the host server type stats + */ + public static HostServerTypeStats statHostServerType(final Federation federation) + { + HostServerTypeStats result; + + result = new HostServerTypeStats(); + + // + for (Service service : federation.getAllServices()) + { + result.inc(service.getHostServerType()); + } + + // + return result; + } + /** * Stat organizations properties. * @@ -251,4 +301,34 @@ public class StatAgent // return result; } + + /** + * Stats organization turnout. + * + * @param federation + * the federation + * @return the organization turnout stats + */ + public static OrganizationTurnoutStats statsOrganizationTurnout(final Federation federation) + { + OrganizationTurnoutStats result; + + result = new OrganizationTurnoutStats(); + + // + for (Organization organization : federation.getOrganizations()) + { + if (StringUtils.isBlank(organization.getStartDate())) + { + result.incPassiveCount(); + } + else + { + result.incActiveCount(); + } + } + + // + return result; + } } diff --git a/src/fr/devinsy/statoolinfos/stats/organizations/OrganizationTurnoutStats.java b/src/fr/devinsy/statoolinfos/stats/organizations/OrganizationTurnoutStats.java new file mode 100644 index 0000000..3e8d622 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/organizations/OrganizationTurnoutStats.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2020 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.organizations; + +/** + * The Class OrganizationTurnoutStats. + */ +public class OrganizationTurnoutStats +{ + private long activeCount; + private long passiveCount; + + /** + * Instantiates a new organization turnout stats. + * + * @param name + * the name + */ + public OrganizationTurnoutStats() + { + this.activeCount = 0; + this.passiveCount = 0; + } + + public long getActiveCount() + { + return this.activeCount; + } + + public long getPassiveCount() + { + return this.passiveCount; + } + + /** + * Gets the total count. + * + * @return the total count + */ + public long getTotalCount() + { + long result; + + result = this.activeCount + this.passiveCount; + + // + return result; + } + + public void incActiveCount() + { + this.activeCount += 1; + } + + public void incPassiveCount() + { + this.passiveCount += 1; + } + + public void setActiveCount(final long activeCount) + { + this.activeCount = activeCount; + } + + public void setPassiveCount(final long passiveCount) + { + this.passiveCount = passiveCount; + } +} diff --git a/src/fr/devinsy/statoolinfos/stats/services/HostProviderTypeStats.java b/src/fr/devinsy/statoolinfos/stats/services/HostProviderTypeStats.java new file mode 100644 index 0000000..36734bc --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/services/HostProviderTypeStats.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2020 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.HostProviderType; + +/** + * The Class HostProviderTypeStats. + */ +public class HostProviderTypeStats +{ + private long homeCount; + private long hostedBayCount; + private long hostedServerCount; + private long outsourcedCount; + private long unknownCount; + + /** + * Instantiates a new host provider type stats. + */ + public HostProviderTypeStats() + { + this.homeCount = 0; + this.hostedBayCount = 0; + this.hostedServerCount = 0; + this.outsourcedCount = 0; + this.unknownCount = 0; + } + + public long getHomeCount() + { + return this.homeCount; + } + + public long getHostedBayCount() + { + return this.hostedBayCount; + } + + public long getHostedServerCount() + { + return this.hostedServerCount; + } + + public long getOutsourcedCount() + { + return this.outsourcedCount; + } + + public long getUnknownCount() + { + return this.unknownCount; + } + + /** + * Inc. + * + * @param type + * the type + */ + public void inc(final HostProviderType type) + { + switch (type) + { + case HOME: + this.homeCount += 1; + break; + case HOSTEDBAY: + this.hostedBayCount += 1; + break; + case HOSTEDSERVER: + this.hostedServerCount += 1; + break; + case OUTSOURCED: + this.outsourcedCount += 1; + break; + default: + this.unknownCount += 1; + } + } +} diff --git a/src/fr/devinsy/statoolinfos/stats/services/HostServerTypeStats.java b/src/fr/devinsy/statoolinfos/stats/services/HostServerTypeStats.java new file mode 100644 index 0000000..546a6b4 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/services/HostServerTypeStats.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2020 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.HostServerType; + +/** + * The Class HostServerTypeStats. + */ +public class HostServerTypeStats +{ + private long nanoCount; + private long physicalCount; + private long virtualCount; + private long sharedCount; + private long cloudCount; + private long unknownCount; + + /** + * Instantiates a new host server type stats. + */ + public HostServerTypeStats() + { + this.nanoCount = 0; + this.physicalCount = 0; + this.virtualCount = 0; + this.sharedCount = 0; + this.cloudCount = 0; + this.unknownCount = 0; + } + + public long getCloudCount() + { + return this.cloudCount; + } + + public long getNanoCount() + { + return this.nanoCount; + } + + public long getPhysicalCount() + { + return this.physicalCount; + } + + public long getSharedCount() + { + return this.sharedCount; + } + + public long getUnknownCount() + { + return this.unknownCount; + } + + public long getVirtualCount() + { + return this.virtualCount; + } + + /** + * Inc. + * + * @param type + * the type + */ + public void inc(final HostServerType type) + { + switch (type) + { + case NANO: + this.nanoCount += 1; + break; + case PHYSICAL: + this.physicalCount += 1; + break; + case VIRTUAL: + this.virtualCount += 1; + break; + case SHARED: + this.sharedCount += 1; + break; + case CLOUD: + this.cloudCount += 1; + break; + default: + this.unknownCount += 1; + } + } +}