Added federation statistics. Improved chart management.

This commit is contained in:
Christian P. MOMON 2020-11-19 02:11:52 +01:00
parent 56132be606
commit 8db08a2dfd
16 changed files with 854 additions and 74 deletions

View file

@ -64,6 +64,15 @@ public class Service extends PathPropertyList
UNKNOWN UNKNOWN
} }
public enum RegistrationType
{
NONE,
FREE,
MEMBER,
CLIENT,
UNKNOWN
}
public enum Status public enum Status
{ {
OK, OK,

View file

@ -29,13 +29,18 @@ import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Federation;
import fr.devinsy.statoolinfos.core.StatoolInfosException; 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.DoughnutChartView;
import fr.devinsy.statoolinfos.htmlize.charts.PieChart; 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.htmlize.charts.PieChartView;
import fr.devinsy.statoolinfos.stats.StatAgent; import fr.devinsy.statoolinfos.stats.StatAgent;
import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats; import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats;
import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats; import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats;
import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats; import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats;
import fr.devinsy.statoolinfos.stats.services.RegistrationStats;
import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils; import fr.devinsy.xidyn.presenters.PresenterUtils;
@ -75,6 +80,7 @@ public class FederationStatsPage
{ {
OrganizationTurnoutStats turnout = StatAgent.statsOrganizationTurnout(federation); OrganizationTurnoutStats turnout = StatAgent.statsOrganizationTurnout(federation);
PieChart pie = Htmlizer.toPieChart(turnout); PieChart pie = Htmlizer.toPieChart(turnout);
pie.setLegendPosition(Position.RIGHT);
data.setContent("turnoutChart", PieChartView.build(pie)); data.setContent("turnoutChart", PieChartView.build(pie));
} }
@ -82,6 +88,7 @@ public class FederationStatsPage
{ {
HostServerTypeStats stats = StatAgent.statHostServerType(federation); HostServerTypeStats stats = StatAgent.statHostServerType(federation);
PieChart pie = Htmlizer.toPieChart(stats); PieChart pie = Htmlizer.toPieChart(stats);
pie.setLegendPosition(Position.RIGHT);
data.setContent("hostServerTypeChart", DoughnutChartView.build(pie)); data.setContent("hostServerTypeChart", DoughnutChartView.build(pie));
} }
@ -89,9 +96,48 @@ public class FederationStatsPage
{ {
HostProviderTypeStats stats = StatAgent.statHostProviderType(federation); HostProviderTypeStats stats = StatAgent.statHostProviderType(federation);
PieChart pie = Htmlizer.toPieChart(stats); PieChart pie = Htmlizer.toPieChart(stats);
pie.setLegendPosition(Position.RIGHT);
data.setContent("hostProviderTypeChart", DoughnutChartView.build(pie)); 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(); String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml", data).toString();

View file

@ -31,11 +31,13 @@ import fr.devinsy.statoolinfos.core.Category;
import fr.devinsy.statoolinfos.core.Configuration; import fr.devinsy.statoolinfos.core.Configuration;
import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.core.StatoolInfosUtils; 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.ChartColor;
import fr.devinsy.statoolinfos.htmlize.charts.PieChart; import fr.devinsy.statoolinfos.htmlize.charts.PieChart;
import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats; import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats;
import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats; import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats;
import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats; import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats;
import fr.devinsy.statoolinfos.stats.services.RegistrationStats;
/** /**
* The Class Htmlizer. * The Class Htmlizer.
@ -274,6 +276,28 @@ public class Htmlizer
SocialNetworksPage.buildAll(); 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. * To pie chart.
* *

View file

@ -0,0 +1,151 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<BarChartData>
{
private static final long serialVersionUID = -5230173915580487951L;
private static Logger logger = LoggerFactory.getLogger(BarChartDatas.class);
/**
* Instantiates a new bar chart datas.
*/
public BarChartDatas()
{
super();
}
}

View file

@ -0,0 +1,71 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize.charts;
import java.util.ArrayList;
import fr.devinsy.strings.StringList;
/**
* The Class ChartColors.
*/
public class ChartColors extends ArrayList<ChartColor>
{
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;
}
}

View file

@ -22,7 +22,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.charts.PieChartView.PieType;
/** /**
* The Class DoughnutChartView. * The Class DoughnutChartView.
@ -44,7 +43,8 @@ public class DoughnutChartView
{ {
String result; String result;
result = PieChartView.build(PieType.DOUGHNUT, pie); pie.setType(PieChart.PieType.DOUGHNUT);
result = PieChartView.build(pie);
// //
return result; return result;

View file

@ -30,9 +30,27 @@ public class PieChart
{ {
private static Logger logger = LoggerFactory.getLogger(PieChart.class); private static Logger logger = LoggerFactory.getLogger(PieChart.class);
public enum PieType
{
DOUGHNUT,
PIE
}
public enum Position
{
TOP,
RIGHT,
BOTTOM,
LEFT
}
private String title; private String title;
private boolean displayTitle; private boolean titleVisible;
private Position titlePosition;
private PieType type;
private PieChartDatas datas; private PieChartDatas datas;
private boolean legendVisible;
private Position legendPosition;
/** /**
* Instantiates a new pie chart. * Instantiates a new pie chart.
@ -40,8 +58,12 @@ public class PieChart
public PieChart(final String title) public PieChart(final String title)
{ {
this.title = title; this.title = title;
this.displayTitle = true; this.titleVisible = true;
this.titlePosition = Position.TOP;
this.type = PieType.PIE;
this.datas = new PieChartDatas(); this.datas = new PieChartDatas();
this.legendVisible = true;
this.legendPosition = Position.TOP;
} }
/** /**
@ -104,11 +126,56 @@ public class PieChart
return result; 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() public String getTitle()
{ {
return this.title; 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. * Gets the values.
* *
@ -131,18 +198,43 @@ public class PieChart
return result; 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) public void setTitle(final String title)
{ {
this.title = 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;
}
} }

View file

@ -35,12 +35,6 @@ public class PieChartView
{ {
private static Logger logger = LoggerFactory.getLogger(PieChartView.class); private static Logger logger = LoggerFactory.getLogger(PieChartView.class);
enum PieType
{
DOUGHNUT,
PIE
}
/** /**
* Builds the. * Builds the.
* *
@ -51,51 +45,6 @@ public class PieChartView
* the statool infos exception * the statool infos exception
*/ */
public static String build(final PieChart pie) throws StatoolInfosException 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; String result;
try try
@ -103,12 +52,15 @@ public class PieChartView
String source = XidynUtils.load(PieChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml")); String source = XidynUtils.load(PieChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/pieChartView.xhtml"));
result = XidynUtils.extractBodyContent(source); result = XidynUtils.extractBodyContent(source);
result = result.replaceFirst("type: '.*'", "type: '" + type.toString().toLowerCase() + "'"); result = result.replaceFirst("type: '.*'", "type: '" + pie.getType().toString().toLowerCase() + "'");
result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(title + "PieChart")); result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(pie.getTitle() + "PieChart"));
result = result.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(values)); result = result.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(new StringList(pie.getValues())));
result = result.replaceFirst("backgroundColor: \\[.*\\]", "backgroundColor: " + ChabuUtils.toJSonStrings(colors)); result = result.replaceFirst("backgroundColor: \\[.*\\]", "backgroundColor: " + ChabuUtils.toJSonStrings(pie.getColors()));
result = result.replaceFirst("text: '.*'", "text: '" + title.replace("'", "\\\\'") + "'"); result = result.replaceFirst("text: '.*'", "text: '" + pie.getTitle().replace("'", "\\\\'") + "'");
result = result.replaceFirst("labels: \\[.*\\]", "labels: " + ChabuUtils.toJSonStrings(labels)); 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) catch (IOException exception)
{ {

View file

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js"></script>
<script src="Chart.bundle.min.js"></script>
<link rel="stylesheet" type="text/css" href="datatables.min.css"/>
<script type="text/javascript" src="datatables.min.js"></script>
</head>
<body>
<canvas id="myChart" width="100%" height="100%"></canvas>
<script>
var ctx = document.getElementById('myChart');
var myChart = new Chart(ctx,
{
type: 'bar',
data:
{
labels: ['New', 'Started', 'Waiting', 'Maybe', 'Resolved', 'Closed'],
datasets:
[{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: ['rgba(255, 99, 132, 0.2)','rgba(54, 162, 235, 0.2)','rgba(255, 206, 86, 0.2)','rgba(75, 192, 192, 0.2)','rgba(153, 102, 255, 0.2)','rgba(255, 159, 64, 0.2)'],
borderColor: ['rgba(255, 99, 132, 1)','rgba(54, 162, 235, 1)','rgba(255, 206, 86, 1)','rgba(75, 192, 192, 1)','rgba(153, 102, 255, 1)','rgba(255, 159, 64, 1)'],
borderWidth: 1
}]
},
options:
{
maintainAspectRatio: false,
display: true,
responsive: true,
legend:
{
display: false,
position: 'top',
},
title:
{
display: true,
text: 'a title'
},
scales:
{
xAxes:
[{
ticks:
{
beginAtZero: true
}
}],
yAxes:
[{
ticks:
{
beginAtZero: true,
suggestedMax: 10,
precision: 0
}
}]
}
}
});
</script>
</body>
</html>

View file

@ -32,15 +32,8 @@ var myChart = new Chart(ctx,
maintainAspectRatio: false, maintainAspectRatio: false,
display: true, display: true,
responsive: true, responsive: true,
legend: legend: { display: true, position: 'right' },
{ title: { display: true, position: 'top', text: 'a title' },
position: 'right',
},
title:
{
display: true,
text: 'a title'
},
} }
}); });
</script> </script>

