games_app/backend/src/utils/analyticsDashboardFallbacks.ts
2026-06-29 15:01:23 +02:00

155 lines
3.4 KiB
TypeScript

/** Safe empty payloads when a dashboard subsection fails or times out. */
const emptySegment = () => ({
users: 0,
predictions: 0,
stakeRaw: 0,
netPnlRaw: 0,
winRate: 0,
});
const emptyMoneyKpi = () => ({
totalAmountRaw: 0,
totalCount: 0,
uniqueUsers: 0,
averagePerUserRaw: 0,
maxAmountRaw: 0,
});
export const dashboardFallbacks = {
users: {
totalUsers: 0,
newUsers: 0,
activeUsers: 0,
inactiveUsers: 0,
signupGrowthRate: 0,
onlineNow: 0,
onlineInApp: 0,
adminCount: 0,
},
deposits: emptyMoneyKpi(),
withdrawals: emptyMoneyKpi(),
bonuses: {
totalAmountRaw: 0,
uniqueUsers: 0,
averagePerUserRaw: 0,
byType: { manualBonusRaw: 0, referralCommissionRaw: 0 },
},
adjustments: {
uniqueUsers: 0,
totalAmountRaw: 0,
averageRaw: 0,
},
balances: {
mainWalletRaw: 0,
bonusWalletRaw: 0,
testWalletRaw: 0,
totalRaw: 0,
distribution: [] as { kind: string; amountRaw: number }[],
},
performance: {
platformNetPnlRaw: 0,
platformNetPnlTestRaw: 0,
bonusCostRaw: 0,
adjustmentCostRaw: 0,
depositWithdrawalRatio: null as number | null,
},
games: {
participation: {
uniqueParticipants: 0,
totalPredictions: 0,
avgPredictionsPerUser: 0,
totalStakeRaw: 0,
},
manual: emptySegment(),
auto: emptySegment(),
multiCandle: emptySegment(),
testWallet: { uniqueUsers: 0, totalStakeRaw: 0, netPnlRaw: 0 },
cross: {
realManual: emptySegment(),
realAuto: emptySegment(),
realMulti: emptySegment(),
testManual: emptySegment(),
testAuto: emptySegment(),
testMulti: emptySegment(),
},
},
security: {
emailVerified: 0,
emailUnverified: 0,
totpEnabled: 0,
totpDisabled: 0,
suspendedAccounts: 0,
disabledAccounts: 0,
expiredAccounts: 0,
credentialsExpired: 0,
underSurveillance: 0,
withdrawalsBlocked: 0,
},
activity: {
activeToday: 0,
activeThisWeek: 0,
activeThisMonth: 0,
inactiveInPeriod: 0,
},
recentLogins: [] as { userId: string; name: string; loggedAt: string }[],
geography: [] as {
country: string;
users: number;
depositsRaw: number;
withdrawalsRaw: number;
netPnlRaw: number;
activeUsers: number;
}[],
demographics: {
byGender: [] as {
gender: string;
users: number;
stakeRaw: number;
netPnlRaw: number;
depositsRaw: number;
}[],
byAge: [] as {
ageBucket: string;
users: number;
stakeRaw: number;
netPnlRaw: number;
depositsRaw: number;
}[],
},
charts: {
signups: [],
activeUsers: [],
verifiedUsers: [],
totpEnabled: [],
deposits: [],
withdrawals: [],
bonuses: [],
adjustments: [],
netPnl: [],
predictionsManual: [],
predictionsAuto: [],
predictionsMultiCandle: [],
shortVsLong: [],
byInterval: [],
loginHours: [],
betHours: [],
retention: { newUsers: 0, returningUsers: 0 },
},
alerts: {
openAlertsCount: 0,
failedLoginAlerts: 0,
depositSpike: { currentRaw: 0, previousRaw: 0, spikePercent: 0, isUnusual: false },
withdrawalSpike: { currentRaw: 0, previousRaw: 0, spikePercent: 0, isUnusual: false },
recentAlerts: [] as {
id: string;
type: string;
severity: string;
status: string;
userId: string | null;
createdAt: string;
}[],
},
settings: { allow_withdrawals: true },
};