feat(enakgame): budget controller recommendations and analytics
EnakGame phase 9 of docs/tasks-enakgame.md (EG-901 to EG-903). Budget Controller (EG-901, EG-902) - GET /marketing/enakgame/budgets/:id/recommendation, GLOBAL budgets only: the multiplier (budget − realized) / (forecast − realized), within one step of 1, rounded down to two decimals, either way. Shows each game's new rules. - POST .../recommendation/accept with the multiplier the admin saw: recomputed in the transaction, then one new ACTIVE version per game, the old one RETIRED, audited with source budget_controller and RECOMMENDATION_ACCEPTED on the budget. - Migration 000112: base_config_id, multiplier and budget_id on game_reward_configs. Rules are always scaled from the admin's last version, so rounding does not compound and min/max are against what the admin set. - Guardrails in game_budgets.thresholds: max_step_percent 10, min/max multiplier 50-150%, cooldown_days 7 per organization. Provisional pending RFC §19.2 #4. - RewardCalculator.Scale for the four reward types: amounts only, rounded down. Analytics (EG-903) - GET /marketing/enakgame/analytics/games and /analytics/economy over a range of Asia/Jakarta days (at most 366), from game_sessions and the wallet ledger. - Migrations 000113 (game_sessions by organization and start) and 000114 (wallet_transactions by organization and time, CONCURRENTLY). The Postgres tests for accepting and analytics were not run: no test database here. Migrations 000112-000114 have not been run anywhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
798a36bd6c
commit
296708244e
@@ -0,0 +1,7 @@
|
||||
DROP INDEX IF EXISTS idx_game_reward_configs_controller;
|
||||
|
||||
ALTER TABLE game_reward_configs
|
||||
DROP CONSTRAINT IF EXISTS chk_game_reward_configs_controller,
|
||||
DROP COLUMN IF EXISTS budget_id,
|
||||
DROP COLUMN IF EXISTS multiplier,
|
||||
DROP COLUMN IF EXISTS base_config_id;
|
||||
@@ -0,0 +1,19 @@
|
||||
-- Reward configurations made by accepting a Budget Controller recommendation
|
||||
-- (docs/rfc-enakgame.md §10, PRD §29–§31). Such a version scales the amounts of the
|
||||
-- version an admin wrote last, its base, so a run of adjustments never compounds its
|
||||
-- rounding and min/max multiplier are measured against what the admin set. A version
|
||||
-- an admin writes has none of the three, and becomes the base of the next adjustments.
|
||||
ALTER TABLE game_reward_configs
|
||||
ADD COLUMN base_config_id UUID REFERENCES game_reward_configs(id),
|
||||
-- Applied to every amount of the base, rounded down: 0.8100 pays 81%.
|
||||
ADD COLUMN multiplier NUMERIC(6,4),
|
||||
-- The global budget whose recommendation was accepted.
|
||||
ADD COLUMN budget_id UUID REFERENCES game_budgets(id),
|
||||
ADD CONSTRAINT chk_game_reward_configs_controller CHECK (
|
||||
(base_config_id IS NULL AND multiplier IS NULL AND budget_id IS NULL)
|
||||
OR (base_config_id IS NOT NULL AND multiplier > 0 AND budget_id IS NOT NULL AND effective_at IS NOT NULL));
|
||||
|
||||
-- The last adjustment of an organization, for the cooldown. effective_at is when the
|
||||
-- Budget Controller made it, by the application clock.
|
||||
CREATE INDEX idx_game_reward_configs_controller
|
||||
ON game_reward_configs(organization_id, effective_at DESC) WHERE budget_id IS NOT NULL;
|
||||
@@ -0,0 +1 @@
|
||||
DROP INDEX IF EXISTS idx_game_sessions_org_started;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- EnakGame analytics read an organization's sessions by start time
|
||||
-- (docs/tasks-enakgame.md EG-903).
|
||||
CREATE INDEX IF NOT EXISTS idx_game_sessions_org_started ON game_sessions(organization_id, started_at);
|
||||
@@ -0,0 +1 @@
|
||||
DROP INDEX CONCURRENTLY IF EXISTS idx_wallet_transactions_org_created;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- EnakGame economy analytics sum an organization's ledger over a date range
|
||||
-- (docs/tasks-enakgame.md EG-903). One statement, for CONCURRENTLY.
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_wallet_transactions_org_created ON wallet_transactions(organization_id, created_at);
|
||||
Reference in New Issue
Block a user