/** * Copyright (C) 2017-2018 Christian Pierre MOMON * * 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 */ package org.april.hebdobot.model.stats; 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() { } /** * 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(new Double(a).doubleValue(), new Double(b).doubleValue()); // return result; } /** * Report duration. * * @param datas * the datas * @param currentDuration * the current duration * @return the string */ public static String reportDuration(final ReviewDatas datas, final int currentDuration) { String result; IntegerBoard board = new IntegerBoard(); for (ReviewData data : datas) { board.add(data.getDuration()); } logger.debug("Duration board: " + board.toString()); IntegerStat 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; IntegerBoard board = new IntegerBoard(); for (ReviewData data : datas) { board.add(data.getDuration()); } result = "Tableau des durées (mn) : " + board.toString(); // return result; } /** * Report new max. * * @param datas * the datas * @param currentUserCount * the current user count * @return the string */ public static String reportNewMaxUserCount(final ReviewDatas datas, final int currentUserCount) { String result; datas.sortByDate(); ReviewData last = datas.getLastByMaxUserCount(); if (currentUserCount == last.getUserCount()) { result = "Record de participation égalé."; } else if (currentUserCount < last.getUserCount()) { result = "Pas de nouveau record de participation."; } else { result = "Nombre record de personnes participantes !"; } String lastRecordDate = last.getDate().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy", Locale.FRENCH)); result = String.format("%s Le dernier record de %d personnes participantes remonte au %s.", result, last.getUserCount(), lastRecordDate); // 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; 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.getDuration()); } result = "Tableau du nombre de personnes participantes : " + board.toString(); // return result; } }