Improved missing command message (#3415). Improved code and typography.

This commit is contained in:
Christian P. MOMON 2019-05-02 18:46:18 +02:00
parent d02e12e1da
commit 90c739ed07
13 changed files with 177 additions and 61 deletions

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2018-2019 Christian Pierre MOMON <cmomon@april.org>
*
* 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)
{

View File

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

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2018-2019 Christian Pierre MOMON <cmomon@april.org>
*
* 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<String> participants = bot.getReview().getParticipants();
Collection<String> currentParticipants = topic.getParticipants();
StringSet participants = bot.getReview().getParticipants();
if (participants.isEmpty())
{
participants.add(bot.getReview().getOwner());
}
StringSet currentParticipants = topic.getParticipants();
Collection<String> 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
{

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2018-2019 Christian Pierre MOMON <cmomon@april.org>
*
* 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
{

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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<String> getParticipants()
public StringSet getParticipants()
{
final Set<String> 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;
}
}

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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<String> getParticipants()
public StringSet getParticipants()
{
Set<String> result;
StringSet result;
result = this.messages.keySet();
result = new StringSet(this.messages.keySet());
//
return result;

View File

@ -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<String> getParticipants()
public StringSet getParticipants()
{
Collection<String> result;
StringSet result;
result = new HashSet<>();
result = new StringSet();
for (final Topic topic : this.individualTopics)
{

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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()));
//

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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<String> getParticipants();
public abstract StringSet getParticipants();
/**
* Gets the title.

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
*
* This file is part of (April) Hebdobot.
*
@ -185,6 +185,10 @@ public class ReviewDataComparator implements Comparator<ReviewData>
case USERCOUNT:
result = compare(getUserCount(alpha), getUserCount(bravo));
if (result == 0)
{
result = compare(getDate(alpha), getDate(bravo));
}
break;
case DURATION:

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
*
* This file is part of (April) Hebdobot.
*
@ -42,6 +42,28 @@ public class ReviewDatas extends ArrayList<ReviewData>
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<ReviewData>
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<ReviewData>
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.
*/

View File

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

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2018-2019 Christian Pierre MOMON <cmomon@april.org>
*
* 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"));
}
/**