Improved !oops command. Improved stats.
This commit is contained in:
parent
b5fd23533f
commit
cd319dbacc
@ -43,7 +43,7 @@ public class CancelPreviousInputHook extends Hook
|
||||
|
||||
if (StringsUtils.containsAnyIgnoreCase(message, "!cancelprevious", "!oops", "!oups"))
|
||||
{
|
||||
logger.info("!cancelprevious/!oups caught.");
|
||||
logger.info("!cancelprevious/!oops caught.");
|
||||
|
||||
// Missing.
|
||||
if (bot.getReview() == null)
|
||||
@ -62,11 +62,11 @@ public class CancelPreviousInputHook extends Hook
|
||||
String previousMessage = topic.cancelPreviousMessage(sender);
|
||||
if (previousMessage == null)
|
||||
{
|
||||
bot.sendMessage("Vous n'avez pas d'entrée en cours.");
|
||||
bot.sendMessage(sender + ", vous n'avez pas d'entrée en cours.");
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.sendMessage(sender + ", suppressiond de votre dernière entrée : " + previousMessage);
|
||||
bot.sendMessage(sender + ", suppressiond de votre précédente entrée : " + previousMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,12 +159,12 @@ public class FinishReviewHook extends Hook
|
||||
}
|
||||
|
||||
// Send conclusion message in channel.
|
||||
bot.sendMessage("% " + ReviewStatsReporter.reportReviewCount(datas));
|
||||
bot.sendMessage("% " + ReviewStatsReporter.reportCurrentReviewCount(datas));
|
||||
bot.sendMessage("% Compte-rendu de la revue : " + pastebinUrl);
|
||||
bot.sendMessage("% Durée de la revue : " + bot.getReview().getDurationInMinutes() + " minutes");
|
||||
bot.sendMessage("% Nombre de personnes participantes : " + bot.getReview().getParticipants().size());
|
||||
|
||||
bot.sendMessage("% " + ReviewStatsReporter.reportNewUserCountRecord(datas));
|
||||
bot.sendMessage("% " + ReviewStatsReporter.reportCheckUserCountRecord(datas));
|
||||
bot.sendMessage(bot.getReview().getOwner(), ReviewStatsReporter.reportUserCount(datas, bot.getReview().getParticipants().size()));
|
||||
bot.sendMessage(bot.getReview().getOwner(), ReviewStatsReporter.reportDuration(datas, bot.getReview().getDurationInMinutes()));
|
||||
|
||||
|
@ -56,6 +56,7 @@ public class StatsHook extends Hook
|
||||
{
|
||||
ReviewDatas datas = ReviewDatasFile.load(reviewDataFile);
|
||||
datas.clean();
|
||||
bot.sendMessage("% " + ReviewStatsReporter.reportReviewCount(datas));
|
||||
bot.sendMessage("% " + ReviewStatsReporter.reportUserCountBoard(datas));
|
||||
bot.sendMessage("% " + ReviewStatsReporter.reportDurationBoard(datas));
|
||||
}
|
||||
|
@ -343,12 +343,12 @@ public class ReviewReporter
|
||||
addEmpty(buffer);
|
||||
addCenter(buffer, "Statistiques");
|
||||
addEmpty(buffer);
|
||||
addChunk(buffer, ReviewStatsReporter.reportReviewCount(datas));
|
||||
addChunk(buffer, ReviewStatsReporter.reportCurrentReviewCount(datas));
|
||||
addChunk(buffer, "Horaire de début de la revue : " + review.getFormattedStartTime());
|
||||
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.reportCheckUserCountRecord(datas));
|
||||
addChunk(buffer, ReviewStatsReporter.reportUserCount(datas, review.getParticipants().size()));
|
||||
addChunk(buffer, ReviewStatsReporter.reportDuration(datas, review.getDurationInMinutes()));
|
||||
|
||||
|
@ -106,6 +106,34 @@ public class ReviewDatas extends ArrayList<ReviewData>
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the averatge user count.
|
||||
*
|
||||
* @return the averatge user count
|
||||
*/
|
||||
public double getAveratgeUserCount()
|
||||
{
|
||||
double result;
|
||||
|
||||
if (isEmpty())
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
for (ReviewData data : this)
|
||||
{
|
||||
result += data.getUserCount();
|
||||
}
|
||||
|
||||
result = result / size();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the by year.
|
||||
*
|
||||
@ -298,32 +326,60 @@ public class ReviewDatas extends ArrayList<ReviewData>
|
||||
/**
|
||||
* Reverse.
|
||||
*/
|
||||
public void reverse()
|
||||
public ReviewDatas reverse()
|
||||
{
|
||||
ReviewDatas result;
|
||||
|
||||
Collections.reverse(this);
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort by date.
|
||||
*/
|
||||
public void sortByDate()
|
||||
public ReviewDatas sortByDate()
|
||||
{
|
||||
ReviewDatas result;
|
||||
|
||||
Collections.sort(this, new ReviewDataComparator(Sorting.DATE));
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort by duration.
|
||||
*/
|
||||
public void sortByDuration()
|
||||
public ReviewDatas sortByDuration()
|
||||
{
|
||||
ReviewDatas result;
|
||||
|
||||
Collections.sort(this, new ReviewDataComparator(Sorting.DURATION));
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort by user count.
|
||||
*/
|
||||
public void sortByUserCount()
|
||||
public ReviewDatas sortByUserCount()
|
||||
{
|
||||
ReviewDatas result;
|
||||
|
||||
Collections.sort(this, new ReviewDataComparator(Sorting.USERCOUNT));
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -108,6 +108,82 @@ public class ReviewStatsReporter
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report new max. The current user count is found in last review by date.
|
||||
*
|
||||
* @param datas
|
||||
* the datas
|
||||
* @return the string
|
||||
*/
|
||||
public static String reportCheckUserCountRecord(final ReviewDatas datas)
|
||||
{
|
||||
String result;
|
||||
|
||||
if ((datas == null) || (datas.isEmpty()) || (datas.size() == 1))
|
||||
{
|
||||
result = "Absence de statistique sur la participation.";
|
||||
}
|
||||
else
|
||||
{
|
||||
ReviewDatas reviews = new ReviewDatas(datas);
|
||||
reviews.sortByDate();
|
||||
ReviewData lastReview = datas.getLastByIndex();
|
||||
reviews.removeLast();
|
||||
reviews.sortByUserCount();
|
||||
ReviewData recordReview = reviews.getLastByIndex();
|
||||
|
||||
if (lastReview.getUserCount() < recordReview.getUserCount())
|
||||
{
|
||||
double averageUserCount = reviews.getAveratgeUserCount();
|
||||
result = String.format("La moyenne de participation est de %02.1f personnes.", averageUserCount);
|
||||
}
|
||||
else if (lastReview.getUserCount() == recordReview.getUserCount())
|
||||
{
|
||||
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 de %d personnes était le %s.",
|
||||
recordReview.getUserCount(), lastRecordDate);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report review count.
|
||||
*
|
||||
* @param datas
|
||||
* the datas
|
||||
* @return the string
|
||||
*/
|
||||
public static String reportCurrentReviewCount(final ReviewDatas datas)
|
||||
{
|
||||
String result;
|
||||
|
||||
if ((datas == null) || (datas.isEmpty()))
|
||||
{
|
||||
result = "Pas de statistique sur le nombre de revues.";
|
||||
}
|
||||
else
|
||||
{
|
||||
long currentYear = LocalDateTime.now().getYear();
|
||||
long reviewYearCount = datas.countByYear(currentYear);
|
||||
|
||||
result = String.format("C'était la %d%s revue hebdomadaire de l'April, la %d%s de l'année %d.", datas.size(), numberSuffix(datas.size()),
|
||||
reviewYearCount, numberSuffix(reviewYearCount), currentYear);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report duration.
|
||||
*
|
||||
@ -169,55 +245,6 @@ public class ReviewStatsReporter
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report new max. The current user count is found in last review by date.
|
||||
*
|
||||
* @param datas
|
||||
* the datas
|
||||
* @return the string
|
||||
*/
|
||||
public static String reportNewUserCountRecord(final ReviewDatas datas)
|
||||
{
|
||||
String result;
|
||||
|
||||
if ((datas == null) || (datas.isEmpty()) || (datas.size() == 1))
|
||||
{
|
||||
result = "Absence de statistique sur la participation.";
|
||||
}
|
||||
else
|
||||
{
|
||||
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é.";
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report review count.
|
||||
*
|
||||
@ -235,11 +262,11 @@ public class ReviewStatsReporter
|
||||
}
|
||||
else
|
||||
{
|
||||
long currentYear = LocalDateTime.now().getYear();
|
||||
long reviewYearCount = datas.countByYear(currentYear);
|
||||
ReviewData firstReview = datas.sortByDate().get(0);
|
||||
long reviewCount = datas.size();
|
||||
String firstDate = firstReview.getDate().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy", Locale.FRENCH));
|
||||
|
||||
result = String.format("C'était la %d%s revue hebdomadaire de l'April, la %d%s de l'année %d.", datas.size(), numberSuffix(datas.size()),
|
||||
reviewYearCount, numberSuffix(reviewYearCount), currentYear);
|
||||
result = String.format("Il y a eu %d revues. La première date du %s.", reviewCount, firstDate);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -72,7 +72,7 @@ public class ReviewStatsReporterTest
|
||||
logger.debug("File loaded.");
|
||||
ReviewData currentReview = new ReviewData(LocalDateTime.now(), 12, 17L);
|
||||
datas.add(currentReview);
|
||||
String report = ReviewStatsReporter.reportNewUserCountRecord(datas);
|
||||
String report = ReviewStatsReporter.reportCheckUserCountRecord(datas);
|
||||
logger.debug("Report=" + report);
|
||||
Assert.assertTrue(StringUtils.startsWith(report, "Le dernier record de"));
|
||||
}
|
||||
@ -92,7 +92,7 @@ public class ReviewStatsReporterTest
|
||||
logger.debug("File loaded.");
|
||||
ReviewData currentReview = new ReviewData(LocalDateTime.now(), 42000, 17L);
|
||||
datas.add(currentReview);
|
||||
String report = ReviewStatsReporter.reportNewUserCountRecord(datas);
|
||||
String report = ReviewStatsReporter.reportCheckUserCountRecord(datas);
|
||||
logger.debug("Report=" + report);
|
||||
Assert.assertTrue(StringUtils.startsWith(report, "*\\o/* Nouveau record de participation"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user