get actual heaset name and get long region name
Some checks failed
deploy / deploy (push) Failing after 31s

This commit is contained in:
Lee 2023-10-30 15:45:35 +00:00
parent 9984b416b6
commit 41661059a0
3 changed files with 42 additions and 2 deletions

26
src/headsets.ts Normal file

@ -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",
},
];

@ -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())
);

11
src/utils/regionUtils.ts Normal file

@ -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);
}