Permalink
Browse files

Setup webserver and frontend stuff, and fix some minor issues

  • Loading branch information...
Derpthemeus committed Jan 1, 2018
1 parent 5626821 commit 17e9ff5a62255565aa34e2f9aece7633fa16249b
Showing with 23,511 additions and 5 deletions.
  1. +2 −0 build.gradle
  2. +5 −2 src/main/java/com/derpthemeus/runeCoach/RuneCoach.java
  3. +2 −0 .../java/com/derpthemeus/runeCoach/databasePopulator/threadSupervisors/StatAggregatorSupervisor.java
  4. +73 −0 src/main/java/com/derpthemeus/runeCoach/jetty/ChampionInfoHandler.java
  5. +34 −0 src/main/java/com/derpthemeus/runeCoach/jetty/RuneCoachWebServer.java
  6. +72 −0 src/main/java/com/derpthemeus/runeCoach/jetty/RunesHandler.java
  7. +79 −0 src/main/java/com/derpthemeus/runeCoach/jetty/StaticDataHandler.java
  8. +650 −0 src/main/resources/LCU-runes.json
  9. +589 −0 src/main/resources/builder-runes.json
  10. +151 −0 src/main/resources/frontend_static/css/lol-fonts.css
  11. +3,527 −0 src/main/resources/frontend_static/css/rune-builder.css
  12. +89 −0 src/main/resources/frontend_static/css/styles.css
  13. +1,315 −0 src/main/resources/frontend_static/fonts/BeaufortforLOL-Bold.svg
  14. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Bold.ttf
  15. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Bold.woff
  16. +1,316 −0 src/main/resources/frontend_static/fonts/BeaufortforLOL-BoldItalic.svg
  17. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-BoldItalic.ttf
  18. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-BoldItalic.woff
  19. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-BoldItalicd41d.eot
  20. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Boldd41d.eot
  21. +1,315 −0 src/main/resources/frontend_static/fonts/BeaufortforLOL-Heavy.svg
  22. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Heavy.ttf
  23. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Heavy.woff
  24. +1,319 −0 src/main/resources/frontend_static/fonts/BeaufortforLOL-HeavyItalic.svg
  25. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-HeavyItalic.ttf
  26. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-HeavyItalic.woff
  27. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-HeavyItalicd41d.eot
  28. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Heavyd41d.eot
  29. +1,316 −0 src/main/resources/frontend_static/fonts/BeaufortforLOL-Italic.svg
  30. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Italic.ttf
  31. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Italic.woff
  32. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Italicd41d.eot
  33. +1,314 −0 src/main/resources/frontend_static/fonts/BeaufortforLOL-Light.svg
  34. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Light.ttf
  35. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Light.woff
  36. +1,317 −0 src/main/resources/frontend_static/fonts/BeaufortforLOL-LightItalic.svg
  37. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-LightItalic.ttf
  38. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-LightItalic.woff
  39. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-LightItalicd41d.eot
  40. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Lightd41d.eot
  41. +1,317 −0 src/main/resources/frontend_static/fonts/BeaufortforLOL-Medium.svg
  42. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Medium.ttf
  43. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Medium.woff
  44. +1,316 −0 src/main/resources/frontend_static/fonts/BeaufortforLOL-MediumItalic.svg
  45. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-MediumItalic.ttf
  46. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-MediumItalic.woff
  47. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-MediumItalicd41d.eot
  48. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Mediumd41d.eot
  49. +1,314 −0 src/main/resources/frontend_static/fonts/BeaufortforLOL-Regular.svg
  50. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Regular.ttf
  51. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Regular.woff
  52. BIN src/main/resources/frontend_static/fonts/BeaufortforLOL-Regulard41d.eot
  53. BIN src/main/resources/frontend_static/img/checkbox-sprite.png
  54. BIN src/main/resources/frontend_static/img/construct/domination/construct.png
  55. BIN src/main/resources/frontend_static/img/construct/domination/environment.png
  56. BIN src/main/resources/frontend_static/img/construct/inspiration/construct.png
  57. BIN src/main/resources/frontend_static/img/construct/inspiration/environment.png
  58. BIN src/main/resources/frontend_static/img/construct/precision/construct.png
  59. BIN src/main/resources/frontend_static/img/construct/precision/environment.png
  60. BIN src/main/resources/frontend_static/img/construct/resolve/construct.png
  61. BIN src/main/resources/frontend_static/img/construct/resolve/environment.png
  62. BIN src/main/resources/frontend_static/img/construct/sorcery/construct.png
  63. BIN src/main/resources/frontend_static/img/construct/sorcery/environment.png
  64. BIN src/main/resources/frontend_static/img/logo-icon.png
  65. BIN src/main/resources/frontend_static/img/ring.png
  66. BIN src/main/resources/frontend_static/img/runes-108x108/8005.png
  67. BIN src/main/resources/frontend_static/img/runes-108x108/8008.png
  68. BIN src/main/resources/frontend_static/img/runes-108x108/8009.png
  69. BIN src/main/resources/frontend_static/img/runes-108x108/8014.png
  70. BIN src/main/resources/frontend_static/img/runes-108x108/8017.png
  71. BIN src/main/resources/frontend_static/img/runes-108x108/8021.png
  72. BIN src/main/resources/frontend_static/img/runes-108x108/8105.png
  73. BIN src/main/resources/frontend_static/img/runes-108x108/8112.png
  74. BIN src/main/resources/frontend_static/img/runes-108x108/8120.png
  75. BIN src/main/resources/frontend_static/img/runes-108x108/8124.png
  76. BIN src/main/resources/frontend_static/img/runes-108x108/8126.png
  77. BIN src/main/resources/frontend_static/img/runes-108x108/8128.png
  78. BIN src/main/resources/frontend_static/img/runes-108x108/8134.png
  79. BIN src/main/resources/frontend_static/img/runes-108x108/8135.png
  80. BIN src/main/resources/frontend_static/img/runes-108x108/8136.png
  81. BIN src/main/resources/frontend_static/img/runes-108x108/8138.png
  82. BIN src/main/resources/frontend_static/img/runes-108x108/8139.png
  83. BIN src/main/resources/frontend_static/img/runes-108x108/8143.png
  84. BIN src/main/resources/frontend_static/img/runes-108x108/8210.png
  85. BIN src/main/resources/frontend_static/img/runes-108x108/8214.png
  86. BIN src/main/resources/frontend_static/img/runes-108x108/8224.png
  87. BIN src/main/resources/frontend_static/img/runes-108x108/8226.png
  88. BIN src/main/resources/frontend_static/img/runes-108x108/8229.png
  89. BIN src/main/resources/frontend_static/img/runes-108x108/8230.png
  90. BIN src/main/resources/frontend_static/img/runes-108x108/8232.png
  91. BIN src/main/resources/frontend_static/img/runes-108x108/8233.png
  92. BIN src/main/resources/frontend_static/img/runes-108x108/8234.png
  93. BIN src/main/resources/frontend_static/img/runes-108x108/8236.png
  94. BIN src/main/resources/frontend_static/img/runes-108x108/8237.png
  95. BIN src/main/resources/frontend_static/img/runes-108x108/8242.png
  96. BIN src/main/resources/frontend_static/img/runes-108x108/8243.png
  97. BIN src/main/resources/frontend_static/img/runes-108x108/8299.png
  98. BIN src/main/resources/frontend_static/img/runes-108x108/8304.png
  99. BIN src/main/resources/frontend_static/img/runes-108x108/8306.png
  100. BIN src/main/resources/frontend_static/img/runes-108x108/8313.png
  101. BIN src/main/resources/frontend_static/img/runes-108x108/8316.png
  102. BIN src/main/resources/frontend_static/img/runes-108x108/8321.png
  103. BIN src/main/resources/frontend_static/img/runes-108x108/8326.png
  104. BIN src/main/resources/frontend_static/img/runes-108x108/8339.png
  105. BIN src/main/resources/frontend_static/img/runes-108x108/8345.png
  106. BIN src/main/resources/frontend_static/img/runes-108x108/8347.png
  107. BIN src/main/resources/frontend_static/img/runes-108x108/8351.png
  108. BIN src/main/resources/frontend_static/img/runes-108x108/8359.png
  109. BIN src/main/resources/frontend_static/img/runes-108x108/8410.png
  110. BIN src/main/resources/frontend_static/img/runes-108x108/8429.png
  111. BIN src/main/resources/frontend_static/img/runes-108x108/8430.png
  112. BIN src/main/resources/frontend_static/img/runes-108x108/8435.png
  113. BIN src/main/resources/frontend_static/img/runes-108x108/8437.png
  114. BIN src/main/resources/frontend_static/img/runes-108x108/8439.png
  115. BIN src/main/resources/frontend_static/img/runes-108x108/8444.png
  116. BIN src/main/resources/frontend_static/img/runes-108x108/8446.png
  117. BIN src/main/resources/frontend_static/img/runes-108x108/8451.png
  118. BIN src/main/resources/frontend_static/img/runes-108x108/8453.png
  119. BIN src/main/resources/frontend_static/img/runes-108x108/8463.png
  120. BIN src/main/resources/frontend_static/img/runes-108x108/8465.png
  121. BIN src/main/resources/frontend_static/img/runes-108x108/9101.png
  122. BIN src/main/resources/frontend_static/img/runes-108x108/9103.png
  123. BIN src/main/resources/frontend_static/img/runes-108x108/9104.png
  124. BIN src/main/resources/frontend_static/img/runes-108x108/9105.png
  125. BIN src/main/resources/frontend_static/img/runes-108x108/9111.png
  126. BIN src/main/resources/frontend_static/img/style-icons/36x36/domination.png
  127. BIN src/main/resources/frontend_static/img/style-icons/36x36/inspiration.png
  128. BIN src/main/resources/frontend_static/img/style-icons/36x36/precision.png
  129. BIN src/main/resources/frontend_static/img/style-icons/36x36/resolve.png
  130. BIN src/main/resources/frontend_static/img/style-icons/36x36/sorcery.png
  131. BIN src/main/resources/frontend_static/img/style-icons/domination.png
  132. BIN src/main/resources/frontend_static/img/style-icons/inspiration.png
  133. BIN src/main/resources/frontend_static/img/style-icons/precision.png
  134. BIN src/main/resources/frontend_static/img/style-icons/resolve.png
  135. BIN src/main/resources/frontend_static/img/style-icons/sorcery.png
  136. BIN src/main/resources/frontend_static/img/style-vfx/domination.png
  137. BIN src/main/resources/frontend_static/img/style-vfx/inspiration.png
  138. BIN src/main/resources/frontend_static/img/style-vfx/precision.png
  139. BIN src/main/resources/frontend_static/img/style-vfx/resolve.png
  140. BIN src/main/resources/frontend_static/img/style-vfx/sorcery.png
  141. BIN src/main/resources/frontend_static/img/tooltip-caret.png
  142. +101 −0 src/main/resources/frontend_static/index.html
  143. +212 −0 src/main/resources/frontend_static/js/main.js
  144. +4,529 −0 src/main/resources/frontend_static/js/runeBuilder.js
  145. +213 −0 src/main/resources/frontend_static/js/script.js
  146. +23 −0 src/main/resources/frontend_static/js/vendor.js
  147. +1 −3 src/main/resources/hibernate.cfg.xml
