diff --git a/frontend/server/api/champion/[id].js b/frontend/server/api/champion/[alias].js
similarity index 84%
rename from frontend/server/api/champion/[id].js
rename to frontend/server/api/champion/[alias].js
index 7169d98..686d18b 100644
--- a/frontend/server/api/champion/[id].js
+++ b/frontend/server/api/champion/[alias].js
@@ -12,19 +12,19 @@ async function fetchLatestPatch(client) {
const latestPatch = await patches.find().limit(1).sort({date:-1}).next()
return latestPatch.patch
}
-async function championInfos(client, patch, championId) {
+async function championInfos(client, patch, championAlias) {
const database = client.db("champions");
const collection = database.collection(patch);
- const query = { id:Number(championId) };
+ const query = { alias:championAlias };
const championInfo = await collection.findOne(query);
return championInfo
}
export default defineEventHandler(async (event) => {
- const championId = getRouterParam(event, "id")
+ const championAlias = getRouterParam(event, "alias").toLowerCase()
const client = await connectToDatabase();
const latestPatch = await fetchLatestPatch(client);
- const data = await championInfos(client, latestPatch, championId);
+ const data = await championInfos(client, latestPatch, championAlias);
await client.close()
return data
})
diff --git a/match_collector/champion_stat.ts b/match_collector/champion_stat.ts
index 151fce8..ce36d6c 100644
--- a/match_collector/champion_stat.ts
+++ b/match_collector/champion_stat.ts
@@ -29,8 +29,14 @@ type Builds = {
boots: Array<{data: number, count: number}>
lateGame: Array<{data: number, count: number}>
}
+type Champion = {
+ id: Number
+ name: String
+ alias: String
+}
-async function championInfos(client, patch: number, championId: number) {
+async function championInfos(client, patch: number, champion: Champion) {
+ const championId = champion.id
const database = client.db("matches");
const matches = database.collection(patch)
const allMatches = matches.find()
@@ -181,7 +187,9 @@ async function championInfos(client, patch: number, championId: number) {
builds.bootsFirst /= (winningMatches + losingMatches)
builds.lateGame.sort((a, b) => b.count - a.count)
- return {id: championId,
+ return {name: champion.name,
+ alias: champion.alias.toLowerCase(),
+ id: championId,
winrate:winningMatches / (winningMatches + losingMatches),
gameCount:(winningMatches + losingMatches),
pickrate:(winningMatches + losingMatches)/totalMatches,
@@ -190,8 +198,8 @@ async function championInfos(client, patch: number, championId: number) {
};
}
-async function makeChampionStat(client, patch, championId) {
- const championInfo = await championInfos(client, patch, championId)
+async function makeChampionStat(client, patch : number, champion : Champion) {
+ const championInfo = await championInfos(client, patch, champion)
const database = client.db("champions")
const collection = database.collection(patch)
await collection.updateOne({id: championInfo.id}, {$set: championInfo}, { upsert: true })
@@ -203,7 +211,7 @@ async function championList() {
return list.slice(1)
}
-async function makeChampionsStats(client, patch) {
+async function makeChampionsStats(client, patch : number) {
var globalItems = await itemList()
for(let item of globalItems) {
itemDict.set(item.id, item)
@@ -214,13 +222,14 @@ async function makeChampionsStats(client, patch) {
let i = 0;
for(let champion of list) {
console.log("Entry " + i + "/" + list.length + " (" + champion.name + ")...")
- await makeChampionStat(client, patch, champion.id)
+ await makeChampionStat(client, patch, champion)
i += 1
}
const database = client.db("champions")
const collection = database.collection(patch)
await collection.createIndex({id:1})
+ await collection.createIndex({alias:1})
}
export default {makeChampionsStats}