Add ranking, need to do mobile view

This commit is contained in:
Sebastien 2019-01-01 22:40:37 +01:00
parent f0d4b865b1
commit 89f20e7644
3 changed files with 68 additions and 12 deletions

View File

@ -2,6 +2,7 @@ package net.Broken.Tools.UserManager.Stats;
public class GuildStats{ public class GuildStats{
public String userName; public String userName;
public int rank;
public String avatarUrl; public String avatarUrl;
public long voiceTime; public long voiceTime;
@ -19,13 +20,13 @@ public class GuildStats{
public GuildStats() { public GuildStats() {
} }
public GuildStats(String userName, String avatarUrl, long voiceTime, long messageCount, long apiCount) { public GuildStats(String userName, int rank, String avatarUrl, long voiceTime, long messageCount, long apiCount) {
this.userName = userName; this.userName = userName;
this.avatarUrl = avatarUrl; this.avatarUrl = avatarUrl;
this.voiceTime = voiceTime; this.voiceTime = voiceTime;
this.messageCount = messageCount; this.messageCount = messageCount;
this.apiCount = apiCount; this.apiCount = apiCount;
this.rank = rank;
voiceXp = (long) (this.voiceTime * UserStatsUtils.XP_PER_VOICE_TIME); voiceXp = (long) (this.voiceTime * UserStatsUtils.XP_PER_VOICE_TIME);
messageXp = (long) (this.messageCount * UserStatsUtils.XP_PER_MESSAGE); messageXp = (long) (this.messageCount * UserStatsUtils.XP_PER_MESSAGE);

View File

@ -165,13 +165,16 @@ public class UserStatsUtils {
List<UserStats> allStats = userStatsRepository.findByGuildId(guildId); List<UserStats> allStats = userStatsRepository.findByGuildId(guildId);
List<GuildStats> ranked = new ArrayList<>(); List<GuildStats> ranked = new ArrayList<>();
int i = 1;
for(UserStats stats : allStats){ for(UserStats stats : allStats){
String avatar = MainBot.jda.getUserById(stats.getUser().getJdaId()).getAvatarUrl(); String avatar = MainBot.jda.getUserById(stats.getUser().getJdaId()).getAvatarUrl();
GuildStats temp = new GuildStats(stats.getUser().getName(), avatar, stats.getVocalTime(), stats.getMessageCount(), stats.getApiCommandCount()); GuildStats temp = new GuildStats(stats.getUser().getName(), i, avatar, stats.getVocalTime(), stats.getMessageCount(), stats.getApiCommandCount());
if(stats.getUser().getId().equals(userEntity.getId())){ if(stats.getUser().getId().equals(userEntity.getId())){
selfGuildStats = temp; selfGuildStats = temp;
} }
ranked.add(temp); ranked.add(temp);
i++;
} }
ranked.sort((guildStats, t1) -> (int) (t1.total - guildStats.total)); ranked.sort((guildStats, t1) -> (int) (t1.total - guildStats.total));

View File

@ -24,6 +24,11 @@
font-size: 15px; font-size: 15px;
font-weight: normal; font-weight: normal;
} }
td span{
color: #fbcf40;
font-size: 12px;
}
</style> </style>
@ -42,7 +47,7 @@
<main> <main>
<!--/*@thymesVar id="stack" type="net.Broken.Tools.UserManager.Stats.GuildStatsPack"*/--> <!--/*@thymesVar id="stack" type="net.Broken.Tools.UserManager.Stats.GuildStatsPack"*/-->
<div class="row"> <div class="row">
<div class="card-panel col m6 offset-m3 s10 offset-s1 grey darken-4 white-text"> <div class="card-panel col l6 offset-l3 m10 offset-m1 s10 offset-s1 grey darken-4 white-text">
<div class="row" style="margin-bottom: 0"> <div class="row" style="margin-bottom: 0">
<div class="col s12 center" style="margin-top: 10px"> <div class="col s12 center" style="margin-top: 10px">
<img class="circle" th:src="${stack.selfStats.avatarUrl}" <img class="circle" th:src="${stack.selfStats.avatarUrl}"
@ -52,8 +57,8 @@
<h4 style="font-weight: bold; margin: 0;" th:text="${stack.selfStats.userName}"></h4> <h4 style="font-weight: bold; margin: 0;" th:text="${stack.selfStats.userName}"></h4>
</div> </div>
</div> </div>
<div class="row"> <div class="row" style="margin-bottom: 0">
<div class="col s6 center"> <div class="col m6 s12 center">
<table class="centered"> <table class="centered">
<thead> <thead>
<tr> <tr>
@ -72,7 +77,7 @@
</table> </table>
</div> </div>
<div class="col s6 center"> <div class="col m6 s12 center">
<table class="centered"> <table class="centered">
<thead> <thead>
<tr> <tr>
@ -94,7 +99,7 @@
<div class="row"> <div class="row">
<div class="col s6 center"> <div class="col m6 s12 center">
<table class="centered"> <table class="centered">
<thead> <thead>
<tr> <tr>
@ -105,9 +110,12 @@
<tr> <tr>
<td> <td>
<h4 style="font-weight: bold; margin: 0"> <h4 style="font-weight: bold; margin: 0">
<span th:text="${T(net.Broken.Tools.TimeConvertor).sToTime(stack.selfStats.voiceTime).get(0)}" th:remove="tag"></span> <span>H</span> <span th:text="${T(net.Broken.Tools.TimeConvertor).sToTime(stack.selfStats.voiceTime).get(0)}"
<span th:text="${T(net.Broken.Tools.TimeConvertor).sToTime(stack.selfStats.voiceTime).get(1)}" th:remove="tag"></span> <span>M</span> th:remove="tag"></span> <span>H</span>
<span th:text="${T(net.Broken.Tools.TimeConvertor).sToTime(stack.selfStats.voiceTime).get(2)}" th:remove="tag"></span> <span>S</span> <span th:text="${T(net.Broken.Tools.TimeConvertor).sToTime(stack.selfStats.voiceTime).get(1)}"
th:remove="tag"></span> <span>M</span>
<span th:text="${T(net.Broken.Tools.TimeConvertor).sToTime(stack.selfStats.voiceTime).get(2)}"
th:remove="tag"></span> <span>S</span>
</h4> </h4>
</td> </td>
</tr> </tr>
@ -115,7 +123,7 @@
</table> </table>
</div> </div>
<div class="col s6 center"> <div class="col m6 s12 center">
<table class="centered"> <table class="centered">
<thead> <thead>
<tr> <tr>
@ -137,6 +145,50 @@
</div> </div>
</div> </div>
<div class="row">
<div class="col l6 offset-l3 m10 offset-m1 hide-on-small-and-down card-panel grey darken-4 white-text">
<h3 class="center"><b>Ranking</b></h3>
<table class="centered">
<thead>
<tr>
<th>Rank</th>
<th></th>
<th>Name</th>
<th>Vocal Time</th>
<th>Message Count</th>
<th>Total XP</th>
</tr>
</thead>
<tbody>
<th:block th:each="stat : ${stack.ranking}">
<tr>
<td th:text="${stat.rank}"></td>
<td><img th:src="${stat.avatarUrl}" class="circle" style="max-height: 50px"/> </td>
<td th:text="${stat.userName}"></td>
<td> <span th:text="${T(net.Broken.Tools.TimeConvertor).sToTime(stat.voiceTime).get(0)}"
th:remove="tag"></span> <span>H</span>
<span th:text="${T(net.Broken.Tools.TimeConvertor).sToTime(stat.voiceTime).get(1)}"
th:remove="tag"></span> <span>M</span>
<span th:text="${T(net.Broken.Tools.TimeConvertor).sToTime(stat.voiceTime).get(2)}"
th:remove="tag"></span> <span>S</span></td>
<td th:text="${stat.messageCount}"></td>
<td th:text="${stat.total}"></td>
</tr>
</th:block>
</tbody>
</table>
</div>
</div>
</main> </main>
<footer class="page-footer" style="padding: 0"> <footer class="page-footer" style="padding: 0">