changes 2

This commit is contained in:
Woosle Park 2019-03-27 04:47:48 -04:00
parent f2c11cc7f8
commit 138c4714d5
3 changed files with 35 additions and 9 deletions

View File

@ -44,6 +44,34 @@ public class UserStatsHelper {
return rows;
}
/**
* Get top n players along with all their stat values, in descending order
*
* @param n Maximum number of players
* @return Top n players, in User,value format, in descending order
*/
public ArrayList<Map.Entry<User, Map<String, Integer>>> getTopNAll(int n) {
ArrayList<Map.Entry<User, Map<String, Integer>>> rows = new ArrayList<>();
ArrayList<Map.Entry<User, ArrayList>> vaults = new ArrayList<>(this.getTopNSetLength("completedVaults", n));
ArrayList<Map.Entry<User, Integer>> deaths = new ArrayList<>(this.getTopN("deathCount", n));
ArrayList<Map.Entry<User, Integer>> time = new ArrayList<>(this.getTopN("executionTime", n));
ArrayList<Map.Entry<User, Integer>> distance = new ArrayList<>(this.getTopN("walkDistance", n));
for (int i = 0; i < n ; i++) {
User user = vaults.get(i).getKey();
Map<String, Integer> allStats = new HashMap();
allStats.put("completedVaults", vaults.get(i).getValue().size());
allStats.put("deathCount", deaths.get(i).getValue());
allStats.put("executionTime", time.get(i).getValue());
allStats.put("walkDistance", distance.get(i).getValue());
rows.add(new AbstractMap.SimpleEntry<>(user, allStats));
}
return rows;
}
/**
* Get top n players along with the stat set, in descending order
*

View File

@ -9,16 +9,14 @@ import spark.TemplateViewRoute;
import java.util.HashMap;
import java.util.Map;
public class LeaderBoardPage implements TemplateViewRoute {
@Override
public ModelAndView handle(Request request, Response response) {
Map<String, Object> model = new HashMap<>(5);
Map<String, Object> model = new HashMap<>(2);
model.put("session", request.session());
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("completedVaults", 25));
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("deathCount", 25));
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("totalExecutionTime", 25));
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("walkDistance", 25));
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNAll(25));;
return new ModelAndView(model, "leaderboard.vm");
}
}

View File

@ -25,10 +25,10 @@
#foreach($row in $stats)
<tr>
<td>$row.getKey().getUsername()</td>
<td>$row.getValue().size()</td>
<td>$row.getValue()</td>
<td>$row.getValue()</td>
<td>$row.getValue()</td>
<td>$row.getValue().get("completedVaults")</td>
<td>$row.getValue().get("deathCount")</td>
<td>$row.getValue().get("executionTime")</td>
<td>$row.getValue().get("walkDistance")</td>
</tr>
#end
</tbody>