Improved code on building closed/concluded charts.
This commit is contained in:
parent
7a770e562b
commit
1a4fb278fa
4 changed files with 137 additions and 46 deletions
|
@ -101,7 +101,8 @@ public class AgirStatoolUtils
|
||||||
if (index < source.size())
|
if (index < source.size())
|
||||||
{
|
{
|
||||||
DateCount current = source.get(index);
|
DateCount current = source.get(index);
|
||||||
AgirStatoolUtils.logger.info("===> " + dateToken + " " + current.getDate());
|
// AgirStatoolUtils.logger.info("===> " + dateToken + " " +
|
||||||
|
// current.getDate());
|
||||||
if (StringUtils.equals(current.getDate(), dateToken))
|
if (StringUtils.equals(current.getDate(), dateToken))
|
||||||
{
|
{
|
||||||
count = current.getCount();
|
count = current.getCount();
|
||||||
|
@ -148,13 +149,8 @@ public class AgirStatoolUtils
|
||||||
DateCount current = source.get(dateToken);
|
DateCount current = source.get(dateToken);
|
||||||
if (current != null)
|
if (current != null)
|
||||||
{
|
{
|
||||||
AgirStatoolUtils.logger.info("xxx> " + dateToken + " " + current.getDate());
|
|
||||||
count += current.getCount();
|
count += current.getCount();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
AgirStatoolUtils.logger.info("xxx> " + dateToken + " " + null);
|
|
||||||
}
|
|
||||||
result.add(new DateCount(dateToken, count));
|
result.add(new DateCount(dateToken, count));
|
||||||
date = date.plusWeeks(1);
|
date = date.plusWeeks(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,63 @@ public class CreatedConcludedCountChartView
|
||||||
{
|
{
|
||||||
private static Logger logger = LoggerFactory.getLogger(CreatedConcludedCountChartView.class);
|
private static Logger logger = LoggerFactory.getLogger(CreatedConcludedCountChartView.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
|
||||||
|
{
|
||||||
|
logger.info("Building created/closed x months chart view…");
|
||||||
|
|
||||||
|
if (project.hasIssue())
|
||||||
|
{
|
||||||
|
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/chartLineView.xhtml"));
|
||||||
|
String code = XidynUtils.extractBodyContent(source);
|
||||||
|
|
||||||
|
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "lineChart"));
|
||||||
|
|
||||||
|
StringList labels = buildWeekLabels(start, end);
|
||||||
|
code = code.replaceAll("labels: \\[.*\\]", "labels: " + AgirStatoolUtils.toJSonStrings(labels));
|
||||||
|
|
||||||
|
DateCountList dates = project.issueStats().getWeekCreatedIssueCounts();
|
||||||
|
StringList values = AgirStatoolUtils.normalizedWeekCountList(dates, start, end).toValueList();
|
||||||
|
code = code.replaceAll("data: \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
|
||||||
|
|
||||||
|
dates = project.issueStats().getWeekConcludedIssueCounts();
|
||||||
|
values = AgirStatoolUtils.normalizedWeekCountList(dates, start, end).toValueList();
|
||||||
|
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.
|
* Builds the.
|
||||||
*
|
*
|
||||||
|
@ -50,7 +107,7 @@ public class CreatedConcludedCountChartView
|
||||||
* @throws AgirStatoolException
|
* @throws AgirStatoolException
|
||||||
* the agir statool exception
|
* the agir statool exception
|
||||||
*/
|
*/
|
||||||
public static String build(final String title, final Project project) throws AgirStatoolException
|
public static String buildFull(final String title, final Project project) throws AgirStatoolException
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
|
|
||||||
|
@ -101,46 +158,31 @@ public class CreatedConcludedCountChartView
|
||||||
* @throws AgirStatoolException
|
* @throws AgirStatoolException
|
||||||
* the agir statool exception
|
* the agir statool exception
|
||||||
*/
|
*/
|
||||||
public static String build(final String title, final Project project, final int monthCount) throws AgirStatoolException
|
public static String buildLastMonth(final String title, final Project project, final int monthCount) throws AgirStatoolException
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
|
|
||||||
try
|
logger.info("Building created/closed x months chart view…");
|
||||||
{
|
|
||||||
logger.info("Building created/closed x months chart view…");
|
|
||||||
|
|
||||||
if (project.hasIssue())
|
result = build(title, project, LocalDate.now().minusMonths(monthCount), LocalDate.now());
|
||||||
{
|
|
||||||
String source = XidynUtils.load(AgirStatool.class.getResource("/org/april/agirstatool/core/pages/chartLineView.xhtml"));
|
|
||||||
String code = XidynUtils.extractBodyContent(source);
|
|
||||||
|
|
||||||
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "lineChartXMonths"));
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
LocalDate start = LocalDate.now().minusMonths(monthCount);
|
/**
|
||||||
LocalDate end = LocalDate.now();
|
* @param title
|
||||||
|
* @param project
|
||||||
|
* @return
|
||||||
|
* @throws AgirStatoolException
|
||||||
|
*/
|
||||||
|
public static String buildLastYear(final String title, final Project project) throws AgirStatoolException
|
||||||
|
{
|
||||||
|
String result;
|
||||||
|
|
||||||
StringList labels = buildWeekLabels(start);
|
logger.info("Building created/closed x months chart view…");
|
||||||
code = code.replaceAll("labels: \\[.*\\]", "labels: " + AgirStatoolUtils.toJSonStrings(labels));
|
|
||||||
|
|
||||||
DateCountList dates = project.issueStats().getWeekCreatedIssueCounts();
|
result = buildYear(title, project, LocalDate.now().getYear() - 1);
|
||||||
StringList values = AgirStatoolUtils.normalizedWeekCountList(dates, start, end).toValueList();
|
|
||||||
code = code.replaceAll("data: \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
|
|
||||||
|
|
||||||
dates = project.issueStats().getWeekConcludedIssueCounts();
|
|
||||||
values = AgirStatoolUtils.normalizedWeekCountList(dates, start, end).toValueList();
|
|
||||||
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;
|
return result;
|
||||||
|
@ -157,13 +199,32 @@ public class CreatedConcludedCountChartView
|
||||||
{
|
{
|
||||||
StringList result;
|
StringList result;
|
||||||
|
|
||||||
|
result = buildWeekLabels(start, LocalDate.now());
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the week labels.
|
||||||
|
*
|
||||||
|
* @param start
|
||||||
|
* the start
|
||||||
|
* @param end
|
||||||
|
* the end
|
||||||
|
* @return the string list
|
||||||
|
*/
|
||||||
|
private static StringList buildWeekLabels(final LocalDate start, final LocalDate end)
|
||||||
|
{
|
||||||
|
StringList result;
|
||||||
|
|
||||||
result = new StringList();
|
result = new StringList();
|
||||||
|
|
||||||
if (start != null)
|
if (start != null)
|
||||||
{
|
{
|
||||||
LocalDate end = AgirStatoolUtils.normaliseWeekDate(LocalDate.now());
|
LocalDate normalizedEnd = AgirStatoolUtils.normaliseWeekDate(end);
|
||||||
LocalDate date = AgirStatoolUtils.normaliseWeekDate(start);
|
LocalDate date = AgirStatoolUtils.normaliseWeekDate(start);
|
||||||
while (date.isBefore(end) || date.isEqual(end))
|
while (date.isBefore(normalizedEnd) || date.isEqual(normalizedEnd))
|
||||||
{
|
{
|
||||||
String label = date.format(DateTimeFormatter.ofPattern("yyyy-MMM"));
|
String label = date.format(DateTimeFormatter.ofPattern("yyyy-MMM"));
|
||||||
result.add(label);
|
result.add(label);
|
||||||
|
@ -174,4 +235,33 @@ public class CreatedConcludedCountChartView
|
||||||
//
|
//
|
||||||
return result;
|
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;
|
||||||
|
|
||||||
|
logger.info("Building created/closed x months chart view…");
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,9 +58,9 @@ public class ProjectPage
|
||||||
data.setContent("agirLink", project.getName());
|
data.setContent("agirLink", project.getName());
|
||||||
data.setAttribute("agirLink", "href", "https://agir.april.org/projects/" + project.getIdentifier() + "/issues");
|
data.setAttribute("agirLink", "href", "https://agir.april.org/projects/" + project.getIdentifier() + "/issues");
|
||||||
|
|
||||||
data.setContent("issueCreatedClosedChart", CreatedConcludedCountChartView.build("Created/closed Count", project));
|
data.setContent("issueCreatedClosed3MonthsChart", CreatedConcludedCountChartView.buildLastYear("Created/closed last year Count", project));
|
||||||
data.setContent("issueCreatedClosed3MonthsChart", CreatedConcludedCountChartView.build("Created/closed 3 months Count", project, 3));
|
data.setContent("issueCreatedClosed6MonthsChart", CreatedConcludedCountChartView.buildLastMonth("Created/closed 6 months Count", project, 6));
|
||||||
data.setContent("issueCreatedClosed6MonthsChart", CreatedConcludedCountChartView.build("Created/closed 6 months Count", project, 6));
|
data.setContent("issueCreatedClosedChart", CreatedConcludedCountChartView.buildFull("Created/closed Count", project));
|
||||||
|
|
||||||
data.setContent("issueRawChart", IssueStatChartView.build("Issue Raw Count", project));
|
data.setContent("issueRawChart", IssueStatChartView.build("Issue Raw Count", project));
|
||||||
data.setContent("issueGroupedChart", IssueStatChartView.buildGrouped("Issue Grouped Count", project));
|
data.setContent("issueGroupedChart", IssueStatChartView.buildGrouped("Issue Grouped Count", project));
|
||||||
|
|
|
@ -49,20 +49,25 @@ var myChart = new Chart(ctx,
|
||||||
options:
|
options:
|
||||||
{
|
{
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
|
title: {
|
||||||
|
display: false,
|
||||||
|
text: 'Min and Max Settings'
|
||||||
|
},
|
||||||
scales:
|
scales:
|
||||||
{
|
{
|
||||||
xAxes:
|
xAxes:
|
||||||
[{
|
[{
|
||||||
ticks:
|
ticks:
|
||||||
{
|
{
|
||||||
beginAtZero: true
|
beginAtZero: false
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
yAxes:
|
yAxes:
|
||||||
[{
|
[{
|
||||||
ticks:
|
ticks:
|
||||||
{
|
{
|
||||||
beginAtZero: true
|
beginAtZero: false,
|
||||||
|
suggestedMax: 10
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue