362 lines
10 KiB
Java
362 lines
10 KiB
Java
/**
|
|
* Copyright (C) 2017-2021 Christian Pierre MOMON <cmomon@april.org>
|
|
*
|
|
* This file is part of (April) Hebdobot.
|
|
*
|
|
* Hebdobot is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Hebdobot is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with Hebdobot. If not, see <http://www.gnu.org/licenses/>
|
|
*/
|
|
package org.april.hebdobot.bot.stats;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.Locale;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* The Class ReviewStatReporter.
|
|
*/
|
|
public class ReviewStatsReporter
|
|
{
|
|
private static final Logger logger = LoggerFactory.getLogger(ReviewStatsReporter.class);
|
|
|
|
/**
|
|
* Instantiates a new review stat reporter.
|
|
*/
|
|
private ReviewStatsReporter()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Number suffix.
|
|
*
|
|
* @param number
|
|
* the number
|
|
* @return the string
|
|
*/
|
|
public static String numberSuffix(final long number)
|
|
{
|
|
String result;
|
|
|
|
if (number == 1)
|
|
{
|
|
result = "ère";
|
|
}
|
|
else
|
|
{
|
|
result = "e";
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Percent.
|
|
*
|
|
* @param a
|
|
* the a
|
|
* @param b
|
|
* the b
|
|
* @return the double
|
|
*/
|
|
private static double percent(final double a, final double b)
|
|
{
|
|
double result;
|
|
|
|
if (b == 0.)
|
|
{
|
|
result = 0.;
|
|
}
|
|
else
|
|
{
|
|
result = Math.round(10000. * (a / b)) / 100.;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Percent.
|
|
*
|
|
* @param a
|
|
* the a
|
|
* @param b
|
|
* the b
|
|
* @return the double
|
|
*/
|
|
private static double percent(final int a, final int b)
|
|
{
|
|
double result;
|
|
|
|
result = percent(Double.valueOf(a).doubleValue(), Double.valueOf(b).doubleValue());
|
|
|
|
//
|
|
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.
|
|
*
|
|
* @param datas
|
|
* the datas
|
|
* @param currentDuration
|
|
* the current duration
|
|
* @return the string
|
|
*/
|
|
public static String reportDuration(final ReviewDatas datas, final long currentDuration)
|
|
{
|
|
String result;
|
|
|
|
if ((datas == null) || (datas.isEmpty()))
|
|
{
|
|
result = "Pas de statistique sur la durée de la revue.";
|
|
}
|
|
else
|
|
{
|
|
LongBoard board = new LongBoard();
|
|
for (ReviewData data : datas)
|
|
{
|
|
board.add(data.getDuration());
|
|
}
|
|
logger.debug("Duration board: " + board.toString());
|
|
|
|
LongStat stat = board.get(currentDuration);
|
|
int total = board.getCountSum();
|
|
|
|
result = String.format(
|
|
"Statistiques sur la durée de la revue (%d min) : position %d (min.=%d min, moy.=%.1f min, max.=%d min), fréquence %d/%d (%.0f %%)",
|
|
stat.getValue(), board.getPositionOf(stat.getValue()), board.getMinValue(), board.getAverage(), board.getMaxValue(),
|
|
stat.getCount(), total, percent(stat.getCount(), total));
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Report duration board.
|
|
*
|
|
* @param datas
|
|
* the datas
|
|
* @return the string
|
|
*/
|
|
public static String reportDurationBoard(final ReviewDatas datas)
|
|
{
|
|
String result;
|
|
|
|
LongBoard board = new LongBoard();
|
|
for (ReviewData data : datas)
|
|
{
|
|
board.add(data.getDuration());
|
|
}
|
|
result = "Tableau des durées (en minutes) : " + board.toString();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Report review count.
|
|
*
|
|
* @param datas
|
|
* the datas
|
|
* @return the string
|
|
*/
|
|
public static String reportReviewCount(final ReviewDatas datas)
|
|
{
|
|
String result;
|
|
|
|
if ((datas == null) || (datas.isEmpty()))
|
|
{
|
|
result = "Pas de statistique sur le nombre de revues.";
|
|
}
|
|
else
|
|
{
|
|
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("Il y a eu %d revues. La première date du %s.", reviewCount, firstDate);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Report user count.
|
|
*
|
|
* @param datas
|
|
* the datas
|
|
* @param currentUserCount
|
|
* the current user count
|
|
* @return the string
|
|
*/
|
|
public static String reportUserCount(final ReviewDatas datas, final int currentUserCount)
|
|
{
|
|
String result;
|
|
|
|
if ((datas == null) || (datas.isEmpty()))
|
|
{
|
|
result = "Absence de statistique sur la participation.";
|
|
}
|
|
else
|
|
{
|
|
IntegerBoard board = new IntegerBoard();
|
|
for (ReviewData data : datas)
|
|
{
|
|
board.add(data.getUserCount());
|
|
}
|
|
logger.debug("User count board: " + board.toString());
|
|
|
|
IntegerStat stat = board.get(currentUserCount);
|
|
int total = board.getCountSum();
|
|
result = String.format(
|
|
"Statistiques sur la participation à la revue (%d personnes) : position %d (min.=%d, moy.=%.1f, max.=%d), fréquence %d/%d (%.0f %%)",
|
|
stat.getValue(), board.getPositionOf(stat.getValue()), board.getMinValue(), board.getAverage(), board.getMaxValue(),
|
|
stat.getCount(), total, percent(stat.getCount(), total));
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Report user count board.
|
|
*
|
|
* @param datas
|
|
* the datas
|
|
* @return the string
|
|
*/
|
|
public static String reportUserCountBoard(final ReviewDatas datas)
|
|
{
|
|
String result;
|
|
|
|
IntegerBoard board = new IntegerBoard();
|
|
for (ReviewData data : datas)
|
|
{
|
|
board.add(data.getUserCount());
|
|
}
|
|
result = "Tableau du nombre de personnes participantes : " + board.toString();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Report max user count.
|
|
*
|
|
* @param datas
|
|
* the datas
|
|
* @return the string
|
|
*/
|
|
public static String reportUserCountRecord(final ReviewDatas datas)
|
|
{
|
|
String result;
|
|
|
|
if ((datas == null) || (datas.isEmpty()))
|
|
{
|
|
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 le %s.", recordReview.getUserCount(), recordDate);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|