Improved statistics message display (#2910).
This commit is contained in:
parent
9a18bea228
commit
7651c66c54
@ -58,6 +58,7 @@ import org.quartz.SchedulerException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.strings.StringList;
|
||||
import fr.devinsy.strings.StringsUtils;
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
@ -365,6 +366,52 @@ public class Hebdobot extends PircBot
|
||||
String date = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
|
||||
String textReview = this.review.toString();
|
||||
|
||||
// Display statistics. This feature has to not break
|
||||
// Hebdobot.
|
||||
|
||||
String newMaxUserCountReport;
|
||||
String userCountReport;
|
||||
String durationReport;
|
||||
try
|
||||
{
|
||||
File reviewDataFile = new File(this.reviewDirectory, "reviewstats.csv");
|
||||
if (reviewDataFile.exists())
|
||||
{
|
||||
ReviewDatas datas = ReviewDatasFile.load(reviewDataFile);
|
||||
datas.clean();
|
||||
|
||||
newMaxUserCountReport = ReviewStatsReporter.reportNewMaxUserCount(datas, this.review.getParticipants().size());
|
||||
ReviewData currentReview = new ReviewData(LocalDateTime.now(), this.review.getParticipants().size(),
|
||||
(int) this.review.getDurationInMinutes());
|
||||
datas.add(currentReview);
|
||||
userCountReport = ReviewStatsReporter.reportUserCount(datas, currentReview.getUserCount());
|
||||
durationReport = ReviewStatsReporter.reportDuration(datas, currentReview.getDuration());
|
||||
|
||||
if (this.review.getParticipants().size() > 1)
|
||||
{
|
||||
ReviewDatasFile.append(reviewDataFile, currentReview);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Statistic file not found [{}]", reviewDataFile.getAbsolutePath());
|
||||
sendMessage("% Fichier de statistiques absent.");
|
||||
newMaxUserCountReport = null;
|
||||
userCountReport = null;
|
||||
durationReport = null;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.warn("Exception during statistics work.", exception);
|
||||
newMaxUserCountReport = null;
|
||||
userCountReport = null;
|
||||
durationReport = null;
|
||||
}
|
||||
|
||||
textReview = new StringList(textReview).appendln(newMaxUserCountReport, "\n", userCountReport, "\n", durationReport).toString();
|
||||
|
||||
//
|
||||
if (this.pastebinSettings.isValid())
|
||||
{
|
||||
logger.info("Pastebin the review.");
|
||||
@ -382,6 +429,7 @@ public class Hebdobot extends PircBot
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
logger.info("Write review file.");
|
||||
File reviewFile = new File(this.reviewDirectory, date + StringUtils.defaultString(this.reviewFileSuffix, DEFAULT_SUFFIX));
|
||||
if (reviewFile.exists())
|
||||
@ -402,7 +450,7 @@ public class Hebdobot extends PircBot
|
||||
}
|
||||
catch (final Exception exception)
|
||||
{
|
||||
logger.error("Error during file generation", exception);
|
||||
logger.error("Error during file writing", exception);
|
||||
}
|
||||
|
||||
sendMessage("% Durée de la revue : " + this.review.getDurationInMinutes() + " minutes");
|
||||
@ -417,40 +465,23 @@ public class Hebdobot extends PircBot
|
||||
String participants = StringUtils.join(this.review.getParticipants(), " ");
|
||||
sendMessage("% " + participants + ", pensez à noter votre bénévalo : http://www.april.org/my?action=benevalo");
|
||||
|
||||
// Display statistics. This feature has to not break
|
||||
// Hebdobot.
|
||||
try
|
||||
// Display statistics.
|
||||
if (newMaxUserCountReport != null)
|
||||
{
|
||||
File reviewDataFile = new File(this.reviewDirectory, "reviewstats.csv");
|
||||
if (reviewDataFile.exists())
|
||||
{
|
||||
ReviewDatas datas = ReviewDatasFile.load(reviewDataFile);
|
||||
datas.clean();
|
||||
|
||||
sendMessage("% " + ReviewStatsReporter.reportNewMaxUserCount(datas, this.review.getParticipants().size()));
|
||||
ReviewData currentReview = new ReviewData(LocalDateTime.now(), this.review.getParticipants().size(),
|
||||
(int) this.review.getDurationInMinutes());
|
||||
datas.add(currentReview);
|
||||
sendMessage(this.review.getOwner(), "% " + ReviewStatsReporter.reportUserCount(datas, currentReview.getUserCount()));
|
||||
sendMessage(this.review.getOwner(), "% " + ReviewStatsReporter.reportDuration(datas, currentReview.getDuration()));
|
||||
|
||||
if (this.review.getParticipants().size() > 1)
|
||||
{
|
||||
ReviewDatasFile.append(reviewDataFile, currentReview);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Statistic file not found [{}]", reviewDataFile.getAbsolutePath());
|
||||
sendMessage("% Fichier de statistiques absent.");
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.warn("Exception during statistics work.", exception);
|
||||
sendMessage("% Impossible d'afficher des statistiques.");
|
||||
sendMessage("% " + newMaxUserCountReport);
|
||||
}
|
||||
|
||||
if (userCountReport != null)
|
||||
{
|
||||
sendMessage(this.review.getOwner(), userCountReport);
|
||||
}
|
||||
|
||||
if (durationReport != null)
|
||||
{
|
||||
sendMessage(this.review.getOwner(), durationReport);
|
||||
}
|
||||
|
||||
// Finalize review.
|
||||
sendMessage("% Fin de la revue hebdomadaire");
|
||||
sendMessage(this.review.getOwner(), "Revue finie.");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user