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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import fr.devinsy.strings.StringList;
|
||||||
import fr.devinsy.strings.StringsUtils;
|
import fr.devinsy.strings.StringsUtils;
|
||||||
import twitter4j.TwitterException;
|
import twitter4j.TwitterException;
|
||||||
|
|
||||||
|
@ -365,6 +366,52 @@ public class Hebdobot extends PircBot
|
||||||
String date = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
|
String date = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
|
||||||
String textReview = this.review.toString();
|
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())
|
if (this.pastebinSettings.isValid())
|
||||||
{
|
{
|
||||||
logger.info("Pastebin the review.");
|
logger.info("Pastebin the review.");
|
||||||
|
@ -382,6 +429,7 @@ public class Hebdobot extends PircBot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
logger.info("Write review file.");
|
logger.info("Write review file.");
|
||||||
File reviewFile = new File(this.reviewDirectory, date + StringUtils.defaultString(this.reviewFileSuffix, DEFAULT_SUFFIX));
|
File reviewFile = new File(this.reviewDirectory, date + StringUtils.defaultString(this.reviewFileSuffix, DEFAULT_SUFFIX));
|
||||||
if (reviewFile.exists())
|
if (reviewFile.exists())
|
||||||
|
@ -402,7 +450,7 @@ public class Hebdobot extends PircBot
|
||||||
}
|
}
|
||||||
catch (final Exception exception)
|
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");
|
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(), " ");
|
String participants = StringUtils.join(this.review.getParticipants(), " ");
|
||||||
sendMessage("% " + participants + ", pensez à noter votre bénévalo : http://www.april.org/my?action=benevalo");
|
sendMessage("% " + participants + ", pensez à noter votre bénévalo : http://www.april.org/my?action=benevalo");
|
||||||
|
|
||||||
// Display statistics. This feature has to not break
|
// Display statistics.
|
||||||
// Hebdobot.
|
if (newMaxUserCountReport != null)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
File reviewDataFile = new File(this.reviewDirectory, "reviewstats.csv");
|
sendMessage("% " + newMaxUserCountReport);
|
||||||
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.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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("% Fin de la revue hebdomadaire");
|
||||||
sendMessage(this.review.getOwner(), "Revue finie.");
|
sendMessage(this.review.getOwner(), "Revue finie.");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue