Refactored chart htmlize.

This commit is contained in:
Christian P. MOMON 2020-11-19 05:01:19 +01:00
parent 8db08a2dfd
commit d084e3cdd5
5 changed files with 109 additions and 123 deletions

View file

@ -222,7 +222,7 @@ public class PropertyRule
/** /**
* Sets the pattern. * Sets the pattern.
* *
* @param valuePattern * @param regex
* the new pattern * the new pattern
*/ */
public void setPattern(final String regex) public void setPattern(final String regex)

View file

@ -34,12 +34,7 @@ import fr.devinsy.statoolinfos.htmlize.charts.BarChartView;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; 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.stats.StatAgent; 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.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;
@ -55,14 +50,10 @@ public class FederationStatsPage
/** /**
* Builds the. * Builds the.
* *
* @param title
* the title
* @param organizations
* the organizations
* @return the string
* @throws StatoolInfosException * @throws StatoolInfosException
* the statool infos exception * the statool infos exception
* @throws IOException * @throws IOException
* Signals that an I/O exception has occurred.
*/ */
public static void build() throws StatoolInfosException, IOException public static void build() throws StatoolInfosException, IOException
{ {
@ -76,29 +67,9 @@ public class FederationStatsPage
TagDataManager data = new TagDataManager(); TagDataManager data = new TagDataManager();
// data.setContent("turnoutChart", Htmlizer.htmlizeOrganizationTurnoutChart(federation.getOrganizations()));
{ data.setContent("hostServerTypeChart", Htmlizer.htmlizeHostServerTypeChart(federation.getAllServices()));
OrganizationTurnoutStats turnout = StatAgent.statsOrganizationTurnout(federation); data.setContent("hostProviderTypeChart", Htmlizer.htmlizeHostProviderTypeChart(federation.getAllServices()));
PieChart pie = Htmlizer.toPieChart(turnout);
pie.setLegendPosition(Position.RIGHT);
data.setContent("turnoutChart", PieChartView.build(pie));
}
//
{
HostServerTypeStats stats = StatAgent.statHostServerType(federation);
PieChart pie = Htmlizer.toPieChart(stats);
pie.setLegendPosition(Position.RIGHT);
data.setContent("hostServerTypeChart", DoughnutChartView.build(pie));
}
//
{
HostProviderTypeStats stats = StatAgent.statHostProviderType(federation);
PieChart pie = Htmlizer.toPieChart(stats);
pie.setLegendPosition(Position.RIGHT);
data.setContent("hostProviderTypeChart", DoughnutChartView.build(pie));
}
// //
{ {
@ -109,19 +80,19 @@ public class FederationStatsPage
PieChart pie = new PieChart("Sans"); PieChart pie = new PieChart("Sans");
pie.setLegendVisible(false); pie.setLegendVisible(false);
pie.add("Sans", stats.getNoneCount(), ChartColor.RED); pie.add("Sans", stats.getNoneCount(), ChartColor.GREEN);
pie.add("Autre", stats.getCount() - stats.getNoneCount(), ChartColor.BLUE); pie.add("Autre", stats.getCount() - stats.getNoneCount(), ChartColor.BLUE);
data.setContent("registrationNoneTypeChart", DoughnutChartView.build(pie)); data.setContent("registrationNoneTypeChart", DoughnutChartView.build(pie));
pie = new PieChart("Libre"); pie = new PieChart("Libre");
pie.setLegendVisible(false); pie.setLegendVisible(false);
pie.add("Sans", stats.getFreeCount(), ChartColor.RED); pie.add("Sans", stats.getFreeCount(), ChartColor.YELLOW);
pie.add("Libre", stats.getCount() - stats.getFreeCount(), ChartColor.BLUE); pie.add("Libre", stats.getCount() - stats.getFreeCount(), ChartColor.BLUE);
data.setContent("registrationFreeTypeChart", DoughnutChartView.build(pie)); data.setContent("registrationFreeTypeChart", DoughnutChartView.build(pie));
pie = new PieChart("Membre"); pie = new PieChart("Membre");
pie.setLegendVisible(false); pie.setLegendVisible(false);
pie.add("Sans", stats.getMemberCount(), ChartColor.RED); pie.add("Sans", stats.getMemberCount(), ChartColor.ORANGE);
pie.add("Membre", stats.getCount() - stats.getMemberCount(), ChartColor.BLUE); pie.add("Membre", stats.getCount() - stats.getMemberCount(), ChartColor.BLUE);
data.setContent("registrationMemberTypeChart", DoughnutChartView.build(pie)); data.setContent("registrationMemberTypeChart", DoughnutChartView.build(pie));
@ -130,12 +101,6 @@ public class FederationStatsPage
pie.add("Sans", stats.getClientCount(), ChartColor.RED); pie.add("Sans", stats.getClientCount(), ChartColor.RED);
pie.add("Client", stats.getCount() - stats.getClientCount(), ChartColor.BLUE); pie.add("Client", stats.getCount() - stats.getClientCount(), ChartColor.BLUE);
data.setContent("registrationClientTypeChart", DoughnutChartView.build(pie)); 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));
} }
// //

