From b720e32fd3f08fe50605a95b626d0d315421cc6c Mon Sep 17 00:00:00 2001 From: themrrobert <10122432+themrrobert@users.noreply.github.com> Date: Thu, 13 Jun 2024 01:57:17 -0700 Subject: [PATCH 1/2] Add economy tracking for GE Bank + Big Alchables. --- prisma/schema.prisma | 2 ++ src/lib/analytics.ts | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6f946311f6..94ef7691b3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -41,6 +41,8 @@ model Analytic { ironMinionsCount Int? totalSacrificed BigInt? totalGP BigInt? + totalGeGp BigInt? + totalBigAlchGp BigInt? dicingBank BigInt? duelTaxBank BigInt? dailiesAmount BigInt? diff --git a/src/lib/analytics.ts b/src/lib/analytics.ts index be29bc33b8..eb8feca84c 100644 --- a/src/lib/analytics.ts +++ b/src/lib/analytics.ts @@ -2,6 +2,7 @@ import { ActivityGroup, globalConfig } from '../lib/constants'; import { prisma } from '../lib/settings/prisma'; import { GroupMonsterActivityTaskOptions } from '../lib/types/minions'; import { taskGroupFromActivity } from '../lib/util/taskGroupFromActivity'; +import { getItem } from './util/getOSItem'; async function calculateMinionTaskCounts() { const minionTaskCounts: Record = { @@ -47,8 +48,21 @@ export async function analyticsTick() { ) ).map((result: any) => parseInt(result[0].count)) as number[]; + const artifact = getItem('Magical artifact')!; + const statuette = getItem('Demon statuette')!; + + const [totalGeGp, totalArtifactGp, totalDemonStatuetteGp] = ( + await Promise.all( + [ + 'SELECT quantity AS ge_gp FROM ge_bank WHERE item_id = 995', + `SELECT SUM((bank->>'${artifact.id})::bigint) * ${artifact.highalch} as artifact_val`, + `SELECT SUM((bank->>'${statuette.id})::bigint) * ${statuette.highalch} as statuette_val` + ].map(q => prisma.$queryRawUnsafe(q)) + ) + ).map((v: string) => BigInt(v)); + const taskCounts = await calculateMinionTaskCounts(); - const currentClientSettings = await await prisma.clientStorage.findFirst({ + const currentClientSettings = await prisma.clientStorage.findFirst({ where: { id: globalConfig.clientID }, @@ -84,6 +98,8 @@ export async function analyticsTick() { minionsCount: numberOfMinions, totalSacrificed, totalGP, + totalGeGp, + totalBigAlchGp: totalDemonStatuetteGp + totalArtifactGp, dicingBank: currentClientSettings.economyStats_dicingBank, duelTaxBank: currentClientSettings.economyStats_duelTaxBank, dailiesAmount: currentClientSettings.economyStats_dailiesAmount, From 932979656a7d85002612a4ff72ab11c8dc5d43f6 Mon Sep 17 00:00:00 2001 From: themrrobert <10122432+themrrobert@users.noreply.github.com> Date: Thu, 13 Jun 2024 02:18:11 -0700 Subject: [PATCH 2/2] bug fixes --- src/lib/analytics.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/analytics.ts b/src/lib/analytics.ts index eb8feca84c..d43aead457 100644 --- a/src/lib/analytics.ts +++ b/src/lib/analytics.ts @@ -54,12 +54,12 @@ export async function analyticsTick() { const [totalGeGp, totalArtifactGp, totalDemonStatuetteGp] = ( await Promise.all( [ - 'SELECT quantity AS ge_gp FROM ge_bank WHERE item_id = 995', - `SELECT SUM((bank->>'${artifact.id})::bigint) * ${artifact.highalch} as artifact_val`, - `SELECT SUM((bank->>'${statuette.id})::bigint) * ${statuette.highalch} as statuette_val` - ].map(q => prisma.$queryRawUnsafe(q)) + 'SELECT quantity AS val FROM ge_bank WHERE item_id = 995', + `SELECT COALESCE(SUM((bank->>'${artifact.id}')::bigint) * ${artifact.highalch}, 0) as val FROM users WHERE bank->>'${artifact.id}' IS NOT NULL`, + `SELECT COALESCE(SUM((bank->>'${statuette.id}')::bigint) * ${statuette.highalch}, 0) as val FROM users WHERE bank->>'${artifact.id}' IS NOT NULL` + ].map(q => prisma.$queryRawUnsafe<{ val: bigint }[]>(q)) ) - ).map((v: string) => BigInt(v)); + ).map((v: { val: bigint }[]) => BigInt(v[0].val)); const taskCounts = await calculateMinionTaskCounts(); const currentClientSettings = await prisma.clientStorage.findFirst({