Clean code.

This commit is contained in:
Christian P. MOMON 2021-05-25 16:30:52 +02:00
parent 18b2c3eecc
commit 060f9d8c6e
2 changed files with 0 additions and 201 deletions

View file

@ -1,124 +0,0 @@
/*
* Copyright (C) 2020 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.charts;
import java.io.IOException;
import java.time.LocalDate;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.metrics.Metric;
import fr.devinsy.strings.StringList;
import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class projectsRawPageBuilder.
*/
public class BarMonthsChartView
{
private static Logger logger = LoggerFactory.getLogger(BarMonthsChartView.class);
/**
* Builds the.
*
* @param metric
* the metric
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String build(final Metric metric) throws StatoolInfosException
{
String result;
result = build(metric, ChartColor.BLUE);
//
return result;
}
/**
* Builds the.
*
* @param metric
* the metric
* @return the string
* @throws StatoolInfosException
*/
public static String build(final Metric metric, final ChartColor color) throws StatoolInfosException
{
String result;
LocalDate start = LocalDate.parse(metric.getStartYear() + "-01-01");
LocalDate end = start.plusMonths(metric.getMonthValues().size() - 1);
StringList labels = ChabuUtils.buildYearMonthAlphaLabels(start, end);
result = build(metric.getName(), metric.getDescription(), labels, metric.getMonthValues(), color);
//
return result;
}
/**
* Builds the.
*
* @param title
* the title
* @param description
* the description
* @param labels
* the labels
* @param values
* the values
* @param color
* the color
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String build(final String title, final String description, final StringList labels, final StringList values, final ChartColor color) throws StatoolInfosException
{
String result;
try
{
String source = XidynUtils.load(ChabuUtils.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/barMonthsChartView.xhtml"));
String code = XidynUtils.extractBodyContent(source);
code = code.replace("rgb(54, 162, 235)", color.code());
code = code.replace("rgb(54, 162, 235, 0.2)", color.light());
code = code.replace("description", XidynUtils.escapeXmlBlank(description));
code = code.replace("myChart", "myChart_" + DigestUtils.sha1Hex(title + "barMonthsChart"));
code = code.replace("# of Votes", title.replace("'", "\\\\'"));
code = code.replaceFirst("labels: \\[.*\\]", "labels: " + ChabuUtils.toJSonStrings(labels));
code = code.replaceFirst("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(values));
result = code.toString();
}
catch (IOException exception)
{
throw new StatoolInfosException("Error building bar months chart view: " + exception.getMessage(), exception);
}
//
return result;
}
}

View file

@ -1,77 +0,0 @@
/*
* Copyright (C) 2020 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.charts;
import java.io.IOException;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.strings.StringList;
import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class BarTimeChartView.
*/
public class BarTimeChartView
{
private static Logger logger = LoggerFactory.getLogger(BarTimeChartView.class);
/**
* Builds the.
*
* @param title
* the title
* @param labelTitle
* the label title
* @param labels
* the labels
* @param values
* the values
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String build(final String title, final String labelTitle, final StringList labels, final StringList values) throws StatoolInfosException
{
String result;
try
{
String source = XidynUtils.load(ChabuUtils.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/barTimeChartView.xhtml"));
String code = XidynUtils.extractBodyContent(source);
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "chartBar"));
code = code.replace("# of Votes", labelTitle);
code = code.replaceAll("labels: \\[.*\\]", "labels: " + ChabuUtils.toJSonStrings(labels));
code = code.replaceAll("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(values));
result = code.toString();
}
catch (IOException exception)
{
throw new StatoolInfosException("Error building ProjectsRaw view: " + exception.getMessage(), exception);
}
//
return result;
}
}