View file

@ -29,11 +29,17 @@ import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.core.Category; import fr.devinsy.statoolinfos.core.Category;
import fr.devinsy.statoolinfos.core.Configuration; import fr.devinsy.statoolinfos.core.Configuration;
import fr.devinsy.statoolinfos.core.Organizations;
import fr.devinsy.statoolinfos.core.Services;
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.BarChart;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; 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;
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.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;
@ -276,6 +282,88 @@ public class Htmlizer
SocialNetworksPage.buildAll(); SocialNetworksPage.buildAll();
} }
/**
* Htmlize host provider type chart.
*
* @param services
* the services
* @return the string
* @throws StatoolInfosException
*/
public static String htmlizeHostProviderTypeChart(final Services services) throws StatoolInfosException
{
String result;
HostProviderTypeStats stats = StatAgent.statHostProviderType(services);
PieChart pie = new PieChart("Types d'hébergement");
pie.add("Home", stats.getHomeCount(), ChartColor.GREEN);
pie.add("Baie", stats.getHostedBayCount(), ChartColor.YELLOW);
pie.add("Serveur", stats.getHostedServerCount(), ChartColor.ORANGE);
pie.add("Externalisé", stats.getOutsourcedCount(), ChartColor.RED);
pie.add("Inconnu", stats.getUnknownCount(), ChartColor.BLUE);
pie.setLegendPosition(Position.RIGHT);
result = DoughnutChartView.build(pie);
//
return result;
}
/**
* Htmlize host server type chart.
*
* @param services
* the services
* @return the string
* @throws StatoolInfosException
*/
public static String htmlizeHostServerTypeChart(final Services services) throws StatoolInfosException
{
String result;
HostServerTypeStats stats = StatAgent.statHostServerType(services);
PieChart pie = new PieChart("Types de serveur");
pie.add("Nano", stats.getNanoCount(), ChartColor.PURPLE);
pie.add("Physique", stats.getPhysicalCount(), ChartColor.GREEN);
pie.add("Virtuel", stats.getVirtualCount(), ChartColor.YELLOW);
pie.add("Mutualisé", stats.getSharedCount(), ChartColor.ORANGE);
pie.add("Cloud", stats.getCloudCount(), ChartColor.RED);
pie.add("Inconnu", stats.getUnknownCount(), ChartColor.BLUE);
pie.setLegendPosition(Position.RIGHT);
result = DoughnutChartView.build(pie);
//
return result;
}
/**
* Htmlize organization turnout chart.
*
* @param organizations
* the organizations
* @return the string
* @throws StatoolInfosException
*/
public static String htmlizeOrganizationTurnoutChart(final Organizations organizations) throws StatoolInfosException
{
String result;
OrganizationTurnoutStats stats = StatAgent.statsOrganizationTurnout(organizations);
PieChart pie = new PieChart("Participation");
pie.add("Active", stats.getActiveCount(), ChartColor.GREEN);
pie.add("Passive", stats.getPassiveCount(), ChartColor.BLUE);
pie.setLegendPosition(Position.RIGHT);
result = PieChartView.build(pie);
//
return result;
}
/** /**
* To bar chart. * To bar chart.
* *
@ -289,76 +377,12 @@ public class Htmlizer
result = new BarChart("Types d'inscription"); result = new BarChart("Types d'inscription");
result.add("Sans", stats.getNoneCount(), ChartColor.GREEN); result.add("Sans", stats.getNoneCount(), ChartColor.GREEN);
result.add("Libre", stats.getFreeCount(), ChartColor.PURPLE); result.add("Libre", stats.getFreeCount(), ChartColor.YELLOW);
result.add("Membre", stats.getMemberCount(), ChartColor.YELLOW); result.add("Membre", stats.getMemberCount(), ChartColor.ORANGE);
result.add("Client", stats.getClientCount(), ChartColor.ORANGE); result.add("Client", stats.getClientCount(), ChartColor.RED);
result.add("Inconnu", stats.getUnknownCount(), ChartColor.BLUE); result.add("Inconnu", stats.getUnknownCount(), ChartColor.BLUE);
// //
return result; return result;
} }
/**
* 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.RED);
result.add("Passive", stats.getPassiveCount(), ChartColor.BLUE);
//
return result;
}
} }

View file

@ -220,18 +220,18 @@ public class StatAgent
/** /**
* Stat host provider type. * Stat host provider type.
* *
* @param federation * @param services
* the federation * the services
* @return the host provider type stats * @return the host provider type stats
*/ */
public static HostProviderTypeStats statHostProviderType(final Federation federation) public static HostProviderTypeStats statHostProviderType(final Services services)
{ {
HostProviderTypeStats result; HostProviderTypeStats result;
result = new HostProviderTypeStats(); result = new HostProviderTypeStats();
// //
for (Service service : federation.getAllServices()) for (Service service : services)
{ {
result.inc(service.getHostProviderType()); result.inc(service.getHostProviderType());
} }
@ -247,14 +247,14 @@ public class StatAgent
* the federation * the federation
* @return the host server type stats * @return the host server type stats
*/ */
public static HostServerTypeStats statHostServerType(final Federation federation) public static HostServerTypeStats statHostServerType(final Services services)
{ {
HostServerTypeStats result; HostServerTypeStats result;
result = new HostServerTypeStats(); result = new HostServerTypeStats();
// //
for (Service service : federation.getAllServices()) for (Service service : services)
{ {
result.inc(service.getHostServerType()); result.inc(service.getHostServerType());
} }
@ -349,18 +349,18 @@ public class StatAgent
/** /**
* Stats organization turnout. * Stats organization turnout.
* *
* @param federation * @param organizations
* the federation * the organizations
* @return the organization turnout stats * @return the organization turnout stats
*/ */
public static OrganizationTurnoutStats statsOrganizationTurnout(final Federation federation) public static OrganizationTurnoutStats statsOrganizationTurnout(final Organizations organizations)
{ {
OrganizationTurnoutStats result; OrganizationTurnoutStats result;
result = new OrganizationTurnoutStats(); result = new OrganizationTurnoutStats();
// //
for (Organization organization : federation.getOrganizations()) for (Organization organization : organizations)
{ {
if (StringUtils.isBlank(organization.getStartDate())) if (StringUtils.isBlank(organization.getStartDate()))
{ {

View file

@ -28,9 +28,6 @@ public class OrganizationTurnoutStats
/** /**
* Instantiates a new organization turnout stats. * Instantiates a new organization turnout stats.
*
* @param name
* the name
*/ */
public OrganizationTurnoutStats() public OrganizationTurnoutStats()
{ {