362 lines
9.4 KiB
Java
362 lines
9.4 KiB
Java
/**
|
|
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
|
|
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
|
|
*
|
|
* 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.review;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.Locale;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.april.hebdobot.bot.stats.ReviewDatas;
|
|
import org.april.hebdobot.bot.stats.ReviewStatsReporter;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import fr.devinsy.strings.StringList;
|
|
|
|
/**
|
|
* The Class Review.
|
|
*/
|
|
public class ReviewReporter
|
|
{
|
|
private static final Logger logger = LoggerFactory.getLogger(ReviewReporter.class);
|
|
|
|
private static final int LENGTH_LINE = 80;
|
|
|
|
/**
|
|
* Adds the center.
|
|
*
|
|
* @param buffer
|
|
* the buffer
|
|
* @param content
|
|
* the content
|
|
*/
|
|
private static void addCenter(final StringList buffer, final String content)
|
|
{
|
|
addCenter(buffer, content, ' ');
|
|
}
|
|
|
|
/**
|
|
* Adds the center.
|
|
*
|
|
* @param buffer
|
|
* the buffer
|
|
* @param content
|
|
* the content
|
|
* @param letter
|
|
* the c
|
|
*/
|
|
private static void addCenter(final StringList buffer, final String content, final char letter)
|
|
{
|
|
buffer.appendln(getLine(content, letter));
|
|
}
|
|
|
|
/**
|
|
* Adds the chunk.
|
|
*
|
|
* @param buffer
|
|
* the buffer
|
|
* @param content
|
|
* the content
|
|
*/
|
|
private static void addChunk(final StringList buffer, final String content)
|
|
{
|
|
appendln(buffer, chunk(content));
|
|
}
|
|
|
|
/**
|
|
* Adds the empty.
|
|
*
|
|
* @param buffer
|
|
* the buffer
|
|
*/
|
|
private static void addEmpty(final StringList buffer)
|
|
{
|
|
buffer.appendln();
|
|
}
|
|
|
|
/**
|
|
* Adds the line.
|
|
*
|
|
* @param buffer
|
|
* the buffer
|
|
* @param c
|
|
* the c
|
|
*/
|
|
private static void addLine(final StringList buffer, final char c)
|
|
{
|
|
buffer.append(getLine(c)).appendln();
|
|
}
|
|
|
|
/**
|
|
* Adds the.
|
|
*
|
|
* @param buffer
|
|
* the buffer
|
|
* @param content
|
|
* the content
|
|
*/
|
|
private static void append(final StringList buffer, final String content)
|
|
{
|
|
buffer.append(content);
|
|
}
|
|
|
|
/**
|
|
* Appendln.
|
|
*
|
|
* @param buffer
|
|
* the buffer
|
|
* @param content
|
|
* the content
|
|
*/
|
|
private static void appendln(final StringList buffer, final String content)
|
|
{
|
|
buffer.appendln(content);
|
|
}
|
|
|
|
/**
|
|
* Chunk.
|
|
*
|
|
* @param content
|
|
* the content
|
|
* @return the string
|
|
*/
|
|
private static String chunk(final String content)
|
|
{
|
|
String result;
|
|
|
|
result = chunk(content, LENGTH_LINE);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Chunk.
|
|
*
|
|
* @param content
|
|
* the content
|
|
* @param maxLength
|
|
* the length
|
|
* @return the string
|
|
*/
|
|
private static String chunk(final String content, final int maxLength)
|
|
{
|
|
String result;
|
|
|
|
final String[] words = content.split(" ");
|
|
final StringBuffer buffer = new StringBuffer();
|
|
StringBuffer current = new StringBuffer();
|
|
|
|
for (final String word : words)
|
|
{
|
|
if (current.length() + word.length() > maxLength)
|
|
{
|
|
if (buffer.length() > 0)
|
|
{
|
|
buffer.append("\n");
|
|
}
|
|
buffer.append(current);
|
|
current = new StringBuffer(word);
|
|
}
|
|
else
|
|
{
|
|
if (current.length() > 0)
|
|
{
|
|
current.append(" ");
|
|
}
|
|
current.append(word);
|
|
}
|
|
}
|
|
|
|
if (current.length() > 0)
|
|
{
|
|
if (buffer.length() > 0)
|
|
{
|
|
buffer.append("\n");
|
|
}
|
|
buffer.append(current);
|
|
}
|
|
|
|
result = buffer.toString();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the line.
|
|
*
|
|
* @param letter
|
|
* the letter
|
|
* @return the line
|
|
*/
|
|
private static String getLine(final Character letter)
|
|
{
|
|
String result;
|
|
|
|
result = StringUtils.repeat(letter.toString(), LENGTH_LINE);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the line.
|
|
*
|
|
* @param content
|
|
* the content
|
|
* @param letter
|
|
* the c
|
|
* @return the line
|
|
*/
|
|
private static String getLine(final String content, final char letter)
|
|
{
|
|
String result;
|
|
|
|
result = StringUtils.center(" " + content + " ", LENGTH_LINE, letter);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the topic.
|
|
*
|
|
* @param topic
|
|
* the topic
|
|
* @return the topic
|
|
*/
|
|
private static String getTopic(final Topic topic)
|
|
{
|
|
String result;
|
|
|
|
result = "=== " + topic.getTitle() + " ===";
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Report.
|
|
*
|
|
* @param datas
|
|
* the datas
|
|
* @param review
|
|
* the review
|
|
* @return the string
|
|
*/
|
|
public static String report(final ReviewDatas datas, final Review review)
|
|
{
|
|
String result;
|
|
|
|
//
|
|
StringList buffer = new StringList();
|
|
|
|
//
|
|
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", Locale.FRENCH))));
|
|
addLine(buffer, '=');
|
|
addEmpty(buffer);
|
|
addEmpty(buffer);
|
|
|
|
//
|
|
addLine(buffer, '=');
|
|
addEmpty(buffer);
|
|
addCenter(buffer, "Personnes participantes", '-');
|
|
for (final String participant : review.getParticipants())
|
|
{
|
|
addChunk(buffer, "* " + review.getAliases().getRealName(participant));
|
|
}
|
|
|
|
//
|
|
if (!review.getIndividualTopics().isEmpty())
|
|
{
|
|
for (final String participant : review.getParticipants())
|
|
{
|
|
addEmpty(buffer);
|
|
addLine(buffer, '=');
|
|
addEmpty(buffer);
|
|
addCenter(buffer, review.getAliases().getRealName(participant), '-');
|
|
for (final IndividualTopic topic : review.getIndividualTopics())
|
|
{
|
|
if (topic.hasParticipant(participant))
|
|
{
|
|
addEmpty(buffer);
|
|
appendln(buffer, getTopic(topic));
|
|
addEmpty(buffer);
|
|
for (final Message message : topic.getMessages(participant))
|
|
{
|
|
addChunk(buffer, "* " + message.getContent());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (!review.getCollectiveTopics().isEmpty())
|
|
{
|
|
for (final CollectiveTopic topic : review.getCollectiveTopics())
|
|
{
|
|
addEmpty(buffer);
|
|
addLine(buffer, '=');
|
|
addCenter(buffer, topic.getTitle());
|
|
addLine(buffer, '=');
|
|
addEmpty(buffer);
|
|
for (final Message message : topic.getMessages())
|
|
{
|
|
addChunk(buffer, "* " + message.getAuthor() + " : " + message.getContent());
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
addEmpty(buffer);
|
|
addCenter(buffer, "Log IRC brut");
|
|
addEmpty(buffer);
|
|
for (Message message : review.getMessages())
|
|
{
|
|
addChunk(buffer, "* " + message.getAuthor() + " : " + message.getContent());
|
|
}
|
|
|
|
// Add statistics in text review.
|
|
addEmpty(buffer);
|
|
addCenter(buffer, "Statistiques");
|
|
addEmpty(buffer);
|
|
addChunk(buffer, ReviewStatsReporter.reportCurrentReviewCount(datas));
|
|
addChunk(buffer, "Horaire de début de la revue : " + review.getFormattedStartTime());
|
|
addChunk(buffer, "Horaire de fin de la revue : " + review.getFormattedEndTime());
|
|
addChunk(buffer, "Durée de la revue : " + review.getDurationInMinutes() + " minutes");
|
|
addChunk(buffer, "Nombre de personnes participantes : " + review.getParticipants().size());
|
|
addChunk(buffer, ReviewStatsReporter.reportCheckUserCountRecord(datas));
|
|
addChunk(buffer, ReviewStatsReporter.reportUserCount(datas, review.getParticipants().size()));
|
|
addChunk(buffer, ReviewStatsReporter.reportDuration(datas, review.getDurationInMinutes()));
|
|
|
|
//
|
|
result = buffer.toString();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|