Improved service count federation chart and added organization ones.

This commit is contained in:
Christian P. MOMON 2021-02-20 04:32:56 +01:00
parent e8be6ba8d1
commit 9caf349639
5 changed files with 235 additions and 7 deletions

View file

@ -66,8 +66,10 @@ public class FederationStatsPage
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
TagDataManager data = new TagDataManager();
data.setContent("serviceCountMonthChart", Htmlizer.htmlizeServiceCountMonthChart(federation));
data.setContent("serviceCountYearChart", Htmlizer.htmlizeServiceCountYearChart(federation));
data.setContent("serviceDateStatusChart", Htmlizer.htmlizeServiceDateStatusChart(federation.getAllServices()));
data.setContent("serviceCountChart", Htmlizer.htmlizeServiceCountChart(federation));
data.setContent("turnoutChart", Htmlizer.htmlizeOrganizationTurnoutChart(federation.getOrganizations()));
data.setContent("organizationCountryChart", Htmlizer.htmlizeOrganizationCountryChart(federation.getOrganizations()));

View file

@ -425,21 +425,104 @@ public class Htmlizer
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceCountChart(final Federation federation) throws StatoolInfosException
public static String htmlizeServiceCountMonthChart(final Federation federation) throws StatoolInfosException
{
String result;
result = htmlizeServiceCountMonthChart(federation.getAllServices(),
YearMonth.from(StatoolInfosUtils.parseDate(federation.getStartDate())));
//
return result;
}
/**
* Htmlize service count chart.
*
* @param organization
* the organization
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceCountMonthChart(final Organization organization) throws StatoolInfosException
{
String result;
LocalDate startDate = StatoolInfosUtils.parseDate(organization.getStartDate());
if (startDate == null)
{
result = null;
}
else
{
result = htmlizeServiceCountMonthChart(organization.getServices(), YearMonth.from(startDate));
}
//
return result;
}
/**
* Htmlize service count chart.
*
* @param services
* the services
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceCountMonthChart(final Services services) throws StatoolInfosException
{
String result;
YearMonth first = null;
for (Service service : services)
{
LocalDate date = StatoolInfosUtils.parseDate(service.getStartDate());
if (date != null)
{
YearMonth current = YearMonth.from(date);
if ((first == null) || (first.isBefore(current)))
{
first = current;
}
}
}
result = htmlizeServiceCountMonthChart(services, first);
//
return result;
}
/**
* Htmlize service count chart.
*
* @param services
* the services
* @param start
* the start
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceCountMonthChart(final Services services, final YearMonth first) throws StatoolInfosException
{
String result;
BarChart chart;
chart = new BarChart("Nombre des services");
chart = new BarChart("Nombre de services (mois)");
chart.addDataset("Services");
YearMonth now = YearMonth.now();
YearMonth current = YearMonth.from(StatoolInfosUtils.parseDate(federation.getStartDate()));
YearMonth current = first;
while (current.compareTo(now) <= 0)
{
long count = 0;
for (Service service : federation.getAllServices())
for (Service service : services)
{
LocalDate startDate = StatoolInfosUtils.parseDate(service.getStartDate());
LocalDate endDate = StatoolInfosUtils.parseDate(service.getEndDate());
@ -454,7 +537,7 @@ public class Htmlizer
}
else
{
end = YearMonth.of(endDate.getYear(), endDate.getMonth());
end = YearMonth.from(endDate);
}
if ((current.compareTo(start) >= 0) && (current.compareTo(end) <= 0))
@ -519,6 +602,139 @@ public class Htmlizer
return result;
}
public static String htmlizeServiceCountYearChart(final Federation federation) throws StatoolInfosException
{
String result;
result = htmlizeServiceCountYearChart(federation.getAllServices(),
StatoolInfosUtils.parseDate(federation.getStartDate()).getYear());
//
return result;
}
/**
* Htmlize service count year chart.
*
* @param organization
* the organization
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceCountYearChart(final Organization organization) throws StatoolInfosException
{
String result;
LocalDate startDate = StatoolInfosUtils.parseDate(organization.getStartDate());
if (startDate == null)
{
result = null;
}
else
{
result = htmlizeServiceCountYearChart(organization.getServices(), startDate.getYear());
}
//
return result;
}
/**
* Htmlize service count year chart.
*
* @param services
* the services
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceCountYearChart(final Services services) throws StatoolInfosException
{
String result;
Integer first = null;
for (Service service : services)
{
LocalDate date = StatoolInfosUtils.parseDate(service.getStartDate());
if (date != null)
{
int current = date.getYear();
if ((first == null) || (first < current))
{
first = current;
}
}
}
result = htmlizeServiceCountYearChart(services, first);
//
return result;
}
/**
* Htmlize service count chart.
*
* @param services
* the services
* @param first
* the first
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceCountYearChart(final Services services, final int first) throws StatoolInfosException
{
String result;
BarChart chart;
chart = new BarChart("Nombre de services");
chart.addDataset("Services");
int now = LocalDate.now().getYear();
int current = first;
while (current <= now)
{
long count = 0;
for (Service service : services)
{
LocalDate startDate = StatoolInfosUtils.parseDate(service.getStartDate());
LocalDate endDate = StatoolInfosUtils.parseDate(service.getEndDate());
if (startDate != null)
{
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;
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize service date status chart.
*

View file

@ -84,6 +84,10 @@ public class OrganizationStatsPage
TagDataManager data = new TagDataManager();
data.setContent("serviceCountMonthChart", Htmlizer.htmlizeServiceCountMonthChart(organization));
data.setContent("serviceCountYearChart", Htmlizer.htmlizeServiceCountYearChart(organization));
data.setContent("serviceDateStatusChart", Htmlizer.htmlizeServiceDateStatusChart(organization.getServices()));
data.setContent("turnoutChart", Htmlizer.htmlizeOrganizationTurnoutChart(organization));
data.setContent("hostServerTypeChart", Htmlizer.htmlizeHostServerTypeChart(organization.getServices()));

View file

@ -16,8 +16,9 @@
<h2 id="title" class="center">Statistiques</h2>
<div>
<div>
<div id="serviceCountChart" class="chartborder" style="width: 500px; height: 200px; display: inline-block;"/>
<div id="serviceCountMonthChart" class="chartborder" style="width: 500px; height: 200px; display: inline-block;"/>
<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 id="turnoutChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>

View file

@ -15,6 +15,11 @@
<h2 id="title" class="center">Statistiques</h2>
<div>
<div>
<div id="serviceCountMonthChart" class="chartborder" style="width: 500px; height: 200px; display: inline-block;"/>
<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 id="turnoutChart" class="chartborder" style="width: 250px; height: 200px; display: inline-block;"/>
</div>