Improved stats command.

This commit is contained in:
Christian P. MOMON 2021-04-14 21:51:03 +02:00
parent cd319dbacc
commit caba69fc75
3 changed files with 146 additions and 0 deletions

View File

@ -57,6 +57,8 @@ public class StatsHook extends Hook
ReviewDatas datas = ReviewDatasFile.load(reviewDataFile);
datas.clean();
bot.sendMessage("% " + ReviewStatsReporter.reportReviewCount(datas));
bot.sendMessage("% " + ReviewStatsReporter.reportReviewUserCount(datas));
bot.sendMessage("% " + ReviewStatsReporter.reportReviewDuration(datas));
bot.sendMessage("% " + ReviewStatsReporter.reportUserCountBoard(datas));
bot.sendMessage("% " + ReviewStatsReporter.reportDurationBoard(datas));
}

View File

@ -106,6 +106,42 @@ public class ReviewDatas extends ArrayList<ReviewData>
return result;
}
/**
* Gets the averatge duration.
*
* @return the averatge duration
*/
public double getAveratgeDuration()
{
double result;
if (isEmpty())
{
result = 0;
}
else
{
result = 0;
int count = 0;
for (ReviewData data : this)
{
if (data.getDuration() != null)
{
count += 1;
result += data.getUserCount();
}
}
if (count != 0)
{
result = result / count;
}
}
//
return result;
}
/**
* Gets the averatge user count.
*
@ -211,6 +247,35 @@ public class ReviewDatas extends ArrayList<ReviewData>
return result;
}
/**
* Gets the max duration.
*
* @return the max duration
*/
public long getMaxDuration()
{
long result;
if (isEmpty())
{
result = 0;
}
else
{
result = Long.MIN_VALUE;
for (ReviewData data : this)
{
if ((data.getDuration() != null) && (data.getUserCount() > result))
{
result = data.getDuration();
}
}
}
//
return result;
}
/**
* Gets the max user count.
*
@ -240,6 +305,35 @@ public class ReviewDatas extends ArrayList<ReviewData>
return result;
}
/**
* Gets the min duration.
*
* @return the min duration
*/
public long getMinDuration()
{
long result;
if (isEmpty())
{
result = 0;
}
else
{
result = Long.MAX_VALUE;
for (ReviewData data : this)
{
if ((data.getDuration() != null) && (data.getDuration() < result))
{
result = data.getDuration();
}
}
}
//
return result;
}
/**
* Gets the min user count.
*

View File

@ -273,6 +273,56 @@ public class ReviewStatsReporter
return result;
}
/**
* Report review duration.
*
* @param datas
* the datas
* @return the string
*/
public static String reportReviewDuration(final ReviewDatas datas)
{
String result;
if ((datas == null) || (datas.isEmpty()))
{
result = "Pas de statistique sur la durée des revues.";
}
else
{
result = String.format("Statistiques sur la durée des revues : min.=%d min, moy.=%.1f min, max.=%d min", datas.getMinDuration(),
datas.getAveratgeDuration(), datas.getMaxDuration());
}
//
return result;
}
/**
* Report review user count.
*
* @param datas
* the datas
* @return the string
*/
public static String reportReviewUserCount(final ReviewDatas datas)
{
String result;
if ((datas == null) || (datas.isEmpty()))
{
result = "Absence de statistique sur les participations.";
}
else
{
result = String.format("Statistiques sur la participation des revues : min.=%d, moy.=%.1f, max.=%d)", datas.getMinUserCount(),
datas.getAveratgeUserCount(), datas.getMaxUserCount());
}
//
return result;
}
/**
* Report user count.
*