diff --git a/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java
index 70a0711..5d8e8f2 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java
+++ b/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java
@@ -18,7 +18,9 @@
*/
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;
@@ -26,6 +28,7 @@ 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;
@@ -45,6 +48,8 @@ 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;
@@ -297,6 +302,101 @@ public class ChartHtmlizer
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 ((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;
@@ -358,6 +458,156 @@ public class ChartHtmlizer
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 ((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).plusWeeks(1);
+ 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.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.
*
@@ -429,6 +679,78 @@ public class ChartHtmlizer
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.addDataset(dataset.getLabel());
+
+ if (startTarget != null)
+ {
+ for (YearWeek timestamp = startTarget; !timestamp.isAfter(endTarget); timestamp = timestamp.plusWeeks(1))
+ {
+ LocalDate date = timestamp.atDay(DayOfWeek.MONDAY).plusWeeks(1);
+ 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.
*
diff --git a/src/fr/devinsy/statoolinfos/htmlize/MetricHtmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/MetricHtmlizer.java
new file mode 100644
index 0000000..4d385c1
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/htmlize/MetricHtmlizer.java
@@ -0,0 +1,219 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * 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 .
+ */
+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.MenuItem;
+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.XidynException;
+import fr.devinsy.xidyn.data.TagDataManager;
+import fr.devinsy.xidyn.presenters.PresenterUtils;
+
+/**
+ * The Class MetricHtmlizeDataUtils.
+ */
+public class MetricHtmlizer
+{
+ private static Logger logger = LoggerFactory.getLogger(MetricHtmlizer.class);
+
+ private static final int CHART_YEARS_FULL = 0;
+ private static final int CHART_MONTHS_FULL = 1;
+ private static final int CHART_MONTHS_LAST = 2;
+ private static final int CHART_MONTHS_2020 = 3;
+ private static final int CHART_MONTHS_2021 = 4;
+ private static final int CHART_WEEKS_FULL = 5;
+ private static final int CHART_WEEKS_LAST = 6;
+ private static final int CHART_WEEKS_2020 = 7;
+ private static final int CHART_WEEKS_2021 = 8;
+ private static final int CHART_DAYS_LAST = 9;
+
+ /**
+ * Htmlize.
+ *
+ * @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 generic metric page {}…", service.get("service.name"));
+
+ TagDataManager data = new TagDataManager();
+
+ //
+ data.setContent("headerView", ServiceHeaderView.htmlize(service));
+ data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.WEB));
+
+ htmlizeData(data, "http.hits", service, "metrics.http.hits", ChartColor.BLUE);
+
+ htmlizeData(data, "http.hits-ipv4ipv6", service, "http.hits (ipv4 + ipv6)", "metrics.http.hits.ipv4", ChartColor.YELLOW, "metrics.http.hits.ipv6", ChartColor.GREEN);
+ htmlizeData(data, "http.hits.ipv4", service, "metrics.http.hits.ipv4", ChartColor.YELLOW);
+ htmlizeData(data, "http.hits.ipv6", service, "metrics.http.hits.ipv6", ChartColor.GREEN);
+
+ htmlizeData(data, "http.hits-visitorsbots", service, "http.hits (visitors + bots)", "metrics.http.hits.visitors", ChartColor.GREEN, "metrics.http.hits.bots", ChartColor.YELLOW);
+ htmlizeData(data, "http.hits.visitors", service, "metrics.http.hits.visitors", ChartColor.GREEN);
+ htmlizeData(data, "http.hits.bots", service, "metrics.http.hits.bots", ChartColor.YELLOW);
+
+ htmlizeData(data, "http.errors", service, "metrics.http.errors", ChartColor.RED);
+ htmlizeData(data, "http.errors.php", service, "metrics.http.errors.php", ChartColor.RED);
+
+ htmlizeData(data, "http.files", service, "metrics.http.files", ChartColor.BLUE);
+ htmlizeData(data, "http.pages", service, "metrics.http.pages", ChartColor.BLUE);
+ htmlizeData(data, "http.bytes", service, "metrics.http.bytes", ChartColor.BLUE);
+
+ htmlizeData(data, "http.ip", service, "metrics.http.ip", ChartColor.BLUE);
+
+ htmlizeData(data, "http.ip-visitorsbots", service, "http.ip (visitors + bots)", "metrics.http.ip.visitors", ChartColor.GREEN, "metrics.http.ip.bots", ChartColor.YELLOW);
+ htmlizeData(data, "http.ip.visitors", service, "metrics.http.ip.visitors", ChartColor.GREEN);
+ htmlizeData(data, "http.ip.bots", service, "metrics.http.ip.bots", ChartColor.YELLOW);
+
+ htmlizeData(data, "http.ip-ipv4ipv6", service, "http.ip (ipv4 + ipv6)", "metrics.http.ip.ipv4", ChartColor.YELLOW, "metrics.http.ip.ipv6", ChartColor.GREEN);
+ htmlizeData(data, "http.ip.ipv4", service, "metrics.http.ip.ipv4", ChartColor.YELLOW);
+ htmlizeData(data, "http.ip.ipv6", service, "metrics.http.ip.ipv6", ChartColor.GREEN);
+
+ htmlizeData(data, "http.visits", service, "metrics.http.visits", ChartColor.BLUE);
+
+ htmlizeData(data, "http.visits-visitorsbots", service, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN, "metrics.http.visits.bots", ChartColor.YELLOW);
+ htmlizeData(data, "http.visits.bots", service, "metrics.http.visits.bots", ChartColor.YELLOW);
+ htmlizeData(data, "http.visits.visitors", service, "metrics.http.visits.visitors", ChartColor.GREEN);
+
+ //
+ String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricView2.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;
+ }
+
+ /**
+ * 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 htmlizeData(final TagDataManager data, final String metricId, final Service service, final String metricPath, final ChartColor color) throws StatoolInfosException
+ {
+ YearValues yearMetric = service.getMetricYearValues(metricPath);
+ data.setContent("charts", CHART_YEARS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, yearMetric, color));
+
+ MonthValues monthMetric = service.getMetricMonthValues(metricPath);
+ data.setContent("charts", CHART_MONTHS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, monthMetric, color));
+ data.setContent("charts", CHART_MONTHS_LAST, metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.now().minusMonths(11), YearMonth.now(), monthMetric, color));
+ data.setContent("charts", CHART_MONTHS_2020, metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.of(2020, 01), YearMonth.of(2020, 12), monthMetric, color));
+ data.setContent("charts", CHART_MONTHS_2021, metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.of(2021, 01), YearMonth.of(2021, 12), monthMetric, color));
+
+ WeekValues weekMetric = service.getMetricWeekValues(metricPath);
+ data.setContent("charts", CHART_WEEKS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, weekMetric, color));
+ data.setContent("charts", CHART_WEEKS_LAST, metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.now().minusYears(1), YearWeek.now(), weekMetric, color));
+ data.setContent("charts", CHART_WEEKS_2020, metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.of(2020, 01), YearWeek.of(2020, 53), weekMetric, color));
+ data.setContent("charts", CHART_WEEKS_2021, metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.of(2021, 01), YearWeek.of(2021, 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 String metricLabel, final String metricPath1,
+ final ChartColor color1,
+ final String metricPath2,
+ final ChartColor color2) throws StatoolInfosException
+ {
+ //
+ YearValues yearMetric1 = service.getMetricYearValues(metricPath1);
+ YearValues yearMetric2 = service.getMetricYearValues(metricPath2);
+ data.setContent("charts", CHART_YEARS_FULL, metricId,
+ ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, yearMetric1, yearMetric2));
+
+ //
+ MonthValues monthMetric1 = service.getMetricMonthValues(metricPath1);
+ MonthValues monthMetric2 = service.getMetricMonthValues(metricPath2);
+ data.setContent("charts", CHART_MONTHS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
+ data.setContent("charts", CHART_MONTHS_LAST, metricId,
+ ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.now().minusMonths(11), YearMonth.now(), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
+ data.setContent("charts", CHART_MONTHS_2020, metricId,
+ ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.of(2020, 01), YearMonth.of(2020, 12), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
+ data.setContent("charts", CHART_MONTHS_2021, metricId,
+ ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.of(2021, 01), YearMonth.of(2021, 12), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2));
+
+ //
+ WeekValues weekMetric1 = service.getMetricWeekValues(metricPath1);
+ WeekValues weekMetric2 = service.getMetricWeekValues(metricPath2);
+ data.setContent("charts", CHART_WEEKS_FULL, metricId,
+ ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
+ data.setContent("charts", CHART_WEEKS_LAST, metricId,
+ ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.now().minusYears(1), YearWeek.now(), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
+ data.setContent("charts", CHART_WEEKS_2020, metricId,
+ ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.of(2020, 01), YearWeek.of(2020, 53), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
+ data.setContent("charts", CHART_WEEKS_2021, metricId,
+ ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.of(2021, 01), YearWeek.of(2021, 53), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2));
+ }
+}
diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationSummaryMetricPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationSummaryMetricPage.java
index 386f7ac..0581ad6 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationSummaryMetricPage.java
+++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationSummaryMetricPage.java
@@ -18,14 +18,12 @@
*/
package fr.devinsy.statoolinfos.htmlize;
-import java.io.File;
import java.io.IOException;
import java.time.YearMonth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.core.Organization;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.OrganizationMetricMenuView.MenuItem;
@@ -61,8 +59,6 @@ public class OrganizationSummaryMetricPage
{
logger.debug("Building organization summary page {}…");
- File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
-
TagDataManager data = new TagDataManager();
//
diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricGenericPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricGenericPage.java
index a6afe76..7c56f05 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricGenericPage.java
+++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricGenericPage.java
@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem;
+import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
@@ -59,10 +60,12 @@ public class ServiceMetricGenericPage
data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.GENERIC));
//
- int graphicIndex = 0;
+ MetricHtmlizer.htmlizeData(data, "users.count", service, "metrics.users.count", ChartColor.GREEN);
+ MetricHtmlizer.htmlizeData(data, "database.bytes", service, "metrics.database.bytes", ChartColor.GREEN);
+ MetricHtmlizer.htmlizeData(data, "files.bytes", service, "metrics.http.visits.visitors", ChartColor.GREEN);
//
- String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricView.xhtml", data).toString();
+ String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricGenericView.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml");
diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSpecificPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSpecificPage.java
index 6b27104..e3ad985 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSpecificPage.java
+++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSpecificPage.java
@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem;
+import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
@@ -59,10 +60,14 @@ public class ServiceMetricSpecificPage
data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.SPECIFIC));
//
- int graphicIndex = 0;
+ int index = 1;
+ for (String metricPath : service.getMetricSpecificPrefixes())
+ {
+ MetricHtmlizer.htmlizeData(data, "foo" + index++, service, metricPath, ChartColor.BLUE);
+ }
//
- String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricView.xhtml", data).toString();
+ String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricSpecificView.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml");
diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSummaryPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSummaryPage.java
index f876487..920a453 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSummaryPage.java
+++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricSummaryPage.java
@@ -18,8 +18,6 @@
*/
package fr.devinsy.statoolinfos.htmlize;
-import java.time.YearMonth;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,7 +25,6 @@ import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
-import fr.devinsy.statoolinfos.htmlize.charts.MonthValues;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
@@ -39,8 +36,19 @@ public class ServiceMetricSummaryPage
{
private static Logger logger = LoggerFactory.getLogger(ServiceMetricSummaryPage.class);
+ private static final int CHART_YEARS_FULL = 0;
+ private static final int CHART_MONTHS_FULL = 1;
+ private static final int CHART_MONTHS_LAST = 2;
+ private static final int CHART_MONTHS_2020 = 3;
+ private static final int CHART_MONTHS_2021 = 4;
+ private static final int CHART_WEEKS_FULL = 5;
+ private static final int CHART_WEEKS_LAST = 6;
+ private static final int CHART_WEEKS_2020 = 7;
+ private static final int CHART_WEEKS_2021 = 8;
+ private static final int CHART_DAYS_LAST = 9;
+
/**
- * Builds the.
+ * Htmlize.
*
* @param service
* the service
@@ -54,7 +62,7 @@ public class ServiceMetricSummaryPage
try
{
- logger.debug("Building service summary view {}…", service.get("service.name"));
+ logger.debug("Building service generic metric page {}…", service.get("service.name"));
TagDataManager data = new TagDataManager();
@@ -62,31 +70,12 @@ public class ServiceMetricSummaryPage
data.setContent("headerView", ServiceHeaderView.htmlize(service));
data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.SUMMARY));
- //
- String tagIds[] = { "fullChart", "lastChart", "2020Chart", "2021Chart" };
- YearMonth starts[] = { null, YearMonth.now().minusMonths(11), YearMonth.of(2020, 01), YearMonth.of(2021, 01) };
- YearMonth ends[] = { null, YearMonth.now(), YearMonth.of(2020, 12), YearMonth.of(2021, 12) };
-
- for (int index = 0; index < tagIds.length; index++)
- {
- String tagId = tagIds[index];
- YearMonth start = starts[index];
- YearMonth end = ends[index];
-
- int graphicIndex = 0;
-
- MonthValues metric = service.getMetricMonthValues("metrics.http.hits.visitors");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN));
-
- metric = service.getMetricMonthValues("metrics.http.ip.visitors");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN));
-
- metric = service.getMetricMonthValues("metrics.http.visits.visitors");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN));
- }
+ MetricHtmlizer.htmlizeData(data, "http.hits.visitors", service, "metrics.http.hits.visitors", ChartColor.GREEN);
+ MetricHtmlizer.htmlizeData(data, "http.ip.visitors", service, "metrics.http.ip.visitors", ChartColor.GREEN);
+ MetricHtmlizer.htmlizeData(data, "http.visits.visitors", service, "metrics.http.visits.visitors", ChartColor.GREEN);
//
- String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricView.xhtml", data).toString();
+ String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricSummaryView.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml");
@@ -95,7 +84,7 @@ public class ServiceMetricSummaryPage
}
catch (XidynException exception)
{
- throw new StatoolInfosException("Error building service summary metrics view: " + exception.getMessage(), exception);
+ throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception);
}
//
diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricWebPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricWebPage.java
index b63419a..3cf98a0 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricWebPage.java
+++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricWebPage.java
@@ -18,8 +18,6 @@
*/
package fr.devinsy.statoolinfos.htmlize;
-import java.time.YearMonth;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,7 +25,6 @@ import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem;
import fr.devinsy.statoolinfos.htmlize.charts.ChartColor;
-import fr.devinsy.statoolinfos.htmlize.charts.MonthValues;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
@@ -40,7 +37,7 @@ public class ServiceMetricWebPage
private static Logger logger = LoggerFactory.getLogger(ServiceMetricWebPage.class);
/**
- * Builds the.
+ * Htmlize.
*
* @param service
* the service
@@ -62,83 +59,44 @@ public class ServiceMetricWebPage
data.setContent("headerView", ServiceHeaderView.htmlize(service));
data.setContent("metricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.WEB));
- // service.getPrefixes();
+ MetricHtmlizer.htmlizeData(data, "http.hits", service, "metrics.http.hits", ChartColor.BLUE);
- String tagIds[] = { "fullChart", "lastChart", "2020Chart", "2021Chart" };
- YearMonth starts[] = { null, YearMonth.now().minusMonths(11), YearMonth.of(2020, 01), YearMonth.of(2021, 01) };
- YearMonth ends[] = { null, YearMonth.now(), YearMonth.of(2020, 12), YearMonth.of(2021, 12) };
+ MetricHtmlizer.htmlizeData(data, "http.hits-ipv4ipv6", service, "http.hits (ipv4 + ipv6)", "metrics.http.hits.ipv4", ChartColor.YELLOW, "metrics.http.hits.ipv6", ChartColor.GREEN);
+ MetricHtmlizer.htmlizeData(data, "http.hits.ipv4", service, "metrics.http.hits.ipv4", ChartColor.YELLOW);
+ MetricHtmlizer.htmlizeData(data, "http.hits.ipv6", service, "metrics.http.hits.ipv6", ChartColor.GREEN);
- for (int index = 0; index < tagIds.length; index++)
- {
- String tagId = tagIds[index];
- YearMonth start = starts[index];
- YearMonth end = ends[index];
+ MetricHtmlizer.htmlizeData(data, "http.hits-visitorsbots", service, "http.hits (visitors + bots)", "metrics.http.hits.visitors", ChartColor.GREEN, "metrics.http.hits.bots",
+ ChartColor.YELLOW);
+ MetricHtmlizer.htmlizeData(data, "http.hits.visitors", service, "metrics.http.hits.visitors", ChartColor.GREEN);
+ MetricHtmlizer.htmlizeData(data, "http.hits.bots", service, "metrics.http.hits.bots", ChartColor.YELLOW);
- int graphicIndex = 0;
+ MetricHtmlizer.htmlizeData(data, "http.errors", service, "metrics.http.errors", ChartColor.RED);
+ MetricHtmlizer.htmlizeData(data, "http.errors.php", service, "metrics.http.errors.php", ChartColor.RED);
- MonthValues metric = service.getMetricMonthValues("metrics.http.hits");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE));
+ MetricHtmlizer.htmlizeData(data, "http.files", service, "metrics.http.files", ChartColor.BLUE);
+ MetricHtmlizer.htmlizeData(data, "http.pages", service, "metrics.http.pages", ChartColor.BLUE);
+ MetricHtmlizer.htmlizeData(data, "http.bytes", service, "metrics.http.bytes", ChartColor.BLUE);
- MonthValues metric4 = service.getMetricMonthValues("metrics.http.hits.ipv4");
- MonthValues metric6 = service.getMetricMonthValues("metrics.http.hits.ipv6");
- data.setContent(tagId, graphicIndex++,
- ChartHtmlizer.htmlizeMetricsChart("http.hits (ipv4 + ipv6)", start, end, new ChartColor[] { ChartColor.YELLOW, ChartColor.GREEN }, metric4, metric6));
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW));
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN));
+ MetricHtmlizer.htmlizeData(data, "http.ip", service, "metrics.http.ip", ChartColor.BLUE);
- metric4 = service.getMetricMonthValues("metrics.http.hits.bots");
- metric6 = service.getMetricMonthValues("metrics.http.hits.visitors");
- data.setContent(tagId, graphicIndex++,
- ChartHtmlizer.htmlizeMetricsChart("http.hits (visitors + bots)", start, end, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4));
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN));
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW));
+ MetricHtmlizer.htmlizeData(data, "http.ip-visitorsbots", service, "http.ip (visitors + bots)", "metrics.http.ip.visitors", ChartColor.GREEN, "metrics.http.ip.bots",
+ ChartColor.YELLOW);
+ MetricHtmlizer.htmlizeData(data, "http.ip.visitors", service, "metrics.http.ip.visitors", ChartColor.GREEN);
+ MetricHtmlizer.htmlizeData(data, "http.ip.bots", service, "metrics.http.ip.bots", ChartColor.YELLOW);
- metric = service.getMetricMonthValues("metrics.http.errors");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.RED));
+ MetricHtmlizer.htmlizeData(data, "http.ip-ipv4ipv6", service, "http.ip (ipv4 + ipv6)", "metrics.http.ip.ipv4", ChartColor.YELLOW, "metrics.http.ip.ipv6", ChartColor.GREEN);
+ MetricHtmlizer.htmlizeData(data, "http.ip.ipv4", service, "metrics.http.ip.ipv4", ChartColor.YELLOW);
+ MetricHtmlizer.htmlizeData(data, "http.ip.ipv6", service, "metrics.http.ip.ipv6", ChartColor.GREEN);
- metric = service.getMetricMonthValues("metrics.http.errors.php");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.RED));
+ MetricHtmlizer.htmlizeData(data, "http.visits", service, "metrics.http.visits", ChartColor.BLUE);
- metric = service.getMetricMonthValues("metrics.http.files");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE));
-
- metric = service.getMetricMonthValues("metrics.http.pages");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE));
-
- metric = service.getMetricMonthValues("metrics.http.bytes");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE));
-
- metric = service.getMetricMonthValues("metrics.http.ip");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE));
-
- metric4 = service.getMetricMonthValues("metrics.http.ip.bots");
- metric6 = service.getMetricMonthValues("metrics.http.ip.visitors");
- data.setContent(tagId, graphicIndex++,
- ChartHtmlizer.htmlizeMetricsChart("http.ip (visitors + bots)", start, end, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4));
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN));
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW));
-
- metric4 = service.getMetricMonthValues("metrics.http.ip.ipv4");
- metric6 = service.getMetricMonthValues("metrics.http.ip.ipv6");
- data.setContent(tagId, graphicIndex++,
- ChartHtmlizer.htmlizeMetricsChart("http.ip (ipv4 + ipv6)", start, end, new ChartColor[] { ChartColor.YELLOW, ChartColor.GREEN }, metric4, metric6));
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW));
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN));
-
- metric = service.getMetricMonthValues("metrics.http.visits");
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE));
-
- metric4 = service.getMetricMonthValues("metrics.http.visits.bots");
- metric6 = service.getMetricMonthValues("metrics.http.visits.visitors");
- data.setContent(tagId, graphicIndex++,
- ChartHtmlizer.htmlizeMetricsChart("http.visits (visitors + bots)", start, end, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4));
-
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN));
- data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW));
- }
+ MetricHtmlizer.htmlizeData(data, "http.visits-visitorsbots", service, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN, "metrics.http.visits.bots",
+ ChartColor.YELLOW);
+ MetricHtmlizer.htmlizeData(data, "http.visits.bots", service, "metrics.http.visits.bots", ChartColor.YELLOW);
+ MetricHtmlizer.htmlizeData(data, "http.visits.visitors", service, "metrics.http.visits.visitors", ChartColor.GREEN);
//
- String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricView.xhtml", data).toString();
+ String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricWebView.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml");
diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/WeekValues.java b/src/fr/devinsy/statoolinfos/htmlize/charts/WeekValues.java
new file mode 100644
index 0000000..3335072
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/htmlize/charts/WeekValues.java
@@ -0,0 +1,308 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * 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 .
+ */
+package fr.devinsy.statoolinfos.htmlize.charts;
+
+import java.util.HashMap;
+
+import org.threeten.extra.YearWeek;
+
+import fr.devinsy.strings.StringList;
+
+/**
+ * The Class WeekValues.
+ */
+public class WeekValues extends HashMap
+{
+ private static final long serialVersionUID = -211990850389225574L;
+ private String label;
+ private String description;
+
+ /**
+ * Instantiates a new week values.
+ */
+ public WeekValues()
+ {
+ this(null, null);
+ }
+
+ /**
+ * Instantiates a new week values.
+ *
+ * @param label
+ * the label
+ * @param description
+ * the description
+ */
+ public WeekValues(final String label, final String description)
+ {
+ super();
+ this.label = label;
+ this.description = description;
+ }
+
+ /**
+ * Adds the.
+ *
+ * @param timestamp
+ * the timestamp
+ * @param value
+ * the value
+ */
+ public void add(final YearWeek timestamp, final double value)
+ {
+ put(timestamp, getValue(timestamp) + value);
+ }
+
+ /**
+ * Adds the all.
+ *
+ * @param source
+ * the source
+ */
+ public void addAll(final WeekValues source)
+ {
+ if (source != null)
+ {
+ for (YearWeek timestamp : source.keySet())
+ {
+ add(timestamp, source.getValue(timestamp));
+ }
+ }
+ }
+
+ /**
+ * Dec.
+ *
+ * @param timestamp
+ * the timestamp
+ */
+ public void dec(final YearWeek timestamp)
+ {
+ put(timestamp, getValue(timestamp) - 1);
+ }
+
+ /**
+ * Extract.
+ *
+ * @param start
+ * the start
+ * @param end
+ * the end
+ * @return the month value map
+ */
+ public WeekValues extract(final YearWeek start, final YearWeek end)
+ {
+ WeekValues result;
+
+ YearWeek startTarget = normalizeStart(start);
+ YearWeek endTarget = normalizeEnd(end);
+
+ result = new WeekValues();
+ for (YearWeek timestamp : this.keySet())
+ {
+ if ((!timestamp.isBefore(startTarget)) &&
+ (!timestamp.isAfter(endTarget)))
+ {
+ result.put(timestamp, get(timestamp));
+ }
+ }
+
+ //
+ return result;
+ }
+
+ public String getDescription()
+ {
+ return this.description;
+ }
+
+ public String getLabel()
+ {
+ return this.label;
+ }
+
+ /**
+ * Gets the normalized timestamps.
+ *
+ * @param start
+ * the start
+ * @param end
+ * the end
+ * @return the normalized timestamps
+ */
+ public StringList getNormalizedTimestamps(final YearWeek start, final YearWeek end)
+ {
+ StringList result;
+
+ YearWeek startTarget = normalizeStart(start);
+ YearWeek endTarget = normalizeEnd(end);
+
+ result = new StringList();
+ for (YearWeek timestamp = startTarget; endTarget.isAfter(timestamp); timestamp = timestamp.plusWeeks(1))
+ {
+ result.append(timestamp);
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the oldest timestamp.
+ *
+ * @return the oldest timestamp
+ */
+ public YearWeek getOldestTimestamp()
+ {
+ YearWeek result;
+
+ result = null;
+
+ for (YearWeek timestamp : this.keySet())
+ {
+ if ((result == null) || (timestamp.isBefore(result)))
+ {
+ result = timestamp;
+ }
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the value.
+ *
+ * @param timestamp
+ * the timestamp
+ * @return the value
+ */
+ public double getValue(final YearWeek timestamp)
+ {
+ double result;
+
+ Double value = get(timestamp);
+ if (value == null)
+ {
+ result = 0.0;
+ }
+ else
+ {
+ result = value;
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Inc.
+ *
+ * @param timestamp
+ * the timestamp
+ */
+ public void inc(final YearWeek timestamp)
+ {
+ put(timestamp, getValue(timestamp) + 1);
+ }
+
+ /**
+ * Normalize end.
+ *
+ * @param end
+ * the end
+ * @return the year month
+ */
+ public YearWeek normalizeEnd(final YearWeek end)
+ {
+ YearWeek result;
+
+ if (end == null)
+ {
+ result = YearWeek.now();
+ }
+ else
+ {
+ result = end;
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Normalize start.
+ *
+ * @param start
+ * the start
+ * @return the year month
+ */
+ public YearWeek normalizeStart(final YearWeek start)
+ {
+ YearWeek result;
+
+ if (start == null)
+ {
+ result = getOldestTimestamp();
+ }
+ else
+ {
+ result = start;
+ }
+
+ //
+ return result;
+ }
+
+ public void setDescription(final String description)
+ {
+ this.description = description;
+ }
+
+ public void setLabel(final String label)
+ {
+ this.label = label;
+ }
+
+ /**
+ * Gets the normalized values.
+ *
+ * @param start
+ * the start
+ * @param end
+ * the end
+ * @return the normalized values
+ */
+ public StringList toNormalizedValues(final YearWeek start, final YearWeek end)
+ {
+ StringList result;
+
+ YearWeek startTarget = normalizeStart(start);
+ YearWeek endTarget = normalizeEnd(end);
+
+ result = new StringList();
+ for (YearWeek timestamp = startTarget; endTarget.isAfter(timestamp); timestamp = timestamp.plusWeeks(1))
+ {
+ result.append(getValue(timestamp));
+ }
+
+ //
+ return result;
+ }
+}
diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/YearValues.java b/src/fr/devinsy/statoolinfos/htmlize/charts/YearValues.java
new file mode 100644
index 0000000..d79956b
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/htmlize/charts/YearValues.java
@@ -0,0 +1,330 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * 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 .
+ */
+package fr.devinsy.statoolinfos.htmlize.charts;
+
+import java.time.Year;
+import java.util.HashMap;
+
+import fr.devinsy.strings.StringList;
+
+/**
+ * The Class YearValues.
+ */
+public class YearValues extends HashMap
+{
+ private static final long serialVersionUID = -3584379965186135356L;
+ private String label;
+ private String description;
+
+ /**
+ * Instantiates a new year values.
+ */
+ public YearValues()
+ {
+ this(null, null);
+ }
+
+ /**
+ * Instantiates a new month values.
+ *
+ * @param label
+ * the label
+ * @param description
+ * the description
+ */
+ public YearValues(final String label, final String description)
+ {
+ super();
+ this.label = label;
+ this.description = description;
+ }
+
+ /**
+ * Adds the.
+ *
+ * @param timestamp
+ * the timestamp
+ * @param value
+ * the value
+ */
+ public void add(final Year timestamp, final double value)
+ {
+ put(timestamp, getValue(timestamp) + value);
+ }
+
+ /**
+ * Adds the all.
+ *
+ * @param source
+ * the source
+ */
+ public void addAll(final YearValues source)
+ {
+ if (source != null)
+ {
+ for (Year timestamp : source.keySet())
+ {
+ add(timestamp, source.getValue(timestamp));
+ }
+ }
+ }
+
+ /**
+ * Dec.
+ *
+ * @param timestamp
+ * the timestamp
+ */
+ public void dec(final Year timestamp)
+ {
+ put(timestamp, getValue(timestamp) - 1);
+ }
+
+ /**
+ * Extract.
+ *
+ * @param start
+ * the start
+ * @param end
+ * the end
+ * @return the month value map
+ */
+ public YearValues extract(final Year start, final Year end)
+ {
+ YearValues result;
+
+ Year startTarget = normalizeStart(start);
+ Year endTarget = normalizeEnd(end);
+
+ result = new YearValues();
+ for (Year timestamp : this.keySet())
+ {
+ if ((!timestamp.isBefore(startTarget)) &&
+ (!timestamp.isAfter(endTarget)))
+ {
+ result.put(timestamp, get(timestamp));
+ }
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the description.
+ *
+ * @return the description
+ */
+ public String getDescription()
+ {
+ return this.description;
+ }
+
+ /**
+ * Gets the label.
+ *
+ * @return the label
+ */
+ public String getLabel()
+ {
+ return this.label;
+ }
+
+ /**
+ * Gets the normalized timestamps.
+ *
+ * @param start
+ * the start
+ * @param end
+ * the end
+ * @return the normalized timestamps
+ */
+ public StringList getNormalizedTimestamps(final Year start, final Year end)
+ {
+ StringList result;
+
+ Year startTarget = normalizeStart(start);
+ Year endTarget = normalizeEnd(end);
+
+ result = new StringList();
+ for (Year timestamp = startTarget; endTarget.isAfter(timestamp); timestamp = timestamp.plusYears(1))
+ {
+ result.append(timestamp);
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the oldest timestamp.
+ *
+ * @return the oldest timestamp
+ */
+ public Year getOldestTimestamp()
+ {
+ Year result;
+
+ result = null;
+
+ for (Year timestamp : this.keySet())
+ {
+ if ((result == null) || (timestamp.isBefore(result)))
+ {
+ result = timestamp;
+ }
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the value.
+ *
+ * @param timestamp
+ * the timestamp
+ * @return the value
+ */
+ public double getValue(final Year timestamp)
+ {
+ double result;
+
+ Double value = get(timestamp);
+ if (value == null)
+ {
+ result = 0.0;
+ }
+ else
+ {
+ result = value;
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Inc.
+ *
+ * @param timestamp
+ * the timestamp
+ */
+ public void inc(final Year timestamp)
+ {
+ put(timestamp, getValue(timestamp) + 1);
+ }
+
+ /**
+ * Normalize end.
+ *
+ * @param end
+ * the end
+ * @return the year
+ */
+ public Year normalizeEnd(final Year end)
+ {
+ Year result;
+
+ Year endTarget;
+ if (end == null)
+ {
+ result = Year.now();
+ }
+ else
+ {
+ result = end;
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Normalize start.
+ *
+ * @param start
+ * the start
+ * @return the year month
+ */
+ public Year normalizeStart(final Year start)
+ {
+ Year result;
+
+ if (start == null)
+ {
+ result = getOldestTimestamp();
+ }
+ else
+ {
+ result = start;
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description
+ * the new description
+ */
+ public void setDescription(final String description)
+ {
+ this.description = description;
+ }
+
+ /**
+ * Sets the label.
+ *
+ * @param label
+ * the new label
+ */
+ public void setLabel(final String label)
+ {
+ this.label = label;
+ }
+
+ /**
+ * Gets the normalized values.
+ *
+ * @param start
+ * the start
+ * @param end
+ * the end
+ * @return the normalized values
+ */
+ public StringList toNormalizedValues(final Year start, final Year end)
+ {
+ StringList result;
+
+ Year startTarget = normalizeStart(start);
+ Year endTarget = normalizeEnd(end);
+
+ result = new StringList();
+ for (Year timestamp = startTarget; endTarget.isAfter(timestamp); timestamp = timestamp.plusYears(1))
+ {
+ result.append(getValue(timestamp));
+ }
+
+ //
+ return result;
+ }
+}
diff --git a/src/fr/devinsy/statoolinfos/htmlize/metricMenuView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/metricMenuView.xhtml
index 2ae525b..77f3085 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/metricMenuView.xhtml
+++ b/src/fr/devinsy/statoolinfos/htmlize/metricMenuView.xhtml
@@ -20,80 +20,158 @@
Spécifiques
+
+function selectViewMenu(selection)
+{
+ currentView = selection;
+ refreshMenu();
+}
+
+function selectPeriodMenu(selection)
+{
+ currentPeriod = selection;
+ refreshMenu();
+}
+
+window.onload=function() {refreshMenu();}
+
+