From ea3a0d2753463a4d7ab70cf3f3b8d5b7b4f128a8 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 30 Oct 2023 16:08:47 +0000 Subject: [PATCH] many fixes --- src/db/schemas/leaderboard.ts | 10 ++-------- src/services/updateData.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/db/schemas/leaderboard.ts b/src/db/schemas/leaderboard.ts index 8cc7a78..c49c2c8 100644 --- a/src/db/schemas/leaderboard.ts +++ b/src/db/schemas/leaderboard.ts @@ -4,14 +4,8 @@ const { Schema } = mongoose; const leaderboardSchema = new Schema({ _id: String, totalPlays: Number, - countries: { - type: Map, - of: Number, - }, - headsets: { - type: Map, - of: Number, - }, + countries: JSON, + headsets: JSON, }); export const LeaderboardSchema = diff --git a/src/services/updateData.ts b/src/services/updateData.ts index 89316aa..f2c5b2b 100644 --- a/src/services/updateData.ts +++ b/src/services/updateData.ts @@ -76,7 +76,6 @@ async function connectWebsocket() { _id: id, player: { id: player.id, - hmd: hmd, }, mistakes: { badCuts: badCuts, @@ -95,10 +94,13 @@ async function connectWebsocket() { } Score.create(data); // Create the score - const countryId = - normalizedRegionName(player.country?.toLowerCase()) || "unknown"; + + const hmdName = + Headsets.find((h) => h.id.includes(hmd))?.name || "Unknown"; + const countryId = normalizedRegionName(player.country) || "Unknown"; totalCountries[countryId] = (totalCountries[countryId] || 0) + 1; - totalHeadsets[hmd] = (totalHeadsets[hmd] || 0) + 1; + totalHeadsets[hmdName] = (totalHeadsets[hmdName] || 0) + 1; + // Update the leaderboard data in the database await LeaderboardSchema.updateOne( { _id: "scoresaber" }, @@ -121,8 +123,8 @@ async function connectWebsocket() { InfluxWriteAPI.writePoint( new Point("scoresaber") .tag("type", "headsets") - .tag("hmd", Headsets.map((h) => h.name)[hmd]) - .intField("value", totalHeadsets[hmd]) + .tag("hmd", hmdName) + .intField("value", totalHeadsets[hmdName]) .timestamp(new Date()) ); InfluxWriteAPI.writePoint(