Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add economy tracking for GE Bank + Big Alchables. #5918

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ model Analytic {
ironMinionsCount Int?
totalSacrificed BigInt?
totalGP BigInt?
totalGeGp BigInt?
totalBigAlchGp BigInt?
dicingBank BigInt?
duelTaxBank BigInt?
dailiesAmount BigInt?
Expand Down
18 changes: 17 additions & 1 deletion src/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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<ActivityGroup, number> = {
Expand Down Expand Up @@ -47,8 +48,21 @@
)
).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 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: { val: bigint }[]) => BigInt(v[0].val));

const taskCounts = await calculateMinionTaskCounts();
const currentClientSettings = await await prisma.clientStorage.findFirst({
const currentClientSettings = await prisma.clientStorage.findFirst({
where: {
id: globalConfig.clientID
},
Expand All @@ -74,7 +88,7 @@
await prisma.analytic.create({
data: {
guildsCount: globalClient.guilds.cache.size,
membersCount: globalClient.guilds.cache.reduce((acc, curr) => (acc += curr.memberCount || 0), 0),

Check warning on line 91 in src/lib/analytics.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Unexpected number value in conditional. An explicit zero/NaN check is required

Check warning on line 91 in src/lib/analytics.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Unexpected number value in conditional. An explicit zero/NaN check is required
timestamp: Math.floor(Date.now() / 1000),
clueTasksCount: taskCounts.Clue,
minigameTasksCount: taskCounts.Minigame,
Expand All @@ -84,6 +98,8 @@
minionsCount: numberOfMinions,
totalSacrificed,
totalGP,
totalGeGp,
totalBigAlchGp: totalDemonStatuetteGp + totalArtifactGp,
dicingBank: currentClientSettings.economyStats_dicingBank,
duelTaxBank: currentClientSettings.economyStats_duelTaxBank,
dailiesAmount: currentClientSettings.economyStats_dailiesAmount,
Expand Down
Loading