190 lines
7.8 KiB
Java
190 lines
7.8 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.Organization;
|
|
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
|
import fr.devinsy.statoolinfos.htmlize.OrganizationMetricMenuView.PeriodMenu;
|
|
import fr.devinsy.statoolinfos.htmlize.OrganizationMetricMenuView.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 OrganizationMetricHtmlizer.
|
|
*/
|
|
public class OrganizationMetricHtmlizer
|
|
{
|
|
private static Logger logger = LoggerFactory.getLogger(OrganizationMetricHtmlizer.class);
|
|
|
|
/**
|
|
* Htmlize data.
|
|
*
|
|
* @param data
|
|
* the data
|
|
* @param metricId
|
|
* the metric id
|
|
* @param organization
|
|
* the organization
|
|
* @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 Organization organization, final ViewMenu view, final PeriodMenu period, final String metricPath,
|
|
final ChartColor color) throws StatoolInfosException
|
|
{
|
|
if (view == ViewMenu.YEARS)
|
|
{
|
|
YearValues yearMetric = organization.getMetricYearValuesAll(metricPath);
|
|
if (period == PeriodMenu.FULL)
|
|
{
|
|
data.setContent(metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, yearMetric, color));
|
|
}
|
|
}
|
|
else if (view == ViewMenu.MONTHS)
|
|
{
|
|
MonthValues monthMetric = organization.getMetricMonthValuesAll(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 = organization.getMetricWeekValuesAll(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 organization
|
|
* the organization
|
|
* @param view
|
|
* the view
|
|
* @param period
|
|
* the period
|
|
* @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 htmlize(final TagDataManager data, final String metricId, final Organization organization, 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 = organization.getMetricYearValuesAll(metricPath1);
|
|
YearValues yearMetric2 = organization.getMetricYearValuesAll(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 = organization.getMetricMonthValuesAll(metricPath1);
|
|
MonthValues monthMetric2 = organization.getMetricMonthValuesAll(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 = organization.getMetricWeekValuesAll(metricPath1);
|
|
WeekValues weekMetric2 = organization.getMetricWeekValuesAll(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));
|
|
}
|
|
}
|
|
}
|
|
}
|