Browse Source

Improved code on building closed/concluded charts.

master
Christian P. MOMON 2 years ago
parent
commit
1a4fb278fa
  1. 8
      src/org/april/agirstatool/core/AgirStatoolUtils.java
  2. 142
      src/org/april/agirstatool/core/pages/CreatedConcludedCountChartView.java
  3. 6
      src/org/april/agirstatool/core/pages/ProjectPage.java
  4. 9
      src/org/april/agirstatool/core/pages/chartLineView.xhtml

8
src/org/april/agirstatool/core/AgirStatoolUtils.java

@ -101,7 +101,8 @@ public class AgirStatoolUtils
if (index < source.size())
{
DateCount current = source.get(index);
AgirStatoolUtils.logger.info("===> " + dateToken + " " + current.getDate());
// AgirStatoolUtils.logger.info("===> " + dateToken + " " +
// current.getDate());
if (StringUtils.equals(current.getDate(), dateToken))
{
count = current.getCount();
@ -148,13 +149,8 @@ public class AgirStatoolUtils
DateCount current = source.get(dateToken);
if (current != null)
{
AgirStatoolUtils.logger.info("xxx> " + dateToken + " " + current.getDate());
count += current.getCount();
}
else
{
AgirStatoolUtils.logger.info("xxx> " + dateToken + " " + null);
}
result.add(new DateCount(dateToken, count));
date = date.plusWeeks(1);
}

142
src/org/april/agirstatool/core/pages/CreatedConcludedCountChartView.java

@ -44,34 +44,42 @@ public class CreatedConcludedCountChartView
/**
* Builds the.
*
* @param projects
* the projects
* @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) throws AgirStatoolException
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/concluded chart view…");
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 + "lineBar"));
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "lineChart"));
StringList labels = buildWeekLabels(project.issueStats().getFirstCreate().toLocalDate());
StringList labels = buildWeekLabels(start, end);
code = code.replaceAll("labels: \\[.*\\]", "labels: " + AgirStatoolUtils.toJSonStrings(labels));
StringList values = project.issueStats().getWeekCreatedIssueCounts().toValueList();
DateCountList dates = project.issueStats().getWeekCreatedIssueCounts();
StringList values = AgirStatoolUtils.normalizedWeekCountList(dates, start, end).toValueList();
code = code.replaceAll("data: \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
values = project.issueStats().getWeekConcludedIssueCounts().toValueList();
dates = project.issueStats().getWeekConcludedIssueCounts();
values = AgirStatoolUtils.normalizedWeekCountList(dates, start, end).toValueList();
code = code.replaceAll("data: \\[.*\\] ", "data: " + AgirStatoolUtils.toJSonNumbers(values));
result = code.toString();
@ -91,43 +99,36 @@ public class CreatedConcludedCountChartView
}
/**
* Builds the 3 months.
* Builds the.
*
* @param title
* the title
* @param project
* the project
* @param projects
* the projects
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String build(final String title, final Project project, final int monthCount) throws AgirStatoolException
public static String buildFull(final String title, final Project project) throws AgirStatoolException
{
String result;
try
{
logger.info("Building created/closed x months chart view…");
logger.info("Building created/concluded 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 + "lineChartXMonths"));
LocalDate start = LocalDate.now().minusMonths(monthCount);
LocalDate end = LocalDate.now();
code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(title + "lineBar"));
StringList labels = buildWeekLabels(start);
StringList labels = buildWeekLabels(project.issueStats().getFirstCreate().toLocalDate());
code = code.replaceAll("labels: \\[.*\\]", "labels: " + AgirStatoolUtils.toJSonStrings(labels));
DateCountList dates = project.issueStats().getWeekCreatedIssueCounts();
StringList values = AgirStatoolUtils.normalizedWeekCountList(dates, start, end).toValueList();
StringList values = project.issueStats().getWeekCreatedIssueCounts().toValueList();
code = code.replaceAll("data: \\[.*\\]", "data: " + AgirStatoolUtils.toJSonNumbers(values));
dates = project.issueStats().getWeekConcludedIssueCounts();
values = AgirStatoolUtils.normalizedWeekCountList(dates, start, end).toValueList();
values = project.issueStats().getWeekConcludedIssueCounts().toValueList();
code = code.replaceAll("data: \\[.*\\] ", "data: " + AgirStatoolUtils.toJSonNumbers(values));
result = code.toString();
@ -146,6 +147,47 @@ public class CreatedConcludedCountChartView
return result;
}
/**
* Builds the 3 months.
*
* @param title
* the title
* @param project
* the project
* @return the string
* @throws AgirStatoolException
* the agir statool exception
*/
public static String buildLastMonth(final String title, final Project project, final int monthCount) throws AgirStatoolException
{
String result;
logger.info("Building created/closed x months chart view…");
result = build(title, project, LocalDate.now().minusMonths(monthCount), LocalDate.now());
//
return result;
}
/**
* @param title
* @param project
* @return
* @throws AgirStatoolException
*/
public static String buildLastYear(final String title, final Project project) throws AgirStatoolException
{
String result;
logger.info("Building created/closed x months chart view…");
result = buildYear(title, project, LocalDate.now().getYear() - 1);
//
return result;
}
/**
* Builds the week labels.
*
@ -157,13 +199,32 @@ public class CreatedConcludedCountChartView
{
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();
if (start != null)
{
LocalDate end = AgirStatoolUtils.normaliseWeekDate(LocalDate.now());
LocalDate normalizedEnd = AgirStatoolUtils.normaliseWeekDate(end);
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"));
result.add(label);
@ -174,4 +235,33 @@ public class CreatedConcludedCountChartView
//
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;
}
}

6
src/org/april/agirstatool/core/pages/ProjectPage.java

@ -58,9 +58,9 @@ public class ProjectPage
data.setContent("agirLink", project.getName());
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.build("Created/closed 3 months Count", project, 3));
data.setContent("issueCreatedClosed6MonthsChart", CreatedConcludedCountChartView.build("Created/closed 6 months Count", project, 6));
data.setContent("issueCreatedClosed3MonthsChart", CreatedConcludedCountChartView.buildLastYear("Created/closed last year Count", project));
data.setContent("issueCreatedClosed6MonthsChart", CreatedConcludedCountChartView.buildLastMonth("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("issueGroupedChart", IssueStatChartView.buildGrouped("Issue Grouped Count", project));

9
src/org/april/agirstatool/core/pages/chartLineView.xhtml

@ -49,20 +49,25 @@ var myChart = new Chart(ctx,
options:
{
maintainAspectRatio: false,
title: {
display: false,
text: 'Min and Max Settings'
},
scales:
{
xAxes:
[{
ticks:
{
beginAtZero: true
beginAtZero: false
}
}],
yAxes:
[{
ticks:
{
beginAtZero: true
beginAtZero: false,
suggestedMax: 10
}
}]
}

Loading…
Cancel
Save