View
@@ -17,6 +17,8 @@ dependencies {
compile "org.apache.logging.log4j:log4j-api:2.10.0"
compile "org.apache.logging.log4j:log4j-core:2.10.0"
compile "org.hibernate:hibernate-c3p0:5.2.12.Final"
compile "org.eclipse.jetty:jetty-server:9.4.8.v20171121"
compile "com.google.code.gson:gson:2.8.2"
}
jar {
@@ -8,6 +8,7 @@
import com.derpthemeus.runeCoach.databasePopulator.threadSupervisors.SummonerAccountIdUpdaterSupervisor;
import com.derpthemeus.runeCoach.databasePopulator.threadSupervisors.SummonerFinderSupervisor;
import com.derpthemeus.runeCoach.databasePopulator.threadSupervisors.SummonerLeagueUpdaterSupervisor;
import com.derpthemeus.runeCoach.jetty.RuneCoachWebServer;
import no.stelar7.api.l4j8.basic.APICredentials;
import no.stelar7.api.l4j8.impl.L4J8;
import org.hibernate.SessionFactory;
@@ -32,7 +33,7 @@
threadCounts.put(MatchFinderSupervisor.getInstance(), 1);
threadCounts.put(MatchDownloaderSupervisor.getInstance(), 1);
threadCounts.put(StatAggregatorSupervisor.getInstance(), 3);
threadCounts.put(PerkScoreCalculatorSupervisor.getInstance(), 6);
threadCounts.put(PerkScoreCalculatorSupervisor.getInstance(), 7);
l4j8 = new L4J8(new APICredentials(System.getenv("API_KEY"), null));
Configuration config = new Configuration()
@@ -45,7 +46,9 @@
}
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
int port = Integer.parseInt(System.getenv("HTTP_PORT"));
new RuneCoachWebServer(port);
startDatabasePopulators();
}
@@ -8,6 +8,7 @@
import org.hibernate.Transaction;
import org.hibernate.query.Query;
import java.sql.Timestamp;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
@@ -66,6 +67,7 @@ public synchronized AggregatedStatsEntity getStatToAggregate(String patch) {
stat.setChampionId(championId);
stat.setPerkId(perkId);
stat.setPatch(patch);
stat.setLastUpdated(new Timestamp(0));
session.save(stat);
stats.add(stat);
@@ -0,0 +1,73 @@
package com.derpthemeus.runeCoach.jetty;
import com.derpthemeus.runeCoach.DDragonManager;
import com.derpthemeus.runeCoach.RuneCoach;
import com.google.gson.Gson;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.hibernate.Session;
import org.hibernate.query.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ChampionInfoHandler extends AbstractHandler {
// How long data should be cached for (in milliseconds)
private static final int CACHE_TIME = 1000 * 60 * 60;
private final List<String> championIds;
private final Gson gson = new Gson();
// Cached JSON responses for champions. Shorts are champion IDs, Longs are timestamps, Strings are JSON
private final Map<Short, Map.Entry<Long, String>> cache = new HashMap<>();
public ChampionInfoHandler() throws IOException {
DDragonManager.ChampionList champions = DDragonManager.getChampionList(DDragonManager.getLatestVersion());
championIds = champions.data.values().stream().map(champion -> champion.key).collect(Collectors.toList());
}
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (!championIds.contains(request.getParameter("championId"))) {
response.setContentType(MimeTypes.Type.TEXT_PLAIN.asString());
// TODO use a raw message instead of an HTML page
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Error: champion with specified ID does not exist");
baseRequest.setHandled(true);
return;
}
short championId = Short.parseShort(request.getParameter("championId"));
Map.Entry<Long, String> cacheEntry = cache.get(championId);
if (cacheEntry == null || System.currentTimeMillis() - cacheEntry.getKey() > CACHE_TIME) {
try (Session session = RuneCoach.getSessionFactory().openSession()) {
// TODO allow patch to be specified through config, or automatically switch to latest patch once enough data has been aggregated
Query query = session.createQuery("SELECT NEW MAP(perkScore.perkId AS perkId, perkScore.score AS score, perkScore.scoreType AS type)" +
" FROM PerkScoreEntity AS perkScore WHERE patch=:patch AND championId=:championId AND games>200 AND scoreType!='RAW'")
.setParameter("patch", "7.24").setParameter("championId", championId);
List<Map> scores = query.getResultList();
String json = gson.toJson(scores);
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(json);
baseRequest.setHandled(true);
cache.put(championId, new AbstractMap.SimpleEntry<>(System.currentTimeMillis(), json));
}
} else {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(cacheEntry.getValue());
}
baseRequest.setHandled(true);
}
}
@@ -0,0 +1,34 @@
package com.derpthemeus.runeCoach.jetty;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.resource.Resource;
public class RuneCoachWebServer {
private final Server jettyServer;
public RuneCoachWebServer(int port) throws Exception {
jettyServer = new Server(port);
ResourceHandler staticHandler = new ResourceHandler();
staticHandler.setDirectoriesListed(false);
staticHandler.setResourceBase(Resource.newClassPathResource("frontend_static/").toString());
ContextHandler championInfoHandler = new ContextHandler("/getChampionInfo");
championInfoHandler.setHandler(new ChampionInfoHandler());
ContextHandler staticDataHandler = new ContextHandler("/getStaticData");
staticDataHandler.setHandler(new StaticDataHandler());
ContextHandler runesHandler = new ContextHandler("/getRunes");
runesHandler.setHandler(new RunesHandler());
HandlerCollection handlers = new HandlerCollection(
staticHandler, championInfoHandler, staticDataHandler, runesHandler
);
jettyServer.setHandler(handlers);
jettyServer.start();
}
}
@@ -0,0 +1,72 @@
package com.derpthemeus.runeCoach.jetty;
import com.derpthemeus.runeCoach.DDragonManager;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class RunesHandler extends AbstractHandler {
private String cachedResponse;
public RunesHandler() throws IOException {
Gson gson = new Gson();
JsonObject builderRunes = gson.toJsonTree(gson.fromJson(new InputStreamReader(getClass().getResourceAsStream("/builder-runes.json")), Object.class)).getAsJsonObject();
JsonArray lcuRunes = gson.toJsonTree(gson.fromJson(new InputStreamReader(getClass().getResourceAsStream("/LCU-runes.json")), Object.class)).getAsJsonArray();
DDragonManager.StyleInfo[] ddragonRunes = DDragonManager.getRuneInfo(DDragonManager.getLatestVersion());
// Map LCU runes by ID
Map<Integer, JsonObject> lcuMappedRunes = new HashMap<>();
// The first element is a template, not an actual rune
for (int i = 1; i < lcuRunes.size(); i++) {
JsonObject rune = lcuRunes.get(i).getAsJsonObject();
lcuMappedRunes.put(rune.get("id").getAsInt(), rune);
}
builderRunes.getAsJsonArray("styles").forEach(builderStyleEl -> {
JsonObject builderStyle = builderStyleEl.getAsJsonObject();
// Copy style IDs from DDragon
for (DDragonManager.StyleInfo ddragStyle : ddragonRunes) {
if (builderStyle.get("name").getAsString().equals(ddragStyle.name)) {
builderStyle.getAsJsonObject().addProperty("id", ddragStyle.id);
break;
}
}
// Copy formatted descriptions from LCU
builderStyle.getAsJsonArray("slots").forEach(slot -> {
slot.getAsJsonObject().getAsJsonArray("runes").forEach(runeEl -> {
JsonObject builderRune = runeEl.getAsJsonObject();
JsonObject lcuRune = lcuMappedRunes.get(builderRune.get("runeId").getAsInt());
String longDesc = lcuRune.get("longDesc").getAsString();
String shortDesc = lcuRune.get("shortDesc").getAsString();
builderRune.addProperty("longDescription", longDesc);
builderRune.addProperty("shortDescription", shortDesc);
});
});
// TODO bonuses (secondary styles)
});
this.cachedResponse = gson.toJson(builderRunes);
}
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(cachedResponse);
baseRequest.setHandled(true);
}
}
@@ -0,0 +1,79 @@
package com.derpthemeus.runeCoach.jetty;
import com.derpthemeus.runeCoach.DDragonManager;
import com.derpthemeus.runeCoach.RuneCoach;
import com.derpthemeus.runeCoach.hibernate.PerkScoreEntity;
import com.derpthemeus.runeCoach.hibernate.TagEntity;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.hibernate.Session;
import org.hibernate.query.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Returns a champion list, tag list, the best tag for each rune, and announcement messages
*/
public class StaticDataHandler extends AbstractHandler {
private String cachedResponse;
private final Gson gson = new Gson();
private final Logger logger = LogManager.getLogger();
public StaticDataHandler() throws IOException {
updateCachedResponse();
}
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(cachedResponse);
baseRequest.setHandled(true);
}
// TODO automatically update (also requires updating DDragonManager, since it currently caches latest version)
private void updateCachedResponse() throws IOException {
logger.info("Updating static data...");
String ddragVersion = DDragonManager.getLatestVersion();
JsonObject obj = new JsonObject();
obj.addProperty("announcementMessage", System.getenv("ANNOUNCEMENT_MESSAGE"));
obj.addProperty("announcementLink", System.getenv("ANNOUNCEMENT_LINK"));
obj.addProperty("ddragonVersion", ddragVersion);
obj.add("champions", gson.toJsonTree(DDragonManager.getChampionList(ddragVersion).data.values().toArray()));
try (Session session = RuneCoach.getSessionFactory().openSession()) {
// Get tags
Map<Short, TagEntity> tags = new HashMap<>();
for (TagEntity tag : (List<TagEntity>) session.createQuery("FROM TagEntity").getResultList()) {
tags.put(tag.getTagId(), tag);
}
obj.add("tags", gson.toJsonTree(tags));
// Get best tags for each perk
List<PerkScoreEntity> bestTags = new ArrayList<>();
// TODO do some fancy HQL stuff here instead of iterating over perk IDs
for (Short perkId : DDragonManager.getPerkAndStyleIds(DDragonManager.getLatestVersion())) {
// TODO allow patch to be specified through config, or automatically switch to latest patch once enough data has been aggregated
Query query = session.createQuery("SELECT NEW MAP(perkScore.perkId AS perkId, perkScore.score AS score, -perkScore.championId AS tagId) " +
"FROM PerkScoreEntity AS perkScore WHERE games>200 AND championId<0 AND patch=:patch AND scoreType='RELATIVE' AND perkId=:perkId ORDER BY score DESC")
.setParameter("patch", "7.24").setParameter("perkId", perkId);
bestTags.addAll(query.setMaxResults(2).getResultList());
}
obj.add("bestTags", gson.toJsonTree(bestTags));
}
cachedResponse = gson.toJson(obj);
logger.info("Updated static data");
}
}
Oops, something went wrong.

0 comments on commit 17e9ff5

Please sign in to comment.