diff --git a/src/org/april/hebdobot/bot/hooks/CurrentHook.java b/src/org/april/hebdobot/bot/hooks/CurrentHook.java index cb33b2b..c18f4ec 100644 --- a/src/org/april/hebdobot/bot/hooks/CurrentHook.java +++ b/src/org/april/hebdobot/bot/hooks/CurrentHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2019 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -56,7 +56,7 @@ public class CurrentHook extends Hook Topic current = bot.getReview().getCurrentTopic(); if (current == null) { - bot.sendMessage("% Pas de sujet en cours"); + bot.sendMessage("% Pas de sujet en cours."); } else if (current instanceof IndividualTopic) { diff --git a/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java b/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java index d401ca1..10cbfc0 100644 --- a/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java +++ b/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java @@ -163,7 +163,7 @@ public class FinishReviewHook extends Hook bot.sendMessage("% Durée de la revue : " + bot.getReview().getDurationInMinutes() + " minutes"); bot.sendMessage("% Nombre de personnes participantes : " + bot.getReview().getParticipants().size()); - bot.sendMessage("% " + ReviewStatsReporter.reportNewMaxUserCount(datas, bot.getReview().getParticipants().size())); + bot.sendMessage("% " + ReviewStatsReporter.reportNewUserCountRecord(datas)); bot.sendMessage(bot.getReview().getOwner(), ReviewStatsReporter.reportUserCount(datas, bot.getReview().getParticipants().size())); bot.sendMessage(bot.getReview().getOwner(), ReviewStatsReporter.reportDuration(datas, bot.getReview().getDurationInMinutes())); diff --git a/src/org/april/hebdobot/bot/hooks/MissingHook.java b/src/org/april/hebdobot/bot/hooks/MissingHook.java index d34e7fa..3db0154 100644 --- a/src/org/april/hebdobot/bot/hooks/MissingHook.java +++ b/src/org/april/hebdobot/bot/hooks/MissingHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2019 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -27,6 +27,8 @@ import org.april.hebdobot.bot.review.Topic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringSet; + /** * The Class MissingHook. */ @@ -57,17 +59,21 @@ public class MissingHook extends Hook Topic topic = bot.getReview().getCurrentTopic(); if (topic == null) { - bot.sendMessage("Aucun sujet traité"); + bot.sendMessage("Pas sujet en cours."); } else { - Collection participants = bot.getReview().getParticipants(); - Collection currentParticipants = topic.getParticipants(); + StringSet participants = bot.getReview().getParticipants(); + if (participants.isEmpty()) + { + participants.add(bot.getReview().getOwner()); + } + StringSet currentParticipants = topic.getParticipants(); Collection missing = CollectionUtils.subtract(participants, currentParticipants); if (missing.isEmpty()) { - bot.sendMessage("Tout le monde a parlé \\o/"); + bot.sendMessage("Tout le monde s'est exprimé sur le sujet courant \\o/"); } else { diff --git a/src/org/april/hebdobot/bot/hooks/StopReviewHook.java b/src/org/april/hebdobot/bot/hooks/StopReviewHook.java index 3dc055a..0d2f451 100644 --- a/src/org/april/hebdobot/bot/hooks/StopReviewHook.java +++ b/src/org/april/hebdobot/bot/hooks/StopReviewHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2019 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -46,7 +46,7 @@ public class StopReviewHook extends Hook // Stop. if (bot.getReview() == null) { - bot.sendMessage(sender + ", aucune revue en cours, abandon impossible."); + bot.sendMessage(sender + ", pas de revue en cours, abandon impossible."); } else { diff --git a/src/org/april/hebdobot/bot/review/CollectiveTopic.java b/src/org/april/hebdobot/bot/review/CollectiveTopic.java index 33a230c..63a85fb 100644 --- a/src/org/april/hebdobot/bot/review/CollectiveTopic.java +++ b/src/org/april/hebdobot/bot/review/CollectiveTopic.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2017-2018 Christian Pierre MOMON + * Copyright (C) 2017-2019 Christian Pierre MOMON * Copyright (C) 2011-2013 Nicolas Vinot * * This file is part of (April) Hebdobot. @@ -19,9 +19,9 @@ */ package org.april.hebdobot.bot.review; -import java.util.HashSet; import java.util.List; -import java.util.Set; + +import fr.devinsy.strings.StringSet; /** * The Class CollectiveTopic. @@ -66,13 +66,15 @@ public class CollectiveTopic extends Topic * @see org.april.hebdobot.review.Topic#getParticipants() */ @Override - public Set getParticipants() + public StringSet getParticipants() { - final Set participants = new HashSet<>(); + StringSet result = new StringSet(); for (final Message message : this.messages) { - participants.add(message.getAuthor()); + result.add(message.getAuthor()); } - return participants; + + // + return result; } } diff --git a/src/org/april/hebdobot/bot/review/IndividualTopic.java b/src/org/april/hebdobot/bot/review/IndividualTopic.java index 4309ba0..6e0a7e0 100644 --- a/src/org/april/hebdobot/bot/review/IndividualTopic.java +++ b/src/org/april/hebdobot/bot/review/IndividualTopic.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2017-2018 Christian Pierre MOMON + * Copyright (C) 2017-2019 Christian Pierre MOMON * Copyright (C) 2011-2013 Nicolas Vinot * * This file is part of (April) Hebdobot. @@ -21,7 +21,8 @@ package org.april.hebdobot.bot.review; import java.util.HashMap; import java.util.Map; -import java.util.Set; + +import fr.devinsy.strings.StringSet; /** * The Class IndividualTopic. @@ -78,11 +79,11 @@ public class IndividualTopic extends Topic * @see org.april.hebdobot.review.Topic#getParticipants() */ @Override - public Set getParticipants() + public StringSet getParticipants() { - Set result; + StringSet result; - result = this.messages.keySet(); + result = new StringSet(this.messages.keySet()); // return result; diff --git a/src/org/april/hebdobot/bot/review/Review.java b/src/org/april/hebdobot/bot/review/Review.java index 836f7ed..4f98345 100644 --- a/src/org/april/hebdobot/bot/review/Review.java +++ b/src/org/april/hebdobot/bot/review/Review.java @@ -22,8 +22,6 @@ package org.april.hebdobot.bot.review; import java.time.Duration; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.Collection; -import java.util.HashSet; import org.april.hebdobot.bot.UserAliases; @@ -265,11 +263,11 @@ public class Review * * @return the participants */ - public Collection getParticipants() + public StringSet getParticipants() { - Collection result; + StringSet result; - result = new HashSet<>(); + result = new StringSet(); for (final Topic topic : this.individualTopics) { diff --git a/src/org/april/hebdobot/bot/review/ReviewReporter.java b/src/org/april/hebdobot/bot/review/ReviewReporter.java index 5bc671d..8472883 100644 --- a/src/org/april/hebdobot/bot/review/ReviewReporter.java +++ b/src/org/april/hebdobot/bot/review/ReviewReporter.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2017-2018 Christian Pierre MOMON + * Copyright (C) 2017-2019 Christian Pierre MOMON * Copyright (C) 2011-2013 Nicolas Vinot * * This file is part of (April) Hebdobot. @@ -348,8 +348,8 @@ public class ReviewReporter addChunk(buffer, "Horaire de fin de la revue : " + review.getFormattedEndTime()); addChunk(buffer, "Durée de la revue : " + review.getDurationInMinutes() + " minutes"); addChunk(buffer, "Nombre de personnes participantes : " + review.getParticipants().size()); + addChunk(buffer, ReviewStatsReporter.reportNewUserCountRecord(datas)); addChunk(buffer, ReviewStatsReporter.reportUserCount(datas, review.getParticipants().size())); - addChunk(buffer, ReviewStatsReporter.reportNewMaxUserCount(datas, review.getParticipants().size())); addChunk(buffer, ReviewStatsReporter.reportDuration(datas, review.getDurationInMinutes())); // diff --git a/src/org/april/hebdobot/bot/review/Topic.java b/src/org/april/hebdobot/bot/review/Topic.java index 16a1c96..135c6d5 100644 --- a/src/org/april/hebdobot/bot/review/Topic.java +++ b/src/org/april/hebdobot/bot/review/Topic.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2017-2018 Christian Pierre MOMON + * Copyright (C) 2017-2019 Christian Pierre MOMON * Copyright (C) 2011-2013 Nicolas Vinot * * This file is part of (April) Hebdobot. @@ -19,7 +19,7 @@ */ package org.april.hebdobot.bot.review; -import java.util.Set; +import fr.devinsy.strings.StringSet; /** * The Class Topic. @@ -52,7 +52,7 @@ public abstract class Topic * * @return the participants */ - public abstract Set getParticipants(); + public abstract StringSet getParticipants(); /** * Gets the title. diff --git a/src/org/april/hebdobot/bot/stats/ReviewDataComparator.java b/src/org/april/hebdobot/bot/stats/ReviewDataComparator.java index 11e4b61..cf2a4c1 100644 --- a/src/org/april/hebdobot/bot/stats/ReviewDataComparator.java +++ b/src/org/april/hebdobot/bot/stats/ReviewDataComparator.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2017-2018 Christian Pierre MOMON + * Copyright (C) 2017-2019 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -185,6 +185,10 @@ public class ReviewDataComparator implements Comparator case USERCOUNT: result = compare(getUserCount(alpha), getUserCount(bravo)); + if (result == 0) + { + result = compare(getDate(alpha), getDate(bravo)); + } break; case DURATION: diff --git a/src/org/april/hebdobot/bot/stats/ReviewDatas.java b/src/org/april/hebdobot/bot/stats/ReviewDatas.java index 2e90644..1395f58 100644 --- a/src/org/april/hebdobot/bot/stats/ReviewDatas.java +++ b/src/org/april/hebdobot/bot/stats/ReviewDatas.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2017-2018 Christian Pierre MOMON + * Copyright (C) 2017-2019 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -42,6 +42,28 @@ public class ReviewDatas extends ArrayList super(); } + /** + * Instantiates a new review datas. + * + * @param initialCapacity + * the initial capacity + */ + public ReviewDatas(final int initialCapacity) + { + super(initialCapacity); + } + + /** + * Instantiates a new review datas. + * + * @param source + * the source + */ + public ReviewDatas(final ReviewDatas source) + { + super(source); + } + /** * Clean. * @@ -108,6 +130,28 @@ public class ReviewDatas extends ArrayList return result; } + /** + * Gets the last by index. + * + * @return the last by index + */ + public ReviewData getLastByIndex() + { + ReviewData result; + + if (isEmpty()) + { + result = null; + } + else + { + result = this.get(size() - 1); + } + + // + return result; + } + /** * Gets the last by max user count. * @@ -197,6 +241,58 @@ public class ReviewDatas extends ArrayList return result; } + /** + * Gets the previous last by index. + * + * @return the previous last by index + */ + public ReviewData getPreviousLastByIndex() + { + ReviewData result; + + if ((isEmpty()) || (size() == 1)) + { + result = null; + } + else + { + result = this.get(size() - 2); + } + + // + return result; + } + + /** + * Removes the first. + * + * @return the review datas + */ + public ReviewDatas removeFirst() + { + if (!isEmpty()) + { + remove(0); + } + + // + return this; + } + + /** + * Removes the last. + */ + public ReviewDatas removeLast() + { + if (!isEmpty()) + { + remove(size() - 1); + } + + // + return this; + } + /** * Reverse. */ diff --git a/src/org/april/hebdobot/bot/stats/ReviewStatsReporter.java b/src/org/april/hebdobot/bot/stats/ReviewStatsReporter.java index d831d7c..fcfa546 100644 --- a/src/org/april/hebdobot/bot/stats/ReviewStatsReporter.java +++ b/src/org/april/hebdobot/bot/stats/ReviewStatsReporter.java @@ -170,41 +170,48 @@ public class ReviewStatsReporter } /** - * Report new max. + * Report new max. The current user count is found in last review by date. * * @param datas * the datas - * @param currentUserCount - * the current user count * @return the string */ - public static String reportNewMaxUserCount(final ReviewDatas datas, final int currentUserCount) + public static String reportNewUserCountRecord(final ReviewDatas datas) { String result; - if ((datas == null) || (datas.isEmpty())) + if ((datas == null) || (datas.isEmpty()) || (datas.size() == 1)) { - result = "Pas de stats sur le nombre maximal de personnes participantes."; + result = "Absence de statistique sur la participation."; } else { - datas.sortByDate(); - ReviewData last = datas.getLastByMaxUserCount(); - if (currentUserCount == last.getUserCount()) + ReviewDatas reviews = new ReviewDatas(datas); + reviews.sortByDate(); + ReviewData lastReview = datas.getLastByIndex(); + reviews.removeLast(); + reviews.sortByUserCount(); + ReviewData recordReview = reviews.getLastByIndex(); + + if (lastReview.getUserCount() < recordReview.getUserCount()) + { + String lastRecordDate = recordReview.getDate().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy", Locale.FRENCH)); + result = String.format("Le dernier record de participation est de %d personnes le %s.", recordReview.getUserCount(), lastRecordDate); + } + else if (lastReview.getUserCount() == recordReview.getUserCount()) { result = "Record de participation égalé."; - } - else if (currentUserCount < last.getUserCount()) - { - result = "Pas de nouveau record de participation."; + String lastRecordDate = recordReview.getDate().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy", Locale.FRENCH)); + result = String.format("\\o/ Record de participation égalé \\o/ Le précédent record était de %d personnes le %s.", + recordReview.getUserCount(), lastRecordDate); } else { - result = "Nouveau record de personnes participantes !"; + String lastRecordDate = recordReview.getDate().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy", Locale.FRENCH)); + result = String.format( + "*\\o/* Nouveau record de participation : %d personnes ! *\\o/* Le précédent record était de %d personnes le %s.", + lastReview.getUserCount(), recordReview.getUserCount(), lastRecordDate); } - - String lastRecordDate = last.getDate().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy", Locale.FRENCH)); - result = String.format("%s Le dernier record de %d personnes participantes remonte au %s.", result, last.getUserCount(), lastRecordDate); } // @@ -254,7 +261,7 @@ public class ReviewStatsReporter if ((datas == null) || (datas.isEmpty())) { - result = "Pas de statistique sur le nombre de personnes participantes."; + result = "Absence de statistique sur la participation."; } else { @@ -314,13 +321,13 @@ public class ReviewStatsReporter if ((datas == null) || (datas.isEmpty())) { - result = "Indisponibilité de statistiques sur la participation à la revue."; + result = "Absence de statistique sur la participation à la revue."; } else { ReviewData recordReview = datas.getLastByMaxUserCount(); String recordDate = recordReview.getDate().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy", Locale.FRENCH)); - result = String.format("Le record de participation est de %d personnes et remonte au %s.", recordReview.getUserCount(), recordDate); + result = String.format("Le record de participation est de %d personnes le %s.", recordReview.getUserCount(), recordDate); } // diff --git a/test/org/april/hebdobot/reviewstats/ReviewStatsTest.java b/test/org/april/hebdobot/reviewstats/ReviewStatsTest.java index 9a0e6ba..6cf8749 100644 --- a/test/org/april/hebdobot/reviewstats/ReviewStatsTest.java +++ b/test/org/april/hebdobot/reviewstats/ReviewStatsTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2019 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -86,16 +86,17 @@ public class ReviewStatsTest * the exception */ @Test - public void testReportNewMaxUserCount01() throws Exception + public void testReportNewUserCountRecord01() throws Exception { System.out.println("================"); ReviewDatas datas = ReviewDatasFile.load(new File("test/org/april/hebdobot/reviewstats/reviewstats.csv")); datas.clean(); logger.debug("File loaded."); ReviewData currentReview = new ReviewData(LocalDateTime.now(), 12, 17L); - String report = ReviewStatsReporter.reportNewMaxUserCount(datas, currentReview.getUserCount()); + datas.add(currentReview); + String report = ReviewStatsReporter.reportNewUserCountRecord(datas); logger.debug("Report=" + report); - Assert.assertTrue(StringUtils.startsWith(report, "Pas de nouveau record")); + Assert.assertTrue(StringUtils.startsWith(report, "Le dernier record de")); } /** @@ -105,16 +106,17 @@ public class ReviewStatsTest * the exception */ @Test - public void testReportNewMaxUserCount02() throws Exception + public void testReportNewUserCountRecord02() throws Exception { System.out.println("================"); ReviewDatas datas = ReviewDatasFile.load(new File("test/org/april/hebdobot/reviewstats/reviewstats.csv")); datas.clean(); logger.debug("File loaded."); ReviewData currentReview = new ReviewData(LocalDateTime.now(), 42000, 17L); - String report = ReviewStatsReporter.reportNewMaxUserCount(datas, currentReview.getUserCount()); + datas.add(currentReview); + String report = ReviewStatsReporter.reportNewUserCountRecord(datas); logger.debug("Report=" + report); - Assert.assertTrue(StringUtils.startsWith(report, "Nouveau record de personnes participantes !")); + Assert.assertTrue(StringUtils.startsWith(report, "*\\o/* Nouveau record de participation")); } /**