Added service stats page.

This commit is contained in:
Christian P. MOMON 2021-05-26 02:06:15 +02:00
parent 08a88600ef
commit 0e3dbd7e05
7 changed files with 248 additions and 26 deletions

View file

@ -140,4 +140,26 @@ public class Services extends ArrayList<Service>
//
return result;
}
/**
* Of.
*
* @param service
* the service
* @return the services
*/
public static Services of(final Service service)
{
Services result;
result = new Services();
if (service != null)
{
result.add(service);
}
//
return result;
}
}

View file

@ -587,6 +587,34 @@ public class ChartHtmlizer
return result;
}
/**
* Htmlize organization turnout chart.
*
* @param service
* the service
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeOrganizationTurnoutChart(final Service service) throws StatoolInfosException
{
String result;
OrganizationTurnoutStats stats = StatAgent.statsOrganizationTurnout(service);
PieChart pie = new PieChart("Participation");
pie.add("1 fichier", stats.getWithSelfFileCount(), ChartColor.ORANGE);
pie.add("n fichiers", stats.getWithServiceFileCount(), ChartColor.YELLOW);
pie.add("Métriques", stats.getWithServiceMetricCount(), ChartColor.GREEN);
pie.add("Passive", stats.getPassiveCount(), ChartColor.BLUE);
pie.setLegendPosition(Position.RIGHT);
result = PieChartView.build(pie);
//
return result;
}
/**
* Htmlize registration chart.
*
@ -988,7 +1016,7 @@ public class ChartHtmlizer
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceCountYearChart(final Services services, final int first) throws StatoolInfosException
public static String htmlizeServiceCountYearChart(final Services services, final Integer first) throws StatoolInfosException
{
String result;
@ -997,39 +1025,42 @@ public class ChartHtmlizer
chart = new BarChart("Nombre de services");
chart.addDataset("Services");
int now = LocalDate.now().getYear();
int current = first;
while (current <= now)
if (first != null)
{
long count = 0;
for (Service service : services)
int now = LocalDate.now().getYear();
int current = first;
while (current <= now)
{
LocalDate startDate = StatoolInfosUtils.parseDate(service.getStartDate());
LocalDate endDate = StatoolInfosUtils.parseDate(service.getEndDate());
if (startDate != null)
long count = 0;
for (Service service : services)
{
int start = startDate.getYear();
int end;
if (endDate == null)
{
end = now;
}
else
{
end = endDate.getYear();
}
LocalDate startDate = StatoolInfosUtils.parseDate(service.getStartDate());
LocalDate endDate = StatoolInfosUtils.parseDate(service.getEndDate());
if ((current >= start) && (current <= end))
if (startDate != null)
{
count += 1;
int start = startDate.getYear();
int end;
if (endDate == null)
{
end = now;
}
else
{
end = endDate.getYear();
}
if ((current >= start) && (current <= end))
{
count += 1;
}
}
}
chart.add(String.valueOf(current), count, ChartColor.VIOLET);
current += 1;
}
chart.add(String.valueOf(current), count, ChartColor.VIOLET);
current += 1;
}
result = BarChartView.build(chart);

View file

@ -38,6 +38,7 @@ public class ServiceMetricMenuView
public enum MenuItem
{
SUMMARY,
GENERAL,
GENERIC,
WEB,
SPECIFIC
@ -61,6 +62,7 @@ public class ServiceMetricMenuView
TagDataManager data = new TagDataManager();
data.setAttribute("summaryTypeButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml");
data.setAttribute("generalTypeButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-general.xhtml");
data.setAttribute("genericTypeButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-generic.xhtml");
data.setAttribute("webTypeButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-web.xhtml");
data.setAttribute("specificTypeButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-specific.xhtml");
@ -69,6 +71,10 @@ public class ServiceMetricMenuView
{
data.appendAttribute("summaryTypeButton", "class", "button selected");
}
else if (item == MenuItem.GENERAL)
{
data.appendAttribute("generalTypeButton", "class", "button selected");
}
else if (item == MenuItem.GENERIC)
{
data.appendAttribute("genericTypeButton", "class", "button selected");

View file

@ -79,6 +79,11 @@ public class ServicePage
String page = ServicePage.htmlize(service);
FileUtils.write(new File(htmlizeDirectory, service.getLocalFileBaseName() + ".xhtml"), page, StandardCharsets.UTF_8);
//
logger.info("Htmlize service general metric page: {}.", service.getName());
page = ServiceStatsPage.htmlize(service);
FileUtils.write(new File(htmlizeDirectory, service.getLocalFileBaseName() + "-metrics-general.xhtml"), page, StandardCharsets.UTF_8);
//
logger.info("Htmlize service generic metric page: {}.", service.getName());
page = ServiceGenericMetricPage.htmlize(service);

View file

@ -0,0 +1,104 @@
/*
* Copyright (C) 2020-2021 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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.Services;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem;
import fr.devinsy.statoolinfos.stats.StatAgent;
import fr.devinsy.statoolinfos.stats.services.RegistrationStats;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
/**
* The Class ServiceStatsPage.
*/
public class ServiceStatsPage
{
private static Logger logger = LoggerFactory.getLogger(ServiceStatsPage.class);
/**
* Builds the.
*
* @param service
* the service
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlize(final Service service) throws StatoolInfosException
{
String result;
try
{
logger.debug("Building service stats page {}…", service.get("service.name"));
TagDataManager data = new TagDataManager();
//
data.setContent("headerView", ServiceHeaderView.htmlize(service));
data.setContent("serviceMetricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.GENERAL));
//
data.setContent("turnoutChart", ChartHtmlizer.htmlizeOrganizationTurnoutChart(service));
Services mock = Services.of(service);
data.setContent("hostServerTypeChart", ChartHtmlizer.htmlizeHostServerTypeChart(mock));
data.setContent("hostProviderTypeChart", ChartHtmlizer.htmlizeHostProviderTypeChart(mock));
data.setContent("serviceInstallTypeChart", ChartHtmlizer.htmlizeServiceInstallTypeChart(mock));
data.setContent("serviceCountryChart", ChartHtmlizer.htmlizeServiceCountryChart(mock));
//
{
RegistrationStats stats = StatAgent.statRegistrationTypes(mock);
data.setContent("registrationTypeChart", ChartHtmlizer.htmlizeRegistrationBarChart(stats));
data.setContent("registrationNoneTypeChart", ChartHtmlizer.htmlizeRegistrationNonePieChart(stats));
data.setContent("registrationFreeTypeChart", ChartHtmlizer.htmlizeRegistrationFreePieChart(stats));
data.setContent("registrationMemberTypeChart", ChartHtmlizer.htmlizeRegistrationMemberPieChart(stats));
data.setContent("registrationClientTypeChart", ChartHtmlizer.htmlizeRegistrationClientPieChart(stats));
}
data.setContent("serviceCountYearChart", ChartHtmlizer.htmlizeServiceCountYearChart(mock));
data.setContent("serviceDateStatusChart", ChartHtmlizer.htmlizeServiceDateStatusChart(mock));
//
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceStats.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml");
trail.add(service.getName(), service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml");
result = WebCharterView.build(content, trail);
}
catch (XidynException exception)
{
throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception);
}
//
return result;
}
}

View file

@ -15,6 +15,7 @@
<div style="margin: 5px;">
<span style="display: inline-block; width: 100px">Type</span>
<a onclick="javascript:selectTypeMenu('summary');" href="#" id="summaryTypeButton" class="button">Résumé</a>
<a onclick="javascript:selectTypeMenu('general');" href="#" id="generalTypeButton" class="button">Général</a>
<a onclick="javascript:selectTypeMenu('generic');" href="#" id="genericTypeButton" class="button">Génériques</a>
<a onclick="javascript:selectTypeMenu('web');" href="#" id="webTypeButton" class="button">Web</a>
<a onclick="javascript:selectTypeMenu('specific');" href="#" id="specificTypeButton" class="button">Spécifiques</a>
@ -39,6 +40,7 @@
function selectTypeMenu(selection)
{
document.getElementById ('summaryTypeButton').classList.remove('selected');
document.getElementById ('generalTypeButton').classList.remove('selected');
document.getElementById ('genericTypeButton').classList.remove('selected');
document.getElementById ('webTypeButton').classList.remove('selected');
document.getElementById ('specificTypeButton').classList.remove('selected');
@ -51,6 +53,10 @@ function selectTypeMenu(selection)
{
document.getElementById ('genericTypeButton').classList.add('selected');
}
else if (selection == 'general')
{
document.getElementById ('generalTypeButton').classList.add('selected');
}
else if (selection == 'web')
{
document.getElementById ('webTypeButton').classList.add('selected');

View file

@ -0,0 +1,48 @@
<?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 src="Chart.bundle.min.js"></script>
</head>
<body>
<div id="headerView" />
<div id="metricZone">
<h2 id="title" class="center">Statistiques</h2>
<div id="serviceMetricMenuView" />
<div>
<div>
<div id="turnoutChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
</div>
<div>
<div id="hostServerTypeChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
<div id="hostProviderTypeChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
<div id="serviceInstallTypeChart" class="chartborder" style="width: 250px; height: 230px; display: inline-block; vertical-align: top;"/>
<div id="serviceCountryChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
</div>
<div class="row">
<div id="registrationTypeChart" class="column chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
<div class="column">
<div class="row">
<div id="registrationNoneTypeChart" class="chartborder" style="width: 122px; height: 97px; display: inline-block;"/>
<div id="registrationFreeTypeChart" class="chartborder" style="width: 122px; height: 97px; display: inline-block;"/>
</div>
<div class="row">
<div id="registrationMemberTypeChart" class="chartborder" style="width: 122px; height: 97px; display: inline-block;"/>
<div id="registrationClientTypeChart" class="chartborder" style="width: 122px; height: 97px; display: inline-block;"/>
</div>
</div>
</div>
<div>
<div id="serviceDateStatusChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
<div id="serviceCountYearChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
</div>
</div>
</div>
</body>
</html>