From c2471e50c1c508de137ee6d729ba8ea8fea30ceb Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 22 Jan 2018 10:49:07 +0100 Subject: [PATCH] Added stats at the review end (agir #2892). --- src/org/april/hebdobot/model/Hebdobot.java | 3 + .../april/hebdobot/model/review/Review.java | 114 +++++++++++++++++- 2 files changed, 115 insertions(+), 2 deletions(-) diff --git a/src/org/april/hebdobot/model/Hebdobot.java b/src/org/april/hebdobot/model/Hebdobot.java index 4895fe2..5030f86 100644 --- a/src/org/april/hebdobot/model/Hebdobot.java +++ b/src/org/april/hebdobot/model/Hebdobot.java @@ -352,6 +352,9 @@ public class Hebdobot extends PircBot } } + sendMessage("% Durée de la revue : " + this.review.getDurationInMinutes() + " minutes"); + sendMessage("% Nombre de participants : " + this.review.getParticipants().size()); + sendMessage("% " + this.review.getOwner() + ", ne pas oublier d'ajouter le compte-rendu de la revue sur https://agir.april.org/issues/135"); String participants = StringUtils.join(this.review.getParticipants(), " "); diff --git a/src/org/april/hebdobot/model/review/Review.java b/src/org/april/hebdobot/model/review/Review.java index a97ec24..5c67612 100644 --- a/src/org/april/hebdobot/model/review/Review.java +++ b/src/org/april/hebdobot/model/review/Review.java @@ -19,6 +19,7 @@ */ package org.april.hebdobot.model.review; +import java.time.Duration; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Collection; @@ -46,6 +47,8 @@ public class Review private final MessageList messages; private final String owner; private final UserAliases aliases; + private LocalDateTime startTime; + private LocalDateTime endTime; /** * Instantiates a new review. @@ -64,6 +67,9 @@ public class Review this.owner = owner; this.aliases = aliases; + + this.startTime = LocalDateTime.now(); + this.endTime = null; } /** @@ -126,6 +132,85 @@ public class Review return this.currentTopic; } + public long getDuration() + { + long result; + + if (this.endTime == null) + { + result = Duration.between(this.startTime, LocalDateTime.now()).getSeconds(); + } + else + { + result = Duration.between(this.startTime, this.endTime).getSeconds(); + } + + // + return result; + } + + /** + * Gets the duration. + * + * @return the duration + */ + public long getDurationInMinutes() + { + long result; + + result = getDuration() / 60; + + // + return result; + } + + /** + * Gets the end time. + * + * @return the end time + */ + public LocalDateTime getEndTime() + { + return this.endTime; + } + + /** + * Gets the formatted end time. + * + * @return the formatted end time + */ + public String getFormattedEndTime() + { + String result; + + if (this.endTime == null) + { + result = "??h??"; + } + else + { + result = this.endTime.format(DateTimeFormatter.ofPattern("kk'h'mm")); + } + + // + return result; + } + + /** + * Gets the formatted start time. + * + * @return the formatted start time + */ + public String getFormattedStartTime() + { + String result; + + result = this.startTime.format(DateTimeFormatter.ofPattern("kk'h'mm")); + + // + return result; + } + /** * Gets the owner. * @@ -161,6 +246,16 @@ public class Review return result; } + /** + * Gets the start time. + * + * @return the start time + */ + public LocalDateTime getStartTime() + { + return this.startTime; + } + /** * Checks if is empty. * @@ -208,16 +303,17 @@ public class Review { String result; + // StringBuffer buffer = new StringBuffer(); addLine(buffer, '='); addCenter(buffer, "Revue de la semaine en cours"); addEmpty(buffer); - addCenter(buffer, - StringUtils.capitalize(LocalDateTime.now().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy").withLocale(Locale.FRENCH)))); + addCenter(buffer, StringUtils.capitalize(LocalDateTime.now().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy", Locale.FRENCH)))); addLine(buffer, '='); addEmpty(buffer); addEmpty(buffer); + // addLine(buffer, '='); addEmpty(buffer); addCenter(buffer, "Participants", '-'); @@ -226,6 +322,7 @@ public class Review addChunk(buffer, "* " + this.aliases.getRealName(participant) + "\n"); } + // if (!this.individualTopics.isEmpty()) { for (final String participant : this.participants) @@ -250,6 +347,7 @@ public class Review } } + // if (!this.collectiveTopics.isEmpty()) { for (final CollectiveTopic topic : this.collectiveTopics) @@ -266,6 +364,7 @@ public class Review } } + // addEmpty(buffer); addCenter(buffer, "Log IRC brut"); addEmpty(buffer); @@ -274,6 +373,17 @@ public class Review addChunk(buffer, "* " + message.getAuthor() + " : " + message.getContent() + "\n"); } + // + this.endTime = LocalDateTime.now(); + addEmpty(buffer); + addCenter(buffer, "Statistiques"); + addEmpty(buffer); + addChunk(buffer, "Horaire de début de la revue : " + getFormattedStartTime() + "\n"); + addChunk(buffer, "Horaire de fin de la revue : " + getFormattedEndTime() + "\n"); + addChunk(buffer, "Durée de la revue : " + getDurationInMinutes() + " minutes\n"); + addChunk(buffer, "Nombre de participants : " + this.participants.size() + "\n"); + + // result = buffer.toString(); //