Skip to content

Commit

Permalink
Compare revamp (#113)
Browse files Browse the repository at this point in the history
* wipfeat: compare-revamp

* feat: compare revamp, showing a single test instead of test statistics
  • Loading branch information
VanillaViking authored Jan 11, 2024
1 parent d3ff40b commit 3bf8be5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
29 changes: 18 additions & 11 deletions zyenyo-discord/src/main/java/asynchronous/typing/CompareTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package asynchronous.typing;

import java.time.Instant;

import org.bson.Document;

import net.dv8tion.jda.api.EmbedBuilder;
Expand All @@ -25,20 +27,25 @@ public CompareTest(MessageReceivedEvent event, String[] args)
@Override
public void run()
{
String messageAuthorName = event.getAuthor().getName();
String channelID = event.getChannel().getId();
try {
String messageAuthorName = event.getAuthor().getName();
String channelID = event.getChannel().getId();

Document stats = Database.channelCompare(channelID, event.getAuthor().getId());
Document stats = Database.channelCompare(channelID, event.getAuthor().getId());

EmbedBuilder embed = new EmbedBuilder().setTitle(String.format("Top stats for %s on %s", messageAuthorName, stats.getString("_id")));
embed.appendDescription(String.format(
"Best TP: **`%.2f`**%n"
+ "Best WPM: **`%.2f`**%n"
+ "Best ACC: **`%.2f`**%%%n"
+ "Average TP: **`%.2f`**%n",
stats.getDouble("maxTp"), stats.getDouble("maxWpm"), stats.getDouble("maxAcc"), stats.getDouble("avgTp")));
EmbedBuilder embed = new EmbedBuilder().setTitle(String.format("Best score for %s on %s", messageAuthorName, stats.getString("prompt")));
embed.appendDescription(String.format(
"TP: **`%.2f`**%n"
+ "WPM: **`%.2f`**%n"
+ "ACC: **`%.2f`**%%%n"
+ "Set: <t:%d:R>",
stats.getDouble("tp"), stats.getDouble("wpm"), stats.getDouble("accuracy"), stats.getDate("date").toInstant().toEpochMilli() / 1000));

event.getChannel().sendMessageEmbeds(embed.build()).queue();
event.getChannel().sendMessageEmbeds(embed.build()).queue();

} catch (Exception e) {
System.err.println(e);
}
}

}
8 changes: 2 additions & 6 deletions zyenyo-discord/src/main/java/asynchronous/typing/TypeTop.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package asynchronous.typing;

import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
Expand Down Expand Up @@ -96,12 +97,7 @@ public void run()
play.get("tp"),
play.get("wpm"),
play.get("accuracy"),
ZonedDateTime.parse(
play.get("date").toString(),
DateTimeFormatter.ofPattern("E MMM d HH:mm:ss z uuuu", Locale.ENGLISH))
.toInstant()
.toEpochMilli()/1000
),
play.getDate("date").toInstant().toEpochMilli() / 1000),
false
);

Expand Down
8 changes: 2 additions & 6 deletions zyenyo-discord/src/main/java/zyenyo/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,8 @@ public static Document channelCompare(String channelID, String discordId) {
Document results = testsV2.aggregate(Arrays.asList(
Aggregates.match(Filters.eq("discordId", discordId)),
Aggregates.match(Filters.eq("prompt", promptToCompare)),
Aggregates.group("$prompt",
Accumulators.max("maxTp", "$tp"),
Accumulators.max("maxWpm", "$wpm"),
Accumulators.max("maxAcc", "$accuracy"),
Accumulators.avg("avgTp", "$tp")
)
Aggregates.sort(descending("tp")),
Aggregates.limit(1)
)).first();

return results;
Expand Down

0 comments on commit 3bf8be5

Please sign in to comment.