statoolinfosweb/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java

1561 lines
45 KiB
Java

/*
* Copyright (C) 2020-2022 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 java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Year;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.extra.YearWeek;
import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.core.Categories;
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.Services;
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.BarChartView;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColors;
import fr.devinsy.statoolinfos.htmlize.charts.DoughnutChartView;
import fr.devinsy.statoolinfos.htmlize.charts.MonthValues;
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.WeekValues;
import fr.devinsy.statoolinfos.htmlize.charts.YearValues;
import fr.devinsy.statoolinfos.metrics.StringCounter;
import fr.devinsy.statoolinfos.metrics.StringCounterList;
import fr.devinsy.statoolinfos.metrics.StringCounters;
import fr.devinsy.statoolinfos.properties.PathProperty;
import fr.devinsy.statoolinfos.properties.PathPropertyList;
import fr.devinsy.statoolinfos.stats.StatAgent;
import fr.devinsy.statoolinfos.stats.categories.CategoryStat;
import fr.devinsy.statoolinfos.stats.categories.CategoryStats;
import fr.devinsy.statoolinfos.stats.country.CountryStats;
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.ServiceInstallTypeStats;
import fr.devinsy.statoolinfos.stats.softwares.SoftwareStat;
import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats;
import fr.devinsy.strings.StringList;
/**
* The Class ChartHtmlizer.
*/
public class ChartHtmlizer
{
private static Logger logger = LoggerFactory.getLogger(ChartHtmlizer.class);
/**
* Instantiates a new chart htmlizer.
*/
private ChartHtmlizer()
{
}
/**
* Htmlize category distribution chart.
*
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeCategoryDistributionChart() throws StatoolInfosException
{
String result;
BarChart chart;
chart = new BarChart("Distribution des catégories les plus proposées");
chart.addDataset("Catégories");
Federation federation = HtmlizerContext.instance().getFederation();
Categories categories = HtmlizerContext.instance().getCategories();
CategoryStats stats = StatAgent.statAllCategories(federation, categories);
stats.sortByServiceCount().reverse();
for (CategoryStat stat : stats)
{
if (stat.getServiceCount() > 0)
{
chart.add(stat.getCategory().getName(), stat.getServiceCount(), ChartColor.PURPLE);
}
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize catergory distribution pie chart.
*
* @param services
* the services
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeCatergoryDistributionPieChart(final Services services) throws StatoolInfosException
{
String result;
Federation federation = HtmlizerContext.instance().getFederation();
Categories categories = HtmlizerContext.instance().getCategories();
CategoryStats stats = StatAgent.statAllCategories(federation, categories);
stats.sortByServiceCount().reverse();
ChartColors colors = ChartColor.valueList();
colors.remove(ChartColor.BLUE);
PieChart pie = new PieChart("Répartition des services par catégorie");
int index = 0;
while ((index < stats.size() && (index < 10)))
{
ChartColor color = colors.get(index);
CategoryStat stat = stats.get(index);
pie.add(StringUtils.abbreviate(stat.getCategory().getName(), 30), stat.getServiceCount(), color);
index += 1;
}
int others = 0;
while (index < stats.size())
{
CategoryStat stat = stats.get(index);
others += stat.getServiceCount();
index += 1;
}
pie.add("Autres catégories", others, ChartColor.BLUE);
pie.setLegendPosition(Position.RIGHT);
result = DoughnutChartView.build(pie);
//
return result;
}
/**
* Htmlize host name pie chart.
*
* @param services
* the services
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeHostNamePieChart(final Services services) throws StatoolInfosException
{
String result;
ChartColors colors = ChartColor.valueList();
colors.remove(ChartColor.BLUE);
StringCounters counters = new StringCounters();
long unknowns = 0;
for (Service service : services)
{
if (service.getHostProviderType() == null)
{
unknowns += 1;
}
else
{
switch (service.getHostProviderType())
{
case HOME:
counters.inc("Auto-hébergé");
break;
case HOSTEDBAY:
case HOSTEDSERVER:
case OUTSOURCED:
counters.inc(service.getHostName());
break;
case UNKNOWN:
unknowns += 1;
default:
}
}
}
StringCounterList list = counters.toList().sortByCounter().reverse();
PieChart pie = new PieChart("Hébergeurs des services");
pie.setLegendPosition(Position.RIGHT);
int index = 0;
while ((index < list.size() && (index < 9)))
{
ChartColor color = colors.get(index);
StringCounter counter = list.get(index);
pie.add(counter.getString(), counter.getCounter(), color);
index += 1;
}
int others = 0;
while (index < list.size())
{
StringCounter counter = list.get(index);
others += counter.getCounter();
index += 1;
}
pie.add("Autres", others, ChartColor.GREY);
pie.add("Inconnus", unknowns, ChartColor.BLUE);
result = DoughnutChartView.build(pie);
//
return result;
}
/**
* 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 metrics chart.
*
* @param title
* the title
* @param start
* the start
* @param end
* the end
* @param colors
* the colors
* @param datasets
* the datasets
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final String title, final Year start, final Year end, final ChartColor[] colors, final YearValues... datasets) throws StatoolInfosException
{
String result;
Year startTarget;
if (start == null)
{
startTarget = null;
for (YearValues dataset : datasets)
{
Year current = dataset.getOldestTimestamp();
if (current != null)
{
if ((startTarget == null) || (current.isBefore(startTarget)))
{
startTarget = current;
}
}
}
}
else
{
startTarget = start;
}
Year endTarget;
if (end == null)
{
endTarget = Year.now();
}
else
{
endTarget = end;
}
BarChart chart = new BarChart(title);
chart.setStacked(true);
for (YearValues dataset : datasets)
{
chart.addDataset(dataset.getLabel());
}
if (startTarget != null)
{
for (Year timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusYears(1))
{
String timestampLabel = timestamp.format(DateTimeFormatter.ofPattern("yyyy", Locale.FRANCE));
chart.getLabels().add(timestampLabel);
for (int index = 0; index < datasets.length; index++)
{
double value = datasets[index].getValue(timestamp);
chart.add(index, value, colors[index % colors.length]);
}
}
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize metrics chart.
*
* @param title
* the title
* @param start
* the start
* @param end
* the end
* @param colors
* the colors
* @param datasets
* the datasets
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final String title, final YearMonth start, final YearMonth end, final ChartColor[] colors, final MonthValues... datasets) throws StatoolInfosException
{
String result;
YearMonth startTarget;
if (start == null)
{
startTarget = null;
for (MonthValues dataset : datasets)
{
YearMonth current = dataset.getOldestTimestamp();
if (current != null)
{
if ((startTarget == null) || (current.isBefore(startTarget)))
{
startTarget = current;
}
}
}
}
else
{
startTarget = start;
}
YearMonth endTarget;
if (end == null)
{
endTarget = YearMonth.now();
}
else
{
endTarget = end;
}
BarChart chart = new BarChart(title);
chart.setStacked(true);
for (MonthValues dataset : datasets)
{
chart.addDataset(dataset.getLabel());
}
if (startTarget != null)
{
for (YearMonth timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusMonths(1))
{
String timestampLabel = timestamp.format(DateTimeFormatter.ofPattern("yyyy-MMM", Locale.FRANCE));
chart.getLabels().add(timestampLabel);
for (int index = 0; index < datasets.length; index++)
{
double value = datasets[index].getValue(timestamp);
chart.add(index, value, colors[index % colors.length]);
}
}
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize metrics chart.
*
* @param title
* the title
* @param start
* the start
* @param end
* the end
* @param colors
* the colors
* @param datasets
* the datasets
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final String title, final YearWeek start, final YearWeek end, final ChartColor[] colors, final WeekValues... datasets) throws StatoolInfosException
{
String result;
YearWeek startTarget;
if (start == null)
{
startTarget = null;
for (WeekValues dataset : datasets)
{
YearWeek current = dataset.getOldestTimestamp();
if (current != null)
{
if ((startTarget == null) || (current.isBefore(startTarget)))
{
startTarget = current;
}
}
}
}
else
{
startTarget = start;
}
YearWeek endTarget;
if (end == null)
{
endTarget = YearWeek.now();
}
else
{
endTarget = end;
}
BarChart chart = new BarChart(title);
chart.setStacked(true);
for (WeekValues dataset : datasets)
{
chart.addDataset(dataset.getLabel());
}
if (startTarget != null)
{
for (YearWeek timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusWeeks(1))
{
LocalDate date = timestamp.atDay(DayOfWeek.MONDAY).plusDays(6);
String timestampLabel = date.format(DateTimeFormatter.ofPattern("yyyy-MMM-dd", Locale.FRANCE));
chart.getLabels().add(timestampLabel);
for (int index = 0; index < datasets.length; index++)
{
double value = datasets[index].getValue(timestamp);
chart.add(index, value, colors[index % colors.length]);
}
}
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize metrics chart.
*
* @param start
* the start
* @param end
* the end
* @param dataset
* the dataset
* @param color
* the color
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final Year start, final Year end, final YearValues dataset, final ChartColor color) throws StatoolInfosException
{
String result;
Year startTarget;
if (start == null)
{
startTarget = dataset.getOldestTimestamp();
}
else
{
startTarget = start;
}
Year endTarget;
if (end == null)
{
endTarget = Year.now();
}
else
{
endTarget = end;
}
ChartColor targetColor;
if (color == null)
{
targetColor = ChartColor.BLUE;
}
else
{
targetColor = color;
}
BarChart chart = new BarChart(dataset.getLabel());
// chart.setStacked(true);
chart.setAnimated(false);
chart.addDataset(dataset.getLabel());
if (startTarget != null)
{
for (Year timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusYears(1))
{
String timestampLabel = timestamp.format(DateTimeFormatter.ofPattern("yyyy", Locale.FRANCE));
chart.getLabels().add(timestampLabel);
double value = dataset.getValue(timestamp);
chart.add(0, value, targetColor);
}
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize metrics chart.
*
* @param start
* the start
* @param end
* the end
* @param dataset
* the dataset
* @param color
* the color
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final YearMonth start, final YearMonth end, final MonthValues dataset, final ChartColor color) throws StatoolInfosException
{
String result;
YearMonth startTarget;
if (start == null)
{
startTarget = dataset.getOldestTimestamp();
}
else
{
startTarget = start;
}
YearMonth endTarget;
if (end == null)
{
endTarget = YearMonth.now();
}
else
{
endTarget = end;
}
ChartColor targetColor;
if (color == null)
{
targetColor = ChartColor.BLUE;
}
else
{
targetColor = color;
}
BarChart chart = new BarChart(dataset.getLabel());
// chart.setStacked(true);
chart.setAnimated(false);
chart.addDataset(dataset.getLabel());
if (startTarget != null)
{
for (YearMonth timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusMonths(1))
{
String timestampLabel = timestamp.format(DateTimeFormatter.ofPattern("yyyy-MMM", Locale.FRANCE));
chart.getLabels().add(timestampLabel);
double value = dataset.getValue(timestamp);
chart.add(0, value, targetColor);
}
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize metrics chart.
*
* @param start
* the start
* @param end
* the end
* @param dataset
* the dataset
* @param color
* the color
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeMetricsChart(final YearWeek start, final YearWeek end, final WeekValues dataset, final ChartColor color) throws StatoolInfosException
{
String result;
YearWeek startTarget;
if (start == null)
{
startTarget = dataset.getOldestTimestamp();
}
else
{
startTarget = start;
}
YearWeek endTarget;
if (end == null)
{
endTarget = YearWeek.now();
}
else
{
endTarget = end;
}
ChartColor targetColor;
if (color == null)
{
targetColor = ChartColor.BLUE;
}
else
{
targetColor = color;
}
BarChart chart = new BarChart(dataset.getLabel());
// chart.setStacked(true);
chart.setAnimated(false);
chart.addDataset(dataset.getLabel());
if (startTarget != null)
{
for (YearWeek timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusWeeks(1))
{
LocalDate date = timestamp.atDay(DayOfWeek.MONDAY).plusDays(6);
String timestampLabel = date.format(DateTimeFormatter.ofPattern("yyyy-MMM-dd", Locale.FRANCE));
chart.getLabels().add(timestampLabel);
double value = dataset.getValue(timestamp);
chart.add(0, value, targetColor);
}
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize organization count chart.
*
* @param federation
* the federation
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeOrganizationCountChart(final Federation federation) throws StatoolInfosException
{
String result;
BarChart chart;
chart = new BarChart("Nombre de membres");
chart.addDataset("Membres");
PathPropertyList values = federation.getByYearPrefix("metrics.members.count").sortByPath();
for (PathProperty property : values)
{
chart.add(property.getLeaf(), Double.parseDouble(property.getValue()), ChartColor.GREEN);
}
result = BarChartView.build(chart);
//
return result;
}
/**
* @param organizations
* @return
* @throws StatoolInfosException
*/
public static String htmlizeOrganizationCountryChart(final Organizations organizations) throws StatoolInfosException
{
String result;
CountryStats stats = StatAgent.statsCountry(organizations);
PieChart pie = new PieChart("Pays des membres");
StringList countries = new StringList(stats.keySet()).sort();
countries.remove(CountryStats.UNKNOWN_LABEL);
ChartColors colors = new ChartColors();
colors.add(ChartColor.GREEN);
colors.add(ChartColor.ORANGE);
colors.add(ChartColor.RED);
colors.add(ChartColor.PURPLE);
colors.add(ChartColor.TURQUOISE);
colors.add(ChartColor.YELLOW);
int index = 0;
for (String country : countries)
{
pie.add(country, stats.get(country), colors.get(index));
index += 1;
}
pie.add("Inconnu", stats.getUnknown(), ChartColor.BLUE);
pie.setLegendPosition(Position.RIGHT);
result = PieChartView.build(pie);
//
return result;
}
/**
* Htmlize organization in out chart.
*
* @param federation
* the federation
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeOrganizationInOutChart(final Federation federation) throws StatoolInfosException
{
String result;
BarChart chart = new BarChart("Entrées/Sorties");
// chart.setStacked(true);
chart.addDataset("Entrées");
PathPropertyList values = federation.getByYearPrefix("metrics.members.in").sortByPath();
for (PathProperty property : values)
{
chart.getLabels().add(property.getLeaf());
chart.add(0, Double.parseDouble(property.getValue()), ChartColor.GREEN);
}
chart.addDataset("Sorties");
values = federation.getByYearPrefix("metrics.members.out").sortByPath();
for (PathProperty property : values)
{
chart.add(1, Double.parseDouble(property.getValue()), ChartColor.RED);
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize organization turnout chart.
*
* @param organization
* the organization
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeOrganizationTurnoutChart(final Organization organization) throws StatoolInfosException
{
String result;
Organizations organizations = new Organizations();
organizations.add(organization);
result = htmlizeOrganizationTurnoutChart(organizations);
//
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("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 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.
*
* @param stats
* the stats
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeRegistrationBarChart(final RegistrationStats stats) throws StatoolInfosException
{
String result;
BarChart bar = new BarChart("Types d'inscription");
bar.addDataset("Nombre");
bar.add("Sans", stats.getNoneCount(), ChartColor.GREEN);
bar.add("Libre", stats.getFreeCount(), ChartColor.YELLOW);
bar.add("Membre", stats.getMemberCount(), ChartColor.ORANGE);
bar.add("Client", stats.getClientCount(), ChartColor.RED);
bar.add("Inconnu", stats.getUnknownCount(), ChartColor.BLUE);
result = BarChartView.build(bar);
//
return result;
}
/**
* Htmlize registration client pie chart.
*
* @param stats
* the stats
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeRegistrationClientPieChart(final RegistrationStats stats) throws StatoolInfosException
{
String result;
PieChart pie = new PieChart("Client");
pie.setLegendVisible(false);
pie.add("Sans", stats.getClientCount(), ChartColor.RED);
pie.add("Client", stats.getCount() - stats.getClientCount(), ChartColor.BLUE);
result = DoughnutChartView.build(pie);
//
return result;
}
/**
* Htmlize registration free pie chart.
*
* @param stats
* the stats
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeRegistrationFreePieChart(final RegistrationStats stats) throws StatoolInfosException
{
String result;
PieChart pie = new PieChart("Libre");
pie.setLegendVisible(false);
pie.add("Sans", stats.getFreeCount(), ChartColor.YELLOW);
pie.add("Libre", stats.getCount() - stats.getFreeCount(), ChartColor.BLUE);
result = DoughnutChartView.build(pie);
//
return result;
}
/**
* Htmlize registration member pie chart.
*
* @param stats
* the stats
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeRegistrationMemberPieChart(final RegistrationStats stats) throws StatoolInfosException
{
String result;
PieChart pie = new PieChart("Membre");
pie.setLegendVisible(false);
pie.add("Sans", stats.getMemberCount(), ChartColor.ORANGE);
pie.add("Membre", stats.getCount() - stats.getMemberCount(), ChartColor.BLUE);
result = DoughnutChartView.build(pie);
//
return result;
}
/**
* Htmlize registration none pie chart.
*
* @param stats
* the stats
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeRegistrationNonePieChart(final RegistrationStats stats) throws StatoolInfosException
{
String result;
PieChart pie = new PieChart("Sans");
pie.setLegendVisible(false);
pie.add("Sans", stats.getNoneCount(), ChartColor.GREEN);
pie.add("Autre", stats.getCount() - stats.getNoneCount(), ChartColor.BLUE);
result = DoughnutChartView.build(pie);
//
return result;
}
/**
* Htmlize service count month chart.
*
* @param federation
* the federation
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceCountMonthChart(final Federation federation) throws StatoolInfosException
{
String result;
result = htmlizeServiceCountMonthChart(federation.getServicesAll(),
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.getFederation().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 month chart.
*
* @param services
* the services
* @param first
* the first
* @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 de services (mois)");
chart.addDataset("Services");
YearMonth now = YearMonth.now();
YearMonth current = first;
while (current.compareTo(now) <= 0)
{
long count = 0;
for (Service service : services)
{
LocalDate startDate = StatoolInfosUtils.parseDate(service.getStartDate());
LocalDate endDate = StatoolInfosUtils.parseDate(service.getEndDate());
if (startDate != null)
{
YearMonth start = YearMonth.from(startDate);
YearMonth end;
if (endDate == null)
{
end = now;
}
else
{
end = YearMonth.from(endDate);
}
if ((current.compareTo(start) >= 0) && (current.compareTo(end) <= 0))
{
count += 1;
}
}
}
chart.add(current.toString(), count, ChartColor.VIOLET);
current = current.plusMonths(1);
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize service country chart.
*
* @param services
* the services
* @return the string
* @throws StatoolInfosException
* )* the statool infos exception
*/
public static String htmlizeServiceCountryChart(final Services services) throws StatoolInfosException
{
String result;
CountryStats stats = StatAgent.statsCountry(services);
PieChart pie = new PieChart("Pays des services");
StringList countries = new StringList(stats.keySet()).sort();
countries.remove(CountryStats.UNKNOWN_LABEL);
ChartColors colors = new ChartColors();
colors.add(ChartColor.GREEN);
colors.add(ChartColor.ORANGE);
colors.add(ChartColor.RED);
colors.add(ChartColor.PURPLE);
colors.add(ChartColor.TURQUOISE);
colors.add(ChartColor.YELLOW);
int index = 0;
for (String country : countries)
{
pie.add(country, stats.get(country), colors.get(index));
index += 1;
}
pie.add("Inconnu", stats.getUnknown(), ChartColor.BLUE);
pie.setLegendPosition(Position.RIGHT);
result = PieChartView.build(pie);
//
return result;
}
/**
* Htmlize service count year chart.
*
* @param federation
* the federation
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceCountYearChart(final Federation federation) throws StatoolInfosException
{
String result;
result = htmlizeServiceCountYearChart(federation.getServices(), 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.getFederation().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 Integer first) throws StatoolInfosException
{
String result;
BarChart chart;
chart = new BarChart("Nombre de services");
chart.addDataset("Services");
if (first != null)
{
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.
*
* @param services
* the services
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceDateStatusChart(final Services services) throws StatoolInfosException
{
String result;
PieChart pie = new PieChart("Services avec ou sans date");
long filled = 0;
long unfilled = 0;
for (Service service : services)
{
if (StatoolInfosUtils.parseDate(service.getStartDate()) == null)
{
unfilled += 1;
}
else
{
filled += 1;
}
}
pie.add("Avec", filled, ChartColor.VIOLET);
pie.add("Sans", unfilled, ChartColor.BLUE);
pie.setLegendPosition(Position.RIGHT);
result = PieChartView.build(pie);
//
return result;
}
/**
* Htmlize service install type chart.
*
* @param services
* the services
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeServiceInstallTypeChart(final Services services) throws StatoolInfosException
{
String result;
ServiceInstallTypeStats stats = StatAgent.statServiceInstallType(services);
PieChart pie = new PieChart("Types d'installation du service");
pie.add("Distribution", stats.getDistributionCount(), ChartColor.PURPLE);
pie.add("Fournisseur", stats.getProviderCount(), ChartColor.GREEN);
pie.add("Paquet", stats.getPackageCount(), ChartColor.YELLOW);
pie.add("Outillage", stats.getToolingCount(), ChartColor.ORANGE);
pie.add("Dépôt cloné", stats.getClonerepoCount(), ChartColor.RED);
pie.add("Archive", stats.getArchiveCount(), ChartColor.VIOLET);
pie.add("Sources", stats.getSourcesCount(), ChartColor.GREY);
pie.add("Containeur", stats.getContainerCount(), ChartColor.TURQUOISE);
pie.add("Inconnu", stats.getUnknownCount(), ChartColor.BLUE);
pie.setLegendPosition(Position.RIGHT);
result = DoughnutChartView.build(pie);
//
return result;
}
/**
* Htmlize software distribution chart.
*
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeSoftwareDistributionChart() throws StatoolInfosException
{
String result;
BarChart chart = new BarChart("Distribution des logiciels proposés par au moins deux services");
chart.addDataset("Logiciel");
Federation federation = HtmlizerContext.instance().getFederation();
Categories categories = HtmlizerContext.instance().getCategories();
SoftwareStats stats = StatAgent.statAllSoftwares(federation, categories);
stats.sortByServiceCount().reverse();
for (SoftwareStat stat : stats)
{
if (stat.getServiceCount() > 1)
{
chart.add(stat.getName(), stat.getServiceCount(), ChartColor.PURPLE);
}
}
result = BarChartView.build(chart);
//
return result;
}
/**
* Htmlize software used chart.
*
* @param services
* the services
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlizeSoftwareDistributionPieChart(final Services services) throws StatoolInfosException
{
String result;
Federation federation = HtmlizerContext.instance().getFederation();
Categories categories = HtmlizerContext.instance().getCategories();
SoftwareStats stats = StatAgent.statAllSoftwares(federation, categories);
stats.sortByServiceCount().reverse();
ChartColors colors = ChartColor.valueList();
colors.remove(ChartColor.BLUE);
PieChart pie = new PieChart("Répartition des services par logiciel");
int index = 0;
while ((index < stats.size() && (index < 10)))
{
ChartColor color = colors.get(index);
SoftwareStat stat = stats.get(index);
pie.add(stat.getName(), stat.getServiceCount(), color);
index += 1;
}
int others = 0;
while (index < stats.size())
{
SoftwareStat stat = stats.get(index);
others += stat.getServiceCount();
index += 1;
}
pie.add("Autres", others, ChartColor.BLUE);
pie.setLegendPosition(Position.RIGHT);
result = DoughnutChartView.build(pie);
//
return result;
}
}