187 lines
7.6 KiB
Java
187 lines
7.6 KiB
Java
/*
|
|
* Copyright (C) 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 java.time.YearMonth;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.threeten.extra.YearWeek;
|
|
|
|
import fr.devinsy.statoolinfos.core.Service;
|
|
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
|
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.PeriodMenu;
|
|
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.ViewMenu;
|
|
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
|
|
import fr.devinsy.statoolinfos.htmlize.charts.MonthValues;
|
|
import fr.devinsy.statoolinfos.htmlize.charts.WeekValues;
|
|
import fr.devinsy.statoolinfos.htmlize.charts.YearValues;
|
|
import fr.devinsy.xidyn.data.TagDataManager;
|
|
|
|
/**
|
|
* The Class MetricHtmlizeDataUtils.
|
|
*/
|
|
public class ServiceMetricHtmlizer
|
|
{
|
|
private static Logger logger = LoggerFactory.getLogger(ServiceMetricHtmlizer.class);
|
|
|
|
/**
|
|
* Htmlize data.
|
|
*
|
|
* @param data
|
|
* the data
|
|
* @param metricId
|
|
* the metric id
|
|
* @param service
|
|
* the service
|
|
* @param metricPath
|
|
* the metric path
|
|
* @param color
|
|
* the color
|
|
* @throws StatoolInfosException
|
|
* the statool infos exception
|
|
*/
|
|
public static void htmlize(final TagDataManager data, final String metricId, final Service service, final ViewMenu view, final PeriodMenu period, final String metricPath,
|
|
final ChartColor color) throws StatoolInfosException
|
|
{
|
|
if (view == ViewMenu.YEARS)
|
|
{
|
|
YearValues yearMetric = service.getMetricYearValues(metricPath);
|
|
|
|
if (period == PeriodMenu.FULL)
|
|
{
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, yearMetric, color));
|
|
}
|
|
}
|
|
else if (view == ViewMenu.MONTHS)
|
|
{
|
|
MonthValues monthMetric = service.getMetricMonthValues(metricPath);
|
|
|
|
if (period == PeriodMenu.FULL)
|
|
{
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, monthMetric, color));
|
|
}
|
|
else if (period == PeriodMenu.LAST)
|
|
{
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.now().minusMonths(11), YearMonth.now(), monthMetric, color));
|
|
}
|
|
else
|
|
{
|
|
int year = Integer.parseInt(period.name().substring(1));
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.of(year, 01), YearMonth.of(year, 12), monthMetric, color));
|
|
}
|
|
}
|
|
else if (view == ViewMenu.WEEKS)
|
|
{
|
|
WeekValues weekMetric = service.getMetricWeekValues(metricPath);
|
|
|
|
if (period == PeriodMenu.FULL)
|
|
{
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, weekMetric, color));
|
|
}
|
|
else if (period == PeriodMenu.LAST)
|
|
{
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.now().minusYears(1), YearWeek.now(), weekMetric, color));
|
|
}
|
|
else
|
|
{
|
|
int year = Integer.parseInt(period.name().substring(1));
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.of(year, 01), YearWeek.of(year, 53), weekMetric, color));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Htmlize data.
|
|
*
|
|
* @param data
|
|
* the data
|
|
* @param metricId
|
|
* the metric id
|
|
* @param service
|
|
* the service
|
|
* @param metricLabel
|
|
* the metric label
|
|
* @param metricPath1
|
|
* the metric path 1
|
|
* @param color1
|
|
* the color 1
|
|
* @param metricPath2
|
|
* the metric path 2
|
|
* @param color2
|
|
* the color 2
|
|
* @throws StatoolInfosException
|
|
* the statool infos exception
|
|
*/
|
|
public static void htmlizeData(final TagDataManager data, final String metricId, final Service service, final ViewMenu view, final PeriodMenu period, final String metricLabel,
|
|
final String metricPath1, final ChartColor color1, final String metricPath2, final ChartColor color2) throws StatoolInfosException
|
|
{
|
|
if (view == ViewMenu.YEARS)
|
|
{
|
|
YearValues yearMetric1 = service.getMetricYearValues(metricPath1);
|
|
YearValues yearMetric2 = service.getMetricYearValues(metricPath2);
|
|
|
|
if (period == PeriodMenu.FULL)
|
|
{
|
|
data.setContent(metricId,
|
|
ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, yearMetric1, yearMetric2));
|
|
}
|
|
}
|
|
else if (view == ViewMenu.MONTHS)
|
|
{
|
|
MonthValues monthMetric1 = service.getMetricMonthValues(metricPath1);
|
|
MonthValues monthMetric2 = service.getMetricMonthValues(metricPath2);
|
|
|
|
if (period == PeriodMenu.FULL)
|
|
{
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
|
|
}
|
|
else if (period == PeriodMenu.LAST)
|
|
{
|
|
data.setContent(metricId,
|
|
ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.now().minusMonths(11), YearMonth.now(), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
|
|
}
|
|
else
|
|
{
|
|
int year = Integer.parseInt(period.name().substring(1));
|
|
data.setContent(metricId,
|
|
ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.of(year, 01), YearMonth.of(year, 12), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
|
|
}
|
|
}
|
|
else if (view == ViewMenu.WEEKS)
|
|
{
|
|
WeekValues weekMetric1 = service.getMetricWeekValues(metricPath1);
|
|
WeekValues weekMetric2 = service.getMetricWeekValues(metricPath2);
|
|
|
|
if (period == PeriodMenu.FULL)
|
|
{
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
|
|
}
|
|
else if (period == PeriodMenu.LAST)
|
|
{
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.now().minusYears(1), YearWeek.now(), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
|
|
}
|
|
else
|
|
{
|
|
int year = Integer.parseInt(period.name().substring(1));
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.of(year, 01), YearWeek.of(year, 53), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
|
|
}
|
|
}
|
|
}
|
|
}
|