diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index 6143f96..3c11da5 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -64,6 +64,15 @@ public class Service extends PathPropertyList UNKNOWN } + public enum RegistrationType + { + NONE, + FREE, + MEMBER, + CLIENT, + UNKNOWN + } + public enum Status { OK, diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java index 1c900fa..506104d 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java @@ -29,13 +29,18 @@ 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.BarChart; +import fr.devinsy.statoolinfos.htmlize.charts.BarChartView; +import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; import fr.devinsy.statoolinfos.htmlize.charts.DoughnutChartView; 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.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.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; @@ -75,6 +80,7 @@ public class FederationStatsPage { OrganizationTurnoutStats turnout = StatAgent.statsOrganizationTurnout(federation); PieChart pie = Htmlizer.toPieChart(turnout); + pie.setLegendPosition(Position.RIGHT); data.setContent("turnoutChart", PieChartView.build(pie)); } @@ -82,6 +88,7 @@ public class FederationStatsPage { HostServerTypeStats stats = StatAgent.statHostServerType(federation); PieChart pie = Htmlizer.toPieChart(stats); + pie.setLegendPosition(Position.RIGHT); data.setContent("hostServerTypeChart", DoughnutChartView.build(pie)); } @@ -89,9 +96,48 @@ public class FederationStatsPage { HostProviderTypeStats stats = StatAgent.statHostProviderType(federation); PieChart pie = Htmlizer.toPieChart(stats); + pie.setLegendPosition(Position.RIGHT); data.setContent("hostProviderTypeChart", DoughnutChartView.build(pie)); } + // + { + RegistrationStats stats = StatAgent.statRegistrationTypes(federation); + + BarChart bar = Htmlizer.toBarChart(stats); + data.setContent("registrationTypeChart", BarChartView.build(bar)); + + PieChart pie = new PieChart("Sans"); + pie.setLegendVisible(false); + pie.add("Sans", stats.getNoneCount(), ChartColor.RED); + pie.add("Autre", stats.getCount() - stats.getNoneCount(), ChartColor.BLUE); + data.setContent("registrationNoneTypeChart", DoughnutChartView.build(pie)); + + pie = new PieChart("Libre"); + pie.setLegendVisible(false); + pie.add("Sans", stats.getFreeCount(), ChartColor.RED); + pie.add("Libre", stats.getCount() - stats.getFreeCount(), ChartColor.BLUE); + data.setContent("registrationFreeTypeChart", DoughnutChartView.build(pie)); + + pie = new PieChart("Membre"); + pie.setLegendVisible(false); + pie.add("Sans", stats.getMemberCount(), ChartColor.RED); + pie.add("Membre", stats.getCount() - stats.getMemberCount(), ChartColor.BLUE); + data.setContent("registrationMemberTypeChart", DoughnutChartView.build(pie)); + + pie = new PieChart("Client"); + pie.setLegendVisible(false); + pie.add("Sans", stats.getClientCount(), ChartColor.RED); + pie.add("Client", stats.getCount() - stats.getClientCount(), ChartColor.BLUE); + data.setContent("registrationClientTypeChart", DoughnutChartView.build(pie)); + + pie = new PieChart("Iconnu"); + pie.setLegendVisible(false); + pie.add("Sans", stats.getClientCount(), ChartColor.RED); + pie.add("Inconnu", stats.getCount() - stats.getClientCount(), ChartColor.BLUE); + data.setContent("registrationUnknownTypeChart", DoughnutChartView.build(pie)); + } + // String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml", data).toString(); diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 821b261..d9df9be 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -31,11 +31,13 @@ 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.BarChart; 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; +import fr.devinsy.statoolinfos.stats.services.RegistrationStats; /** * The Class Htmlizer. @@ -274,6 +276,28 @@ public class Htmlizer SocialNetworksPage.buildAll(); } + /** + * To bar chart. + * + * @param stats + * the stats + * @return the bar chart + */ + public static BarChart toBarChart(final RegistrationStats stats) + { + BarChart result; + + result = new BarChart("Types d'inscription"); + result.add("Sans", stats.getNoneCount(), ChartColor.GREEN); + result.add("Libre", stats.getFreeCount(), ChartColor.PURPLE); + result.add("Membre", stats.getMemberCount(), ChartColor.YELLOW); + result.add("Client", stats.getClientCount(), ChartColor.ORANGE); + result.add("Inconnu", stats.getUnknownCount(), ChartColor.BLUE); + + // + return result; + } + /** * To pie chart. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/BarChart.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChart.java new file mode 100644 index 0000000..53e0b98 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChart.java @@ -0,0 +1,151 @@ +/* + * 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 BarChart. + */ +public class BarChart +{ + private static Logger logger = LoggerFactory.getLogger(BarChart.class); + + private String title; + private boolean displayTitle; + private BarChartDatas datas; + + /** + * Instantiates a new bar chart. + * + * @param title + * the title + */ + public BarChart(final String title) + { + this.title = title; + this.displayTitle = true; + this.datas = new BarChartDatas(); + } + + /** + * 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 BarChartData(label, value, color)); + } + + /** + * Gets the colors. + * + * @return the colors + */ + public ChartColors getColors() + { + ChartColors result; + + result = new ChartColors(); + + for (BarChartData data : this.datas) + { + result.add(data.getColor()); + } + + // + return result; + } + + public BarChartDatas getDatas() + { + return this.datas; + } + + /** + * Gets the labels. + * + * @return the labels + */ + public StringList getLabels() + { + StringList result; + + result = new StringList(); + + for (BarChartData 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 (BarChartData 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/BarChartData.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartData.java new file mode 100644 index 0000000..7984de4 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartData.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 BarChartData. + */ +public class BarChartData +{ + private static Logger logger = LoggerFactory.getLogger(BarChartData.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 BarChartData(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/BarChartDatas.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartDatas.java new file mode 100644 index 0000000..741a743 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartDatas.java @@ -0,0 +1,41 @@ +/* + * 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 BarChartDatas. + */ +public class BarChartDatas extends ArrayList +{ + private static final long serialVersionUID = -5230173915580487951L; + private static Logger logger = LoggerFactory.getLogger(BarChartDatas.class); + + /** + * Instantiates a new bar chart datas. + */ + public BarChartDatas() + { + super(); + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java new file mode 100644 index 0000000..13f9182 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java @@ -0,0 +1,71 @@ +/* + * 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 BarChartView. + */ +public class BarChartView +{ + private static Logger logger = LoggerFactory.getLogger(BarChartView.class); + + /** + * Builds the. + * + * @param bar + * the bar + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final BarChart bar) throws StatoolInfosException + { + String result; + + try + { + String source = XidynUtils.load(BarChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/barChartView.xhtml")); + result = XidynUtils.extractBodyContent(source); + + result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(bar.getTitle() + "PieChart")); + result = result.replaceFirst("labels: \\[.*\\]", "labels: " + ChabuUtils.toJSonStrings(bar.getLabels())); + result = result.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(new StringList(bar.getValues()))); + result = result.replaceFirst("backgroundColor: \\[.*\\]", "backgroundColor: " + ChabuUtils.toJSonStrings(bar.getColors().getCodes())); + result = result.replaceFirst("borderColor: \\[.*\\]", "borderColor: " + ChabuUtils.toJSonStrings(bar.getColors().getLights())); + result = result.replaceFirst("text: '.*'", "text: '" + bar.getTitle().replace("'", "\\\\'") + "'"); + } + 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/ChartColors.java b/src/fr/devinsy/statoolinfos/htmlize/charts/ChartColors.java new file mode 100644 index 0000000..40572a5 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/ChartColors.java @@ -0,0 +1,79 @@ +/* + * 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 fr.devinsy.strings.StringList; + +/** + * The Class ChartColors. + */ +public class ChartColors extends ArrayList +{ + private static final long serialVersionUID = -8084994308407843536L; + + /** + * Instantiates a new chart colors. + */ + public ChartColors() + { + super(); + } + + /** + * Gets the colors. + * + * @return the colors + */ + public StringList getCodes() + { + StringList result; + + result = new StringList(); + + for (ChartColor color : this) + { + result.add(color.code()); + } + + // + return result; + } + + /** + * Gets the light colors. + * + * @return the light colors + */ + public StringList getLights() + { + StringList result; + + result = new StringList(); + + for (ChartColor color : this) + { + result.add(color.light()); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/DoughnutChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/DoughnutChartView.java index d257d0a..56c50c2 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/DoughnutChartView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/DoughnutChartView.java @@ -22,7 +22,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.core.StatoolInfosException; -import fr.devinsy.statoolinfos.htmlize.charts.PieChartView.PieType; /** * The Class DoughnutChartView. @@ -44,7 +43,8 @@ public class DoughnutChartView { String result; - result = PieChartView.build(PieType.DOUGHNUT, pie); + pie.setType(PieChart.PieType.DOUGHNUT); + result = PieChartView.build(pie); // return result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/PieChart.java b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChart.java index f8d97ea..20dd947 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/PieChart.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChart.java @@ -30,9 +30,27 @@ public class PieChart { private static Logger logger = LoggerFactory.getLogger(PieChart.class); + public enum PieType + { + DOUGHNUT, + PIE + } + + public enum Position + { + TOP, + RIGHT, + BOTTOM, + LEFT + } + private String title; - private boolean displayTitle; + private boolean titleVisible; + private Position titlePosition; + private PieType type; private PieChartDatas datas; + private boolean legendVisible; + private Position legendPosition; /** * Instantiates a new pie chart. @@ -40,8 +58,12 @@ public class PieChart public PieChart(final String title) { this.title = title; - this.displayTitle = true; + this.titleVisible = true; + this.titlePosition = Position.TOP; + this.type = PieType.PIE; this.datas = new PieChartDatas(); + this.legendVisible = true; + this.legendPosition = Position.TOP; } /** @@ -104,11 +126,56 @@ public class PieChart return result; } + public Position getLegendPosition() + { + return this.legendPosition; + } + + /** + * Gets the legend position value. + * + * @return the legend position value + */ + public String getLegendPositionValue() + { + String result; + + result = this.legendPosition.toString().toLowerCase(); + + // + return result; + } + public String getTitle() { return this.title; } + public Position getTitlePosition() + { + return this.titlePosition; + } + + /** + * Gets the title position value. + * + * @return the title position value + */ + public String getTitlePositionValue() + { + String result; + + result = this.titlePosition.toString().toLowerCase(); + + // + return result; + } + + public PieType getType() + { + return this.type; + } + /** * Gets the values. * @@ -131,18 +198,43 @@ public class PieChart return result; } - public boolean isDisplayTitle() + public boolean isLegendVisible() { - return this.displayTitle; + return this.legendVisible; } - public void setDisplayTitle(final boolean displayTitle) + public boolean isTitleVisible() { - this.displayTitle = displayTitle; + return this.titleVisible; + } + + public void setLegendPosition(final Position legendPosition) + { + this.legendPosition = legendPosition; + } + + public void setLegendVisible(final boolean legendVisible) + { + this.legendVisible = legendVisible; } public void setTitle(final String title) { this.title = title; } + + public void setTitlePosition(final Position titlePosition) + { + this.titlePosition = titlePosition; + } + + public void setTitleVisible(final boolean titleVisible) + { + this.titleVisible = titleVisible; + } + + public void setType(final PieType type) + { + this.type = type; + } } diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java index 4c5bc7e..beba4c0 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/PieChartView.java @@ -35,12 +35,6 @@ public class PieChartView { private static Logger logger = LoggerFactory.getLogger(PieChartView.class); - enum PieType - { - DOUGHNUT, - PIE - } - /** * Builds the. * @@ -51,51 +45,6 @@ public class PieChartView * the statool infos exception */ public static String build(final PieChart pie) throws StatoolInfosException - { - String result; - - result = build(PieType.PIE, pie); - - // - return result; - } - - /** - * Builds the. - * - * @param pie - * the pie - * @return the string - * @throws StatoolInfosException - */ - public static String build(final PieType type, final PieChart pie) throws StatoolInfosException - { - String result; - - result = build(type, 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 PieType type, final String title, final StringList labels, final StringList values, final StringList colors) throws StatoolInfosException { String result; try @@ -103,12 +52,15 @@ public class PieChartView String source = XidynUtils.load(PieChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml")); result = XidynUtils.extractBodyContent(source); - result = result.replaceFirst("type: '.*'", "type: '" + type.toString().toLowerCase() + "'"); - 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)); + result = result.replaceFirst("type: '.*'", "type: '" + pie.getType().toString().toLowerCase() + "'"); + result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(pie.getTitle() + "PieChart")); + result = result.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(new StringList(pie.getValues()))); + result = result.replaceFirst("backgroundColor: \\[.*\\]", "backgroundColor: " + ChabuUtils.toJSonStrings(pie.getColors())); + result = result.replaceFirst("text: '.*'", "text: '" + pie.getTitle().replace("'", "\\\\'") + "'"); + result = result.replaceFirst("labels: \\[.*\\]", "labels: " + ChabuUtils.toJSonStrings(pie.getLabels())); + result = result.replaceFirst("legend: .*,", String.format("legend: { display: %b, position: '%s' },", pie.isLegendVisible(), pie.getLegendPositionValue())); + result = result.replaceFirst("title: .*,", + String.format("title: { display: %b, position: '%s', text: '%s' },", pie.isTitleVisible(), pie.getTitlePositionValue(), pie.getTitle().replace("'", "\\\\'"))); } catch (IOException exception) { diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/barChartView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/charts/barChartView.xhtml new file mode 100644 index 0000000..1ec11fe --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/barChartView.xhtml @@ -0,0 +1,72 @@ + + + + + StatoolInfos + + + + + + + + + + + + + + diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml index 699442c..c34f638 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml @@ -32,15 +32,8 @@ var myChart = new Chart(ctx, maintainAspectRatio: false, display: true, responsive: true, - legend: - { - position: 'right', - }, - title: - { - display: true, - text: 'a title' - }, + legend: { display: true, position: 'right' }, + title: { display: true, position: 'top', text: 'a title' }, } }); diff --git a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml index 004072b..333943a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml @@ -22,6 +22,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/fr/devinsy/statoolinfos/stats/StatAgent.java b/src/fr/devinsy/statoolinfos/stats/StatAgent.java index eb6a421..ebe530b 100644 --- a/src/fr/devinsy/statoolinfos/stats/StatAgent.java +++ b/src/fr/devinsy/statoolinfos/stats/StatAgent.java @@ -31,6 +31,7 @@ import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Organizations; import fr.devinsy.statoolinfos.core.Service; +import fr.devinsy.statoolinfos.core.Service.RegistrationType; import fr.devinsy.statoolinfos.core.Services; import fr.devinsy.statoolinfos.core.Software; import fr.devinsy.statoolinfos.core.Softwares; @@ -42,6 +43,7 @@ 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.services.RegistrationStats; import fr.devinsy.statoolinfos.stats.softwares.SoftwareStat; import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats; import fr.devinsy.strings.StringSet; @@ -283,6 +285,48 @@ public class StatAgent return result; } + /** + * Stat registration types. + * + * @param federation + * the federation + * @return the registration stats + */ + public static RegistrationStats statRegistrationTypes(final Federation federation) + { + RegistrationStats result; + + result = new RegistrationStats(); + + // + for (Service service : federation.getAllServices()) + { + if (service.isRegistrationNone()) + { + result.inc(RegistrationType.NONE); + } + else if (service.isRegistrationFree()) + { + result.inc(RegistrationType.FREE); + } + else if (service.isRegistrationMember()) + { + result.inc(RegistrationType.MEMBER); + } + else if (service.isRegistrationClient()) + { + result.inc(RegistrationType.CLIENT); + } + else + { + result.inc(RegistrationType.UNKNOWN); + } + } + + // + return result; + } + /** * @param services * @return diff --git a/src/fr/devinsy/statoolinfos/stats/services/RegistrationStats.java b/src/fr/devinsy/statoolinfos/stats/services/RegistrationStats.java new file mode 100644 index 0000000..aab3f54 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/services/RegistrationStats.java @@ -0,0 +1,112 @@ +/* + * 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.RegistrationType; + +/** + * The Class RegistrationStats. + */ +public class RegistrationStats +{ + private long noneCount; + private long freeCount; + private long memberCount; + private long clientCount; + private long unknownCount; + + /** + * Instantiates a new host provider type stats. + */ + public RegistrationStats() + { + this.noneCount = 0; + this.freeCount = 0; + this.memberCount = 0; + this.clientCount = 0; + this.unknownCount = 0; + } + + public long getClientCount() + { + return this.clientCount; + } + + /** + * Gets the count. + * + * @return the count + */ + public long getCount() + { + long result; + + result = this.noneCount + this.freeCount + this.memberCount + this.clientCount + this.unknownCount; + + // + return result; + } + + public long getFreeCount() + { + return this.freeCount; + } + + public long getMemberCount() + { + return this.memberCount; + } + + public long getNoneCount() + { + return this.noneCount; + } + + public long getUnknownCount() + { + return this.unknownCount; + } + + /** + * Inc. + * + * @param type + * the type + */ + public void inc(final RegistrationType type) + { + switch (type) + { + case NONE: + this.noneCount += 1; + break; + case FREE: + this.freeCount += 1; + break; + case MEMBER: + this.memberCount += 1; + break; + case CLIENT: + this.clientCount += 1; + break; + default: + this.unknownCount += 1; + } + } +}