199 lines
5.3 KiB
Java
199 lines
5.3 KiB
Java
|
/*
|
||
|
* Copyright (C) 2020 Christian Pierre MOMON <christian.momon@devinsy.fr>
|
||
|
*
|
||
|
* This file is part of AgirStatool, simple key value database.
|
||
|
*
|
||
|
* AgirStatool 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.
|
||
|
*
|
||
|
* AgirStatool 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 AgirStatool. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
package org.april.agirstatool.core.pages;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.time.LocalDate;
|
||
|
|
||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||
|
import org.april.agirstatool.core.AgirStatool;
|
||
|
import org.april.agirstatool.core.AgirStatoolException;
|
||
|
import org.april.agirstatool.core.AgirStatoolUtils;
|
||
|
import org.april.agirstatool.core.Project;
|
||
|
import org.slf4j.Logger;
|
||
|
import org.slf4j.LoggerFactory;
|
||
|
|
||
|
import fr.devinsy.strings.StringList;
|
||
|
import fr.devinsy.xidyn.utils.XidynUtils;
|
||
|
|
||
|
/**
|
||
|
* The Class projectsRawPageBuilder.
|
||
|
*/
|
||
|
public class IssueAgeChartView
|
||
|
{
|
||
|
private static Logger logger = LoggerFactory.getLogger(IssueAgeChartView.class);
|
||
|
|
||
|
/**
|
||
|
* Builds the.
|
||
|
*
|
||
|
* @param title
|
||
|
* the title
|
||
|
* @param project
|
||
|
* the project
|
||
|
* @param start
|
||
|
* the start
|
||
|
* @param end
|
||
|
* the end
|
||
|
* @return the string
|
||
|
* @throws AgirStatoolException
|
||
|
* the agir statool exception
|
||
|
*/
|
||
|
public static String build(final String title, final Project project, final LocalDate start, final LocalDate end) throws AgirStatoolException
|
||
|
{
|
||
|
String result;
|
||
|
|
||
|
try
|
||
|
{
|
||
|
if (project.hasIssue())
|
||
|
{
|
||
|
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/issueAgeChartView.xhtml"));
|
||
|
String code = XidynUtils.extractBodyContent(source);
|
||
|
|
||
|
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "ageStatsChart"));
|
||
|
|
||
|
StringList labels = AgirStatoolUtils.buildWeekLabels(start, end);
|
||
|
code = code.replaceAll("labels: \\[.*\\]", "labels: " + AgirStatoolUtils.toJSonStrings(labels));
|
||
|
|
||
|
StringList values = AgirStatoolUtils.buildWeekMinAges(project, start, end);
|
||
|
code = code.replaceAll("data: \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
|
||
|
|
||
|
values = AgirStatoolUtils.buildWeekMeanAges(project, start, end);
|
||
|
code = code.replaceAll("data : \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
|
||
|
|
||
|
values = AgirStatoolUtils.buildWeekMaxAges(project, start, end);
|
||
|
code = code.replaceAll("data : \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
|
||
|
|
||
|
result = code.toString();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
result = "No issue.";
|
||
|
}
|
||
|
}
|
||
|
catch (IOException exception)
|
||
|
{
|
||
|
throw new AgirStatoolException("Error building ProjectsRaw view: " + exception.getMessage(), exception);
|
||
|
}
|
||
|
|
||
|
//
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Builds the full.
|
||
|
*
|
||
|
* @param title
|
||
|
* the title
|
||
|
* @param project
|
||
|
* the project
|
||
|
* @return the string
|
||
|
* @throws AgirStatoolException
|
||
|
* the agir statool exception
|
||
|
*/
|
||
|
public static String buildFull(final String title, final Project project) throws AgirStatoolException
|
||
|
{
|
||
|
String result;
|
||
|
|
||
|
logger.debug("Building created/concluded chart view…");
|
||
|
|
||
|
if (project.hasIssue())
|
||
|
{
|
||
|
result = build(title, project, project.issueStats().getFirstCreate().toLocalDate(), LocalDate.now());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
result = "No issue.";
|
||
|
}
|
||
|
|
||
|
//
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Builds the last months.
|
||
|
*
|
||
|
* @param title
|
||
|
* the title
|
||
|
* @param project
|
||
|
* the project
|
||
|
* @param monthCount
|
||
|
* the month count
|
||
|
* @return the string
|
||
|
* @throws AgirStatoolException
|
||
|
* the agir statool exception
|
||
|
*/
|
||
|
public static String buildLastMonths(final String title, final Project project, final int monthCount) throws AgirStatoolException
|
||
|
{
|
||
|
String result;
|
||
|
|
||
|
result = build(title, project, LocalDate.now().minusMonths(monthCount), LocalDate.now());
|
||
|
|
||
|
//
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Builds the previous year.
|
||
|
*
|
||
|
* @param title
|
||
|
* the title
|
||
|
* @param project
|
||
|
* the project
|
||
|
* @return the string
|
||
|
* @throws AgirStatoolException
|
||
|
* the agir statool exception
|
||
|
*/
|
||
|
public static String buildPreviousYear(final String title, final Project project) throws AgirStatoolException
|
||
|
{
|
||
|
String result;
|
||
|
|
||
|
result = buildYear(title, project, LocalDate.now().getYear() - 1);
|
||
|
|
||
|
//
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Builds the year.
|
||
|
*
|
||
|
* @param title
|
||
|
* the title
|
||
|
* @param project
|
||
|
* the project
|
||
|
* @param year
|
||
|
* the year
|
||
|
* @return the string
|
||
|
* @throws AgirStatoolException
|
||
|
* the agir statool exception
|
||
|
*/
|
||
|
public static String buildYear(final String title, final Project project, final int year) throws AgirStatoolException
|
||
|
{
|
||
|
String result;
|
||
|
|
||
|
LocalDate start = LocalDate.of(year, 1, 1).minusDays(7);
|
||
|
LocalDate end = LocalDate.of(year + 1, 1, 1).minusDays(1);
|
||
|
|
||
|
result = build(title, project, start, end);
|
||
|
|
||
|
//
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
}
|