parent
b8eecdd60f
commit
de605e2a55
13 changed files with 1201 additions and 311 deletions
@ -0,0 +1,166 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
import java.time.LocalDate; |
||||
import java.time.LocalDateTime; |
||||
import java.time.LocalTime; |
||||
import java.time.ZoneOffset; |
||||
|
||||
/** |
||||
* The Class Issue. |
||||
*/ |
||||
public class Issue |
||||
{ |
||||
private int id; |
||||
private Integer projectId; |
||||
private LocalDateTime createdOn; |
||||
private LocalDateTime closedOn; |
||||
|
||||
/** |
||||
* Instantiates a new issue. |
||||
* |
||||
* @param id |
||||
* the id |
||||
* @param createdOn |
||||
* the created on |
||||
*/ |
||||
public Issue(final int id, final Integer projectId, final LocalDateTime createdOn) |
||||
{ |
||||
this(id, projectId, createdOn, null); |
||||
} |
||||
|
||||
/** |
||||
* Instantiates a new issue. |
||||
* |
||||
* @param id |
||||
* the id |
||||
* @param createdOn |
||||
* the created on |
||||
* @param closedOn |
||||
* the closed on |
||||
*/ |
||||
public Issue(final int id, final Integer projectId, final LocalDateTime createdOn, final LocalDateTime closedOn) |
||||
{ |
||||
this.id = id; |
||||
this.projectId = projectId; |
||||
this.createdOn = createdOn; |
||||
this.closedOn = closedOn; |
||||
} |
||||
|
||||
/** |
||||
* Age in days. |
||||
* |
||||
* @return the int |
||||
*/ |
||||
public int getAgeInDays() |
||||
{ |
||||
int result; |
||||
|
||||
long start = this.createdOn.toEpochSecond(ZoneOffset.UTC); |
||||
long end; |
||||
if (this.closedOn == null) |
||||
{ |
||||
end = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); |
||||
} |
||||
else |
||||
{ |
||||
end = this.closedOn.toEpochSecond(ZoneOffset.UTC); |
||||
} |
||||
|
||||
result = (int) ((end - start) / (24 * 60 * 60)); |
||||
|
||||
//
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* Gets the age in days. |
||||
* |
||||
* @param date |
||||
* the date |
||||
* @return the age in days |
||||
*/ |
||||
public int getAgeInDays(final LocalDate date) |
||||
{ |
||||
int result; |
||||
|
||||
if (date == null) |
||||
{ |
||||
result = 0; |
||||
} |
||||
else if ((this.closedOn != null) && (this.closedOn.isBefore(LocalDateTime.of(date, LocalTime.MAX)))) |
||||
{ |
||||
long start = this.createdOn.toEpochSecond(ZoneOffset.UTC); |
||||
long end = this.closedOn.toEpochSecond(ZoneOffset.UTC); |
||||
|
||||
result = (int) ((end - start) / (24 * 60 * 60)); |
||||
} |
||||
else |
||||
{ |
||||
long start = this.createdOn.toEpochSecond(ZoneOffset.UTC); |
||||
long end = LocalDateTime.of(date, LocalTime.MAX).toEpochSecond(ZoneOffset.UTC); |
||||
|
||||
result = (int) ((end - start) / (24 * 60 * 60)); |
||||
} |
||||
|
||||
//
|
||||
return result; |
||||
} |
||||
|
||||
public LocalDateTime getClosedOn() |
||||
{ |
||||
return this.closedOn; |
||||
} |
||||
|
||||
public LocalDateTime getCreatedOn() |
||||
{ |
||||
return this.createdOn; |
||||
} |
||||
|
||||
public int getId() |
||||
{ |
||||
return this.id; |
||||
} |
||||
|
||||
public Integer getProjectId() |
||||
{ |
||||
return this.projectId; |
||||
} |
||||
|
||||
public void setClosedOn(final LocalDateTime closedOn) |
||||
{ |
||||
this.closedOn = closedOn; |
||||
} |
||||
|
||||
public void setCreatedOn(final LocalDateTime createdOn) |
||||
{ |
||||
this.createdOn = createdOn; |
||||
} |
||||
|
||||
public void setId(final int id) |
||||
{ |
||||
this.id = id; |
||||
} |
||||
|
||||
public void setProjectId(final Integer projectId) |
||||
{ |
||||
this.projectId = projectId; |
||||
} |
||||
} |
@ -0,0 +1,129 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
import java.time.LocalDate; |
||||
import java.util.ArrayList; |
||||
|
||||
/** |
||||
* The Class IssueList. |
||||
*/ |
||||
public class Issues extends ArrayList<Issue> |
||||
{ |
||||
private static final long serialVersionUID = -6241164269103539500L; |
||||
|
||||
/** |
||||
* Instantiates a new issue list. |
||||
*/ |
||||
public Issues() |
||||
{ |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* Instantiates a new issue list. |
||||
* |
||||
* @param capacity |
||||
* the capacity |
||||
*/ |
||||
public Issues(final int capacity) |
||||
{ |
||||
super(capacity); |
||||
} |
||||
|
||||
/** |
||||
* Compute stat. |
||||
* |
||||
* @param date |
||||
* the date |
||||
* @return the stat |
||||
*/ |
||||
public Stat computeStat() |
||||
{ |
||||
Stat result; |
||||
|
||||
result = new Stat(); |
||||
for (Issue issue : this) |
||||
{ |
||||
int age = issue.getAgeInDays(); |
||||
result.addValue(age); |
||||
} |
||||
|
||||
//
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* Compute stat. |
||||
* |
||||
* @param date |
||||
* the date |
||||
* @return the stat |
||||
*/ |
||||
public Stat computeStat(final LocalDate date) |
||||
{ |
||||
Stat result; |
||||
|
||||
result = new Stat(); |
||||
for (Issue issue : this) |
||||
{ |
||||
int age = issue.getAgeInDays(date); |
||||
result.addValue(age); |
||||
} |
||||
|
||||
//
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* Extract aticved at. |
||||
* |
||||
* @param date |
||||
* the date |
||||
* @return the issue list |
||||
*/ |
||||
public Issues extractActivedAt(final LocalDate date) |
||||
{ |
||||
Issues result; |
||||
|
||||
result = new Issues(); |
||||
|
||||
for (Issue issue : this) |
||||
{ |
||||
LocalDate createdOn = issue.getCreatedOn().toLocalDate(); |
||||
LocalDate closedOn; |
||||
if (issue.getClosedOn() == null) |
||||
{ |
||||
closedOn = null; |
||||
} |
||||
else |
||||
{ |
||||
closedOn = issue.getClosedOn().toLocalDate(); |
||||
} |
||||
|
||||
if ((!createdOn.isAfter(date)) && ((issue.getClosedOn() == null) || (!closedOn.isBefore(date)))) |
||||
{ |
||||
result.add(issue); |
||||
} |
||||
} |
||||
|
||||
//
|
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,131 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
/** |
||||
* The Class Stat. |
||||
*/ |
||||
public class Stat |
||||
{ |
||||
int count; |
||||
double total; |
||||
double min; |
||||
double max; |
||||
|
||||
/** |
||||
* Instantiates a new stat. |
||||
*/ |
||||
public Stat() |
||||
{ |
||||
this.count = 0; |
||||
this.total = 0; |
||||
this.min = 0; |
||||
this.max = 0; |
||||
} |
||||
|
||||
/** |
||||
* Adds the value. |
||||
* |
||||
* @param value |
||||
* the value |
||||
*/ |
||||
public void addValue(final double value) |
||||
{ |
||||
if (this.count == 0) |
||||
{ |
||||
this.total = value; |
||||
this.min = value; |
||||
this.max = value; |
||||
} |
||||
else |
||||
{ |
||||
//
|
||||
if (value < this.min) |
||||
{ |
||||
this.min = value; |
||||
} |
||||
|
||||
//
|
||||
this.total += value; |
||||
|
||||
//
|
||||
if (value > this.max) |
||||
{ |
||||
this.max = value; |
||||
} |
||||
} |
||||
|
||||
this.count += 1; |
||||
} |
||||
|
||||
public int getCount() |
||||
{ |
||||
return this.count; |
||||
} |
||||
|
||||
public double getMax() |
||||
{ |
||||
return this.max; |
||||
} |
||||
|
||||
/** |
||||
* Gets the mean. |
||||
* |
||||
* @return the mean |
||||
*/ |
||||
public double getMean() |
||||
{ |
||||
double result; |
||||
|
||||
result = this.total / this.count; |
||||
|
||||
//
|
||||
return result; |
||||
} |
||||
|
||||
public double getMin() |
||||
{ |
||||
return this.min; |
||||
} |
||||
|
||||
public double getTotal() |
||||
{ |
||||
return this.total; |
||||
} |
||||
|
||||
public void setCount(final int count) |
||||
{ |
||||
this.count = count; |
||||
} |
||||
|
||||
public void setMax(final double max) |
||||
{ |
||||
this.max = max; |
||||
} |
||||
|
||||
public void setMin(final double min) |
||||
{ |
||||
this.min = min; |
||||
} |
||||
|
||||
public void setTotal(final double total) |
||||
{ |
||||
this.total = total; |
||||
} |
||||
} |