Prepared duration issue chart.

This commit is contained in:
Christian P. MOMON 2020-01-30 03:07:52 +01:00
parent 932ab594af
commit 5060ce34ad
7 changed files with 327 additions and 11 deletions

View file

@ -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));

View file

@ -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.
*

View file

@ -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.
*

View file

@ -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;
}

View file

@ -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<Issue>
{
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;
}
}

View file

@ -142,4 +142,68 @@ public class Issues extends ArrayList<Issue>
//
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;
}
}

View file

@ -140,5 +140,4 @@ public class Projects extends ArrayList<Project>
//
return result;
}
}