2020-01-21 20:07:49 +01:00
|
|
|
/*
|
|
|
|
* 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;
|
2020-01-24 13:15:24 +01:00
|
|
|
import org.april.agirstatool.charts.DateCount;
|
2020-01-22 10:39:44 +01:00
|
|
|
import org.april.agirstatool.charts.DateCountList;
|
2020-01-21 20:07:49 +01:00
|
|
|
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.
|
|
|
|
*/
|
2020-01-24 13:15:24 +01:00
|
|
|
public class CreatedClosedDiffChartView
|
2020-01-21 20:07:49 +01:00
|
|
|
{
|
2020-01-24 13:15:24 +01:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(CreatedClosedDiffChartView.class);
|
2020-01-21 20:07:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the.
|
|
|
|
*
|
2020-01-22 12:09:49 +01:00
|
|
|
* @param title
|
|
|
|
* the title
|
|
|
|
* @param project
|
|
|
|
* the project
|
|
|
|
* @param start
|
|
|
|
* the start
|
|
|
|
* @param end
|
|
|
|
* the end
|
2020-01-21 20:07:49 +01:00
|
|
|
* @return the string
|
|
|
|
* @throws AgirStatoolException
|
|
|
|
* the agir statool exception
|
|
|
|
*/
|
2020-01-22 12:09:49 +01:00
|
|
|
public static String build(final String title, final Project project, final LocalDate start, final LocalDate end) throws AgirStatoolException
|
2020-01-21 20:07:49 +01:00
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-01-22 10:39:44 +01:00
|
|
|
if (project.hasIssue())
|
2020-01-21 20:07:49 +01:00
|
|
|
{
|
2020-01-24 13:15:24 +01:00
|
|
|
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/chartLineView2.xhtml"));
|
2020-01-21 20:07:49 +01:00
|
|
|
String code = XidynUtils.extractBodyContent(source);
|
|
|
|
|
2020-01-24 13:15:24 +01:00
|
|
|
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "line2Chart"));
|
2020-01-21 20:07:49 +01:00
|
|
|
|
2020-01-29 00:51:45 +01:00
|
|
|
StringList labels = AgirStatoolUtils.buildWeekLabels(start, end);
|
2020-01-21 20:07:49 +01:00
|
|
|
code = code.replaceAll("labels: \\[.*\\]", "labels: " + AgirStatoolUtils.toJSonStrings(labels));
|
|
|
|
|
2020-01-24 13:15:24 +01:00
|
|
|
DateCountList createdDates = project.issueStats().getWeekCreatedIssueCounts();
|
|
|
|
DateCountList closedDates = project.issueStats().getWeekConcludedIssueCounts();
|
|
|
|
DateCountList dates = new DateCountList(createdDates.size());
|
|
|
|
for (int dateIndex = 0; dateIndex < createdDates.size(); dateIndex++)
|
|
|
|
{
|
|
|
|
DateCount createdDate = createdDates.get(dateIndex);
|
|
|
|
DateCount closedDate = closedDates.get(dateIndex);
|
|
|
|
dates.add(new DateCount(createdDate.getDate(), createdDate.getCount() - closedDate.getCount()));
|
|
|
|
}
|
|
|
|
|
2020-01-22 12:09:49 +01:00
|
|
|
StringList values = AgirStatoolUtils.normalizedWeekCountList(dates, start, end).toValueList();
|
2020-01-21 20:07:49 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-22 19:37:28 +01:00
|
|
|
* Builds the full.
|
2020-01-21 20:07:49 +01:00
|
|
|
*
|
2020-01-22 19:37:28 +01:00
|
|
|
* @param title
|
|
|
|
* the title
|
|
|
|
* @param project
|
|
|
|
* the project
|
2020-01-21 20:07:49 +01:00
|
|
|
* @return the string
|
|
|
|
* @throws AgirStatoolException
|
|
|
|
* the agir statool exception
|
|
|
|
*/
|
2020-01-22 12:09:49 +01:00
|
|
|
public static String buildFull(final String title, final Project project) throws AgirStatoolException
|
2020-01-21 20:07:49 +01:00
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2020-01-27 13:17:21 +01:00
|
|
|
logger.debug("Building created/concluded chart view…");
|
2020-01-21 20:07:49 +01:00
|
|
|
|
2020-01-27 13:17:21 +01:00
|
|
|
if (project.hasIssue())
|
|
|
|
{
|
|
|
|
result = build(title, project, project.issueStats().getFirstCreate().toLocalDate(), LocalDate.now());
|
2020-01-21 20:07:49 +01:00
|
|
|
}
|
2020-01-27 13:17:21 +01:00
|
|
|
else
|
2020-01-21 20:07:49 +01:00
|
|
|
{
|
2020-01-27 13:17:21 +01:00
|
|
|
result = "No issue.";
|
2020-01-21 20:07:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-01-22 12:09:49 +01:00
|
|
|
/**
|
2020-01-23 09:00:46 +01:00
|
|
|
* Builds the last months.
|
2020-01-22 12:09:49 +01:00
|
|
|
*
|
|
|
|
* @param title
|
|
|
|
* the title
|
|
|
|
* @param project
|
|
|
|
* the project
|
2020-01-23 09:00:46 +01:00
|
|
|
* @param monthCount
|
|
|
|
* the month count
|
2020-01-22 12:09:49 +01:00
|
|
|
* @return the string
|
|
|
|
* @throws AgirStatoolException
|
|
|
|
* the agir statool exception
|
|
|
|
*/
|
2020-01-22 18:13:34 +01:00
|
|
|
public static String buildLastMonths(final String title, final Project project, final int monthCount) throws AgirStatoolException
|
2020-01-22 12:09:49 +01:00
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
|
|
|
result = build(title, project, LocalDate.now().minusMonths(monthCount), LocalDate.now());
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-22 19:37:28 +01:00
|
|
|
* Builds the previous year.
|
|
|
|
*
|
2020-01-22 12:09:49 +01:00
|
|
|
* @param title
|
2020-01-22 19:37:28 +01:00
|
|
|
* the title
|
2020-01-22 12:09:49 +01:00
|
|
|
* @param project
|
2020-01-22 19:37:28 +01:00
|
|
|
* the project
|
|
|
|
* @return the string
|
2020-01-22 12:09:49 +01:00
|
|
|
* @throws AgirStatoolException
|
2020-01-22 19:37:28 +01:00
|
|
|
* the agir statool exception
|
2020-01-22 12:09:49 +01:00
|
|
|
*/
|
2020-01-22 18:13:34 +01:00
|
|
|
public static String buildPreviousYear(final String title, final Project project) throws AgirStatoolException
|
2020-01-22 12:09:49 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-01-21 20:07:49 +01:00
|
|
|
}
|