diff --git a/src/headsets.ts b/src/headsets.ts new file mode 100644 index 0000000..12ebe52 --- /dev/null +++ b/src/headsets.ts @@ -0,0 +1,26 @@ +export const Headsets = [ + { + id: [-1], + name: "Unknown", + }, + { + id: [64], + name: "Valve Index", + }, + { + id: [32], + name: "Oculus Quest", + }, + { + id: [16], + name: "Rift S", + }, + { + id: [1], + name: "Rift CV1", + }, + { + id: [2], + name: "Vive", + }, +]; diff --git a/src/services/updateData.ts b/src/services/updateData.ts index f6c2583..61cffd3 100644 --- a/src/services/updateData.ts +++ b/src/services/updateData.ts @@ -5,6 +5,8 @@ import { InfluxWriteAPI } from ".."; import { connectMongo } from "../db/mongo"; import { LeaderboardSchema } from "../db/schemas/leaderboard"; import { Score } from "../db/schemas/score"; +import { Headsets } from "../headsets"; +import { normalizedRegionName } from "../utils/regionUtils"; async function update() { const response = await axios.get("https://scoresaber.com/api/players/count"); @@ -93,7 +95,8 @@ async function connectWebsocket() { } Score.create(data); - const countryId = player.country?.toLowerCase() || "unknown"; + const countryId = + normalizedRegionName(player.country?.toLowerCase()) || "unknown"; totalCountries[countryId] = (totalCountries[countryId] || 0) + 1; totalHeadsets[hmd] = (totalHeadsets[hmd] || 0) + 1; await LeaderboardSchema.updateOne( @@ -116,7 +119,7 @@ async function connectWebsocket() { InfluxWriteAPI.writePoint( new Point("scoresaber") .tag("type", "headsets") - .tag("hmd", hmd) + .tag("hmd", Headsets.map((h) => h.name)[hmd]) .intField("value", totalHeadsets[hmd]) .timestamp(new Date()) ); diff --git a/src/utils/regionUtils.ts b/src/utils/regionUtils.ts new file mode 100644 index 0000000..632a4f1 --- /dev/null +++ b/src/utils/regionUtils.ts @@ -0,0 +1,11 @@ +let regionNames = new Intl.DisplayNames(["en"], { type: "region" }); + +/** + * Returns the normalized region name + * + * @param region the region to normalize + * @returns the normalized region name + */ +export function normalizedRegionName(region: string) { + return regionNames.of(region); +}