View file

@ -22,6 +22,19 @@
<div id="hostServerTypeChart" style="width: 250px; height: 200px; display: inline-block; border: 1px solid red;"/> <div id="hostServerTypeChart" style="width: 250px; height: 200px; display: inline-block; border: 1px solid red;"/>
<div id="hostProviderTypeChart" style="width: 250px; height: 200px; display: inline-block; border: 1px solid red;"/> <div id="hostProviderTypeChart" style="width: 250px; height: 200px; display: inline-block; border: 1px solid red;"/>
</div> </div>
<div class="row">
<div id="registrationTypeChart" class="column" style="width: 250px; height: 200px; display: inline-block; border: 1px solid red;"/>
<div class="column">
<div class="row">
<div id="registrationNoneTypeChart" style="width: 125px; height: 100px; display: inline-block; border: 1px solid red;"/>
<div id="registrationFreeTypeChart" style="width: 125px; height: 100px; display: inline-block; border: 1px solid red;"/>
</div>
<div class="row">
<div id="registrationMemberTypeChart" style="width: 125px; height: 100px; display: inline-block; border: 1px solid red;"/>
<div id="registrationClientTypeChart" style="width: 125px; height: 100px; display: inline-block; border: 1px solid red;"/>
</div>
</div>
</div>
</div> </div>
</div> </div>
</body> </body>

View file

@ -31,6 +31,7 @@ import fr.devinsy.statoolinfos.core.Federation;
import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Organization;
import fr.devinsy.statoolinfos.core.Organizations; import fr.devinsy.statoolinfos.core.Organizations;
import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.Service.RegistrationType;
import fr.devinsy.statoolinfos.core.Services; import fr.devinsy.statoolinfos.core.Services;
import fr.devinsy.statoolinfos.core.Software; import fr.devinsy.statoolinfos.core.Software;
import fr.devinsy.statoolinfos.core.Softwares; 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.propertyfiles.PropertiesFileStats;
import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats; import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats;
import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats; 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.SoftwareStat;
import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats; import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats;
import fr.devinsy.strings.StringSet; import fr.devinsy.strings.StringSet;
@ -283,6 +285,48 @@ public class StatAgent
return result; 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 * @param services
* @return * @return

View file

@ -0,0 +1,112 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}
}