From caba69fc75eda85ed2194bff8a37c585dd9e6aac Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 14 Apr 2021 21:51:03 +0200 Subject: [PATCH] Improved stats command. --- .../april/hebdobot/bot/hooks/StatsHook.java | 2 + .../april/hebdobot/bot/stats/ReviewDatas.java | 94 +++++++++++++++++++ .../bot/stats/ReviewStatsReporter.java | 50 ++++++++++ 3 files changed, 146 insertions(+) diff --git a/src/org/april/hebdobot/bot/hooks/StatsHook.java b/src/org/april/hebdobot/bot/hooks/StatsHook.java index c473c8f..2c9f14c 100644 --- a/src/org/april/hebdobot/bot/hooks/StatsHook.java +++ b/src/org/april/hebdobot/bot/hooks/StatsHook.java @@ -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)); } diff --git a/src/org/april/hebdobot/bot/stats/ReviewDatas.java b/src/org/april/hebdobot/bot/stats/ReviewDatas.java index e2f80d4..a1d28ff 100644 --- a/src/org/april/hebdobot/bot/stats/ReviewDatas.java +++ b/src/org/april/hebdobot/bot/stats/ReviewDatas.java @@ -106,6 +106,42 @@ public class ReviewDatas extends ArrayList 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 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 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. * diff --git a/src/org/april/hebdobot/bot/stats/ReviewStatsReporter.java b/src/org/april/hebdobot/bot/stats/ReviewStatsReporter.java index 7c71032..e3618db 100644 --- a/src/org/april/hebdobot/bot/stats/ReviewStatsReporter.java +++ b/src/org/april/hebdobot/bot/stats/ReviewStatsReporter.java @@ -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. *