Skip to content

Commit f5aa49f

Browse files
committed
redesign the help statistics plot
1 parent 919fd5e commit f5aa49f

5 files changed

Lines changed: 334 additions & 80 deletions

File tree

src/main/java/net/discordjug/javabot/systems/help/commands/HelpAccountSubcommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private FileUpload generatePlot(User user) {
125125
plotData.add(new Pair<>(position.getMonth() + " " + position.getYear(), new Plotter.Bar(value)));
126126
}
127127

128-
BufferedImage plt = new Plotter(plotData, "gained help XP per month").plot();
128+
BufferedImage plt = new Plotter(plotData, "General Helper XP Gains","XP earned each month from general helper activity").plot();
129129
try(ByteArrayOutputStream os = new ByteArrayOutputStream()){
130130
ImageIO.write(plt, "png", os);
131131
return FileUpload.fromData(os.toByteArray(), "image.png");

src/main/java/net/discordjug/javabot/systems/help/commands/HelpStatisticsSubcommand.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@
55
import java.io.ByteArrayOutputStream;
66
import java.io.IOException;
77
import java.time.LocalDate;
8-
import java.util.ArrayList;
9-
import java.util.Comparator;
10-
import java.util.HashMap;
11-
import java.util.LinkedHashMap;
12-
import java.util.List;
13-
import java.util.Map;
8+
import java.util.*;
149
import java.util.Map.Entry;
15-
import java.util.PriorityQueue;
1610

1711
import javax.imageio.ImageIO;
1812

@@ -24,6 +18,8 @@
2418
import net.discordjug.javabot.util.Plotter;
2519
import net.dv8tion.jda.api.EmbedBuilder;
2620
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
21+
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
22+
import net.dv8tion.jda.api.interactions.commands.OptionType;
2723
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
2824
import net.dv8tion.jda.api.utils.FileUpload;
2925
import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand;
@@ -34,21 +30,30 @@
3430
public class HelpStatisticsSubcommand extends SlashCommand.Subcommand {
3531

3632
private static final List<Pair<String, Color>> COLORS = List.of(
37-
new Pair<>("Red", Color.RED), new Pair<>("Blue", Color.BLUE), new Pair<>("Yellow", Color.YELLOW),
38-
new Pair<>("Green", Color.GREEN), new Pair<>("Cyan", Color.CYAN), new Pair<>("Magenta", Color.MAGENTA),
39-
new Pair<>("Orange", Color.ORANGE), new Pair<>("Pink", Color.PINK), new Pair<>("Light gray", Color.LIGHT_GRAY)
33+
new Pair<>("Red", Color.decode("#D62728")), new Pair<>("Blue", Color.decode("#1F77B4")), new Pair<>("Yellow", Color.decode("#BCBD22")),
34+
new Pair<>("Green", Color.decode("#2CA02C")), new Pair<>("Cyan", Color.decode("#17BECF")), new Pair<>("Magenta", Color.decode("#9467BD")),
35+
new Pair<>("Orange", Color.decode("#FF7F0E")), new Pair<>("Pink", Color.decode("#E377C2")), new Pair<>("Light gray", Color.decode("#7F7F7F"))
4036
);
4137

4238
private final HelpTransactionRepository transactionRepository;
43-
39+
40+
/**
41+
* Creates the help statistics subcommand.
42+
*
43+
* @param transactionRepository repository for help transactions
44+
*/
4445
public HelpStatisticsSubcommand(HelpTransactionRepository transactionRepository) {
4546
this.transactionRepository = transactionRepository;
46-
setCommandData(new SubcommandData("stats", "Shows an general plot about help activity in this server"));
47+
setCommandData(new SubcommandData("stats", "Shows an general plot about help activity in this server")
48+
.addOption(OptionType.BOOLEAN, "darkmode", "generate a plot in dark mode.", false)
49+
);
50+
4751
}
4852

4953
@Override
5054
public void execute(SlashCommandInteractionEvent event) {
51-
55+
boolean darkMode = event.getOption("darkmode", false, OptionMapping::getAsBoolean);
56+
5257
event.deferReply().queue();
5358

5459
List<Pair<MonthInYear,HelpAccount>> transactionWeights = transactionRepository.getTotalTransactionWeightByMonthAndUsers(LocalDate.now().withDayOfMonth(1).minusYears(1).atStartOfDay());
@@ -75,8 +80,8 @@ public void execute(SlashCommandInteractionEvent event) {
7580
}
7681
plotData.add(new Pair<>(position.getMonth() + " " + position.getYear(), new Plotter.Bar(entriesForThisMonth)));
7782
}
78-
79-
BufferedImage plot = new Plotter(plotData, "General helper statistics").plot();
83+
84+
BufferedImage plot = new Plotter(plotData, "Help Statistics","Monthly assistance provided to community members",darkMode).plot();
8085
try(ByteArrayOutputStream os = new ByteArrayOutputStream()){
8186
ImageIO.write(plot, "png", os);
8287
FileUpload upload = FileUpload.fromData(os.toByteArray(), "image.png");

0 commit comments

Comments
 (0)