From 5060ce34ad773c1f7997bda8f5b9fd7ab47ab830 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 30 Jan 2020 03:07:52 +0100 Subject: [PATCH] Prepared duration issue chart. --- .../april/agirstatool/core/AgirStatool.java | 4 +- .../agirstatool/core/AgirStatoolUtils.java | 29 +++ .../april/agirstatool/core/CompareUtils.java | 36 ++++ src/org/april/agirstatool/core/Issue.java | 16 +- .../agirstatool/core/IssueComparator.java | 188 ++++++++++++++++++ src/org/april/agirstatool/core/Issues.java | 64 ++++++ src/org/april/agirstatool/core/Projects.java | 1 - 7 files changed, 327 insertions(+), 11 deletions(-) create mode 100644 src/org/april/agirstatool/core/IssueComparator.java diff --git a/src/org/april/agirstatool/core/AgirStatool.java b/src/org/april/agirstatool/core/AgirStatool.java index 13b34f3..9ba732c 100644 --- a/src/org/april/agirstatool/core/AgirStatool.java +++ b/src/org/april/agirstatool/core/AgirStatool.java @@ -302,8 +302,8 @@ public class AgirStatool while (resultSet.next()) { - int id = resultSet.getInt(1); - int projectId = resultSet.getInt(2); + long id = resultSet.getInt(1); + long projectId = resultSet.getInt(2); LocalDateTime createdOn = SQLUtils.toLocalDateTime(resultSet.getTimestamp(3)); LocalDateTime closedOn = SQLUtils.toLocalDateTime(resultSet.getTimestamp(4)); diff --git a/src/org/april/agirstatool/core/AgirStatoolUtils.java b/src/org/april/agirstatool/core/AgirStatoolUtils.java index d9f9330..caa04c6 100644 --- a/src/org/april/agirstatool/core/AgirStatoolUtils.java +++ b/src/org/april/agirstatool/core/AgirStatoolUtils.java @@ -46,6 +46,35 @@ public class AgirStatoolUtils public static final DateTimeFormatter PATTERN_SHORTDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.FRANCE); public static final DateTimeFormatter PATTERN_LONGDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy hh':'mm", Locale.FRANCE); + public static StringList buildWeekDuration(final Project project, final LocalDate start, final LocalDate end) + { + StringList result; + + result = new StringList(); + + if (start != null) + { + Issues issues = new Issues(); + issues.addAll(project.issues()); + issues.sort(IssueComparator.Sorting.CLOSEDON); + + LocalDate date = AgirStatoolUtils.normaliseWeekDate(start); + LocalDate normalizedEnd = AgirStatoolUtils.normaliseWeekDate(end); + while (!date.isAfter(normalizedEnd)) + { + Stat stat = project.issues().extractActivedAt(date).computeStat(date); + + result.add(String.format(Locale.ENGLISH, "%.2f", stat.getMean())); + + // + date = date.plusWeeks(1); + } + } + + // + return result; + } + /** * Builds the week labels. * diff --git a/src/org/april/agirstatool/core/CompareUtils.java b/src/org/april/agirstatool/core/CompareUtils.java index ce8d54a..df55daa 100644 --- a/src/org/april/agirstatool/core/CompareUtils.java +++ b/src/org/april/agirstatool/core/CompareUtils.java @@ -1,5 +1,7 @@ package org.april.agirstatool.core; +import java.time.LocalDateTime; + import org.apache.commons.lang3.StringUtils; /** @@ -109,6 +111,40 @@ public class CompareUtils return result; } + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @return the int + */ + public static int compare(final LocalDateTime alpha, final LocalDateTime bravo) + { + int result; + + if ((alpha == null) && (bravo == null)) + { + result = 0; + } + else if (alpha == null) + { + result = -1; + } + else if (bravo == null) + { + result = +1; + } + else + { + result = alpha.compareTo(bravo); + } + + // + return result; + } + /** * Compare. * diff --git a/src/org/april/agirstatool/core/Issue.java b/src/org/april/agirstatool/core/Issue.java index d52090e..bd49244 100644 --- a/src/org/april/agirstatool/core/Issue.java +++ b/src/org/april/agirstatool/core/Issue.java @@ -28,8 +28,8 @@ import java.time.ZoneOffset; */ public class Issue { - private int id; - private Integer projectId; + private long id; + private Long projectId; private LocalDateTime createdOn; private LocalDateTime closedOn; @@ -41,7 +41,7 @@ public class Issue * @param createdOn * the created on */ - public Issue(final int id, final Integer projectId, final LocalDateTime createdOn) + public Issue(final long id, final Long projectId, final LocalDateTime createdOn) { this(id, projectId, createdOn, null); } @@ -56,7 +56,7 @@ public class Issue * @param closedOn * the closed on */ - public Issue(final int id, final Integer projectId, final LocalDateTime createdOn, final LocalDateTime closedOn) + public Issue(final long id, final Long projectId, final LocalDateTime createdOn, final LocalDateTime closedOn) { this.id = id; this.projectId = projectId; @@ -134,12 +134,12 @@ public class Issue return this.createdOn; } - public int getId() + public long getId() { return this.id; } - public Integer getProjectId() + public Long getProjectId() { return this.projectId; } @@ -233,12 +233,12 @@ public class Issue this.createdOn = createdOn; } - public void setId(final int id) + public void setId(final long id) { this.id = id; } - public void setProjectId(final Integer projectId) + public void setProjectId(final Long projectId) { this.projectId = projectId; } diff --git a/src/org/april/agirstatool/core/IssueComparator.java b/src/org/april/agirstatool/core/IssueComparator.java new file mode 100644 index 0000000..a152991 --- /dev/null +++ b/src/org/april/agirstatool/core/IssueComparator.java @@ -0,0 +1,188 @@ +package org.april.agirstatool.core; + +import java.time.LocalDateTime; +import java.util.Comparator; + +/** + * The Class ProjectComparator. + */ +public class IssueComparator implements Comparator +{ + public enum Sorting + { + ID, + PROJECTID, + CREATEDON, + CLOSEDON + } + + private Sorting sorting; + + /** + * Instantiates a new project comparator. + * + * @param sorting + * the sorting + */ + public IssueComparator(final Sorting sorting) + { + // + this.sorting = sorting; + } + + /** + * + */ + @Override + public int compare(final Issue alpha, final Issue bravo) + { + int result; + + result = compare(alpha, bravo, this.sorting); + + // + return result; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @param sorting + * the sorting + * @return the int + */ + public static int compare(final Issue alpha, final Issue bravo, final Sorting sorting) + { + int result; + + if (sorting == null) + { + result = 0; + } + else + { + switch (sorting) + { + default: + case ID: + result = CompareUtils.compare(getId(alpha), getId(bravo)); + break; + + case PROJECTID: + result = CompareUtils.compare(getProjectId(alpha), getProjectId(bravo)); + break; + + case CREATEDON: + result = CompareUtils.compare(getCreatedOn(alpha), getCreatedOn(bravo)); + break; + + case CLOSEDON: + result = CompareUtils.compare(getClosedOn(alpha), getClosedOn(bravo)); + break; + } + } + + // + return result; + } + + /** + * Gets the closed on. + * + * @param source + * the source + * @return the closed on + */ + public static LocalDateTime getClosedOn(final Issue source) + { + LocalDateTime result; + + if (source == null) + { + result = null; + } + else + { + result = source.getClosedOn(); + } + + // + return result; + } + + /** + * Gets the created on. + * + * @param source + * the source + * @return the created on + */ + public static LocalDateTime getCreatedOn(final Issue source) + { + LocalDateTime result; + + if (source == null) + { + result = null; + } + else + { + result = source.getCreatedOn(); + } + + // + return result; + } + + /** + * Gets the id. + * + * @param source + * the source + * @return the id + */ + public static Long getId(final Issue source) + { + Long result; + + if (source == null) + { + result = null; + } + else + { + result = source.getId(); + } + + // + return result; + } + + /** + * Gets the identifier. + * + * @param source + * the source + * @return the identifier + */ + public static Long getProjectId(final Issue source) + { + Long result; + + if (source == null) + { + result = null; + } + else + { + result = source.getProjectId(); + } + + // + return result; + } +} diff --git a/src/org/april/agirstatool/core/Issues.java b/src/org/april/agirstatool/core/Issues.java index 2be8d94..90425d9 100644 --- a/src/org/april/agirstatool/core/Issues.java +++ b/src/org/april/agirstatool/core/Issues.java @@ -142,4 +142,68 @@ public class Issues extends ArrayList // return result; } + + /** + * Sort. + * + * @param sorting + * the sorting + * @return the issues + */ + public Issues sort(final IssueComparator.Sorting sorting) + { + Issues result; + + sort(new IssueComparator(sorting)); + + result = this; + + // + return result; + } + + /** + * Sort by created on. + * + * @return the issues + */ + public Issues sortByCreatedOn() + { + Issues result; + + result = sort(IssueComparator.Sorting.CREATEDON); + + // + return result; + } + + /** + * Sort by id. + * + * @return the issues + */ + public Issues sortById() + { + Issues result; + + result = sort(IssueComparator.Sorting.ID); + + // + return result; + } + + /** + * Sort by identifier. + * + * @return the issues + */ + public Issues sortByProjectId() + { + Issues result; + + result = sort(IssueComparator.Sorting.PROJECTID); + + // + return result; + } } \ No newline at end of file diff --git a/src/org/april/agirstatool/core/Projects.java b/src/org/april/agirstatool/core/Projects.java index 8d8a988..5939f36 100644 --- a/src/org/april/agirstatool/core/Projects.java +++ b/src/org/april/agirstatool/core/Projects.java @@ -140,5 +140,4 @@ public class Projects extends ArrayList // return result; } - }