After persist the live activity data for welcome3
This commit is contained in:
parent
6cd166b680
commit
8dfb66f842
@ -2786,6 +2786,7 @@ CREATE TABLE IF NOT EXISTS marketing_live_activity_settings (
|
||||
real_active_threshold INT NOT NULL DEFAULT 200 CHECK (real_active_threshold > 0),
|
||||
max_synthetic_entries INT NOT NULL DEFAULT 20 CHECK (max_synthetic_entries >= 0 AND max_synthetic_entries <= 100),
|
||||
display_active_target INT NOT NULL DEFAULT 250 CHECK (display_active_target > 0),
|
||||
display_active_spread INT NOT NULL DEFAULT 40 CHECK (display_active_spread >= 0 AND display_active_spread <= 500),
|
||||
active_window_minutes INT NOT NULL DEFAULT 15 CHECK (active_window_minutes > 0),
|
||||
feed_real_fetch INT NOT NULL DEFAULT 16 CHECK (feed_real_fetch > 0),
|
||||
client_refresh_seconds INT NOT NULL DEFAULT 30 CHECK (client_refresh_seconds >= 10 AND client_refresh_seconds <= 120),
|
||||
@ -2800,7 +2801,7 @@ INSERT INTO marketing_live_activity_settings (id)
|
||||
VALUES (1)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
-- V2: withdrawal feed plafond + configurable amounts (idempotent for existing installs)
|
||||
-- V2: withdrawal feed plafond + amounts + lively counter spread (idempotent)
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
@ -2821,6 +2822,15 @@ BEGIN
|
||||
ADD COLUMN synthetic_withdrawal_amounts INT[] NOT NULL
|
||||
DEFAULT ARRAY[20,35,50,80,100,120,200,250,300,450,500,800];
|
||||
END IF;
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public' AND table_name = 'marketing_live_activity_settings'
|
||||
AND column_name = 'display_active_spread'
|
||||
) THEN
|
||||
ALTER TABLE marketing_live_activity_settings
|
||||
ADD COLUMN display_active_spread INT NOT NULL DEFAULT 40
|
||||
CHECK (display_active_spread >= 0 AND display_active_spread <= 500);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
INSERT INTO marketing_personas (public_id, is_active, sort_order)
|
||||
|
||||
@ -10,6 +10,7 @@ export type MarketingLiveActivitySettingsRow = {
|
||||
real_active_threshold: number;
|
||||
max_synthetic_entries: number;
|
||||
display_active_target: number;
|
||||
display_active_spread: number;
|
||||
active_window_minutes: number;
|
||||
feed_real_fetch: number;
|
||||
client_refresh_seconds: number;
|
||||
@ -25,6 +26,7 @@ export type MarketingLiveActivitySettings = {
|
||||
realActiveThreshold: number;
|
||||
maxSyntheticEntries: number;
|
||||
displayActiveTarget: number;
|
||||
displayActiveSpread: number;
|
||||
activeWindowMinutes: number;
|
||||
feedRealFetch: number;
|
||||
clientRefreshSeconds: number;
|
||||
@ -40,6 +42,7 @@ const DEFAULTS: Omit<MarketingLiveActivitySettings, 'updatedAt'> = {
|
||||
realActiveThreshold: 200,
|
||||
maxSyntheticEntries: 20,
|
||||
displayActiveTarget: 250,
|
||||
displayActiveSpread: 40,
|
||||
activeWindowMinutes: 15,
|
||||
feedRealFetch: 16,
|
||||
clientRefreshSeconds: 30,
|
||||
@ -56,7 +59,6 @@ function parseAmounts(raw: number[] | string | null | undefined): number[] {
|
||||
if (typeof raw === 'string') {
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) return [...DEFAULT_SYNTHETIC_WITHDRAWAL_AMOUNTS];
|
||||
// pg may return "{20,35}" style
|
||||
const inner = trimmed.replace(/^\{|\}$/g, '');
|
||||
return inner
|
||||
.split(',')
|
||||
@ -73,6 +75,7 @@ function mapRow(row: MarketingLiveActivitySettingsRow): MarketingLiveActivitySet
|
||||
realActiveThreshold: Number(row.real_active_threshold) || DEFAULTS.realActiveThreshold,
|
||||
maxSyntheticEntries: Number(row.max_synthetic_entries) || 0,
|
||||
displayActiveTarget: Number(row.display_active_target) || DEFAULTS.displayActiveTarget,
|
||||
displayActiveSpread: Number(row.display_active_spread) || 0,
|
||||
activeWindowMinutes: Number(row.active_window_minutes) || DEFAULTS.activeWindowMinutes,
|
||||
feedRealFetch: Number(row.feed_real_fetch) || DEFAULTS.feedRealFetch,
|
||||
clientRefreshSeconds: Number(row.client_refresh_seconds) || DEFAULTS.clientRefreshSeconds,
|
||||
@ -86,8 +89,9 @@ function mapRow(row: MarketingLiveActivitySettingsRow): MarketingLiveActivitySet
|
||||
}
|
||||
|
||||
const SELECT_COLS = `id, enabled, real_active_threshold, max_synthetic_entries, display_active_target,
|
||||
active_window_minutes, feed_real_fetch, client_refresh_seconds, list_rotate_seconds,
|
||||
cache_ttl_seconds, max_synthetic_withdrawals, synthetic_withdrawal_amounts, updated_at`;
|
||||
display_active_spread, active_window_minutes, feed_real_fetch, client_refresh_seconds,
|
||||
list_rotate_seconds, cache_ttl_seconds, max_synthetic_withdrawals,
|
||||
synthetic_withdrawal_amounts, updated_at`;
|
||||
|
||||
export async function getLiveActivitySettings(): Promise<MarketingLiveActivitySettings> {
|
||||
const rows = await query<MarketingLiveActivitySettingsRow[]>(
|
||||
@ -105,6 +109,7 @@ export type LiveActivitySettingsPatch = Partial<{
|
||||
realActiveThreshold: number;
|
||||
maxSyntheticEntries: number;
|
||||
displayActiveTarget: number;
|
||||
displayActiveSpread: number;
|
||||
activeWindowMinutes: number;
|
||||
feedRealFetch: number;
|
||||
clientRefreshSeconds: number;
|
||||
@ -123,6 +128,7 @@ export async function updateLiveActivitySettings(
|
||||
realActiveThreshold: patch.realActiveThreshold ?? current.realActiveThreshold,
|
||||
maxSyntheticEntries: patch.maxSyntheticEntries ?? current.maxSyntheticEntries,
|
||||
displayActiveTarget: patch.displayActiveTarget ?? current.displayActiveTarget,
|
||||
displayActiveSpread: patch.displayActiveSpread ?? current.displayActiveSpread,
|
||||
activeWindowMinutes: patch.activeWindowMinutes ?? current.activeWindowMinutes,
|
||||
feedRealFetch: patch.feedRealFetch ?? current.feedRealFetch,
|
||||
clientRefreshSeconds: patch.clientRefreshSeconds ?? current.clientRefreshSeconds,
|
||||
@ -143,13 +149,14 @@ export async function updateLiveActivitySettings(
|
||||
real_active_threshold = $2,
|
||||
max_synthetic_entries = $3,
|
||||
display_active_target = $4,
|
||||
active_window_minutes = $5,
|
||||
feed_real_fetch = $6,
|
||||
client_refresh_seconds = $7,
|
||||
list_rotate_seconds = $8,
|
||||
cache_ttl_seconds = $9,
|
||||
max_synthetic_withdrawals = $10,
|
||||
synthetic_withdrawal_amounts = $11::int[],
|
||||
display_active_spread = $5,
|
||||
active_window_minutes = $6,
|
||||
feed_real_fetch = $7,
|
||||
client_refresh_seconds = $8,
|
||||
list_rotate_seconds = $9,
|
||||
cache_ttl_seconds = $10,
|
||||
max_synthetic_withdrawals = $11,
|
||||
synthetic_withdrawal_amounts = $12::int[],
|
||||
updated_at = NOW()
|
||||
WHERE id = 1
|
||||
RETURNING ${SELECT_COLS}`,
|
||||
@ -158,6 +165,7 @@ export async function updateLiveActivitySettings(
|
||||
next.realActiveThreshold,
|
||||
next.maxSyntheticEntries,
|
||||
next.displayActiveTarget,
|
||||
next.displayActiveSpread,
|
||||
next.activeWindowMinutes,
|
||||
next.feedRealFetch,
|
||||
next.clientRefreshSeconds,
|
||||
|
||||
@ -86,19 +86,26 @@ export function shouldUseSynthetic(
|
||||
}
|
||||
|
||||
/**
|
||||
* Title counter: under threshold with fictifs on → approach display target;
|
||||
* otherwise real-only (never inflate official-looking counts past real when disabled).
|
||||
* Title counter: under threshold with fictifs on → lively band below display target
|
||||
* (varies over time so marketing does not look stuck); otherwise real-only.
|
||||
*/
|
||||
export function computeActivePlayersCount(
|
||||
realActive: number,
|
||||
settings: Pick<
|
||||
MarketingLiveActivitySettings,
|
||||
'enabled' | 'realActiveThreshold' | 'displayActiveTarget'
|
||||
>
|
||||
'enabled' | 'realActiveThreshold' | 'displayActiveTarget' | 'displayActiveSpread'
|
||||
>,
|
||||
now = Date.now()
|
||||
): number {
|
||||
if (!shouldUseSynthetic(realActive, settings)) return realActive;
|
||||
const pad = Math.max(0, settings.displayActiveTarget - realActive);
|
||||
return Math.min(realActive + pad, settings.displayActiveTarget);
|
||||
const target = Math.max(1, settings.displayActiveTarget);
|
||||
const spread = Math.max(0, settings.displayActiveSpread);
|
||||
// Band [target - spread, target], never below realActive.
|
||||
const low = Math.max(realActive, target - spread);
|
||||
const high = Math.max(low, target);
|
||||
const range = high - low;
|
||||
if (range <= 0) return high;
|
||||
return low + (slotIndex(now) % (range + 1));
|
||||
}
|
||||
|
||||
/** Playing-only synthetic rows from active DB personas (no Won / no stake emphasis). */
|
||||
|
||||
@ -19,6 +19,7 @@ const defaultSettings = {
|
||||
enabled: true,
|
||||
realActiveThreshold: 200,
|
||||
displayActiveTarget: 250,
|
||||
displayActiveSpread: 40,
|
||||
};
|
||||
|
||||
const personas = [
|
||||
@ -98,9 +99,12 @@ describe('marketingService helpers', () => {
|
||||
assert.equal(shouldUseSynthetic(100, low), false);
|
||||
});
|
||||
|
||||
test('computeActivePlayersCount pads toward display target under threshold', () => {
|
||||
assert.equal(computeActivePlayersCount(50, defaultSettings), 250);
|
||||
assert.equal(computeActivePlayersCount(199, defaultSettings), 250);
|
||||
test('computeActivePlayersCount varies in band below display target', () => {
|
||||
const a = computeActivePlayersCount(50, defaultSettings, 1_700_000_000_000);
|
||||
const b = computeActivePlayersCount(50, defaultSettings, 1_700_000_050_000);
|
||||
assert.ok(a >= 210 && a <= 250);
|
||||
assert.ok(b >= 210 && b <= 250);
|
||||
assert.notEqual(a, b);
|
||||
});
|
||||
|
||||
test('computeActivePlayersCount returns real when at/above threshold or disabled', () => {
|
||||
@ -112,7 +116,12 @@ describe('marketingService helpers', () => {
|
||||
clearMarketingCache();
|
||||
assert.equal(shouldUseSynthetic(50, { ...defaultSettings, enabled: false }), false);
|
||||
assert.equal(shouldUseSynthetic(50, { ...defaultSettings, realActiveThreshold: 40 }), false);
|
||||
assert.equal(computeActivePlayersCount(10, { ...defaultSettings, displayActiveTarget: 80 }), 80);
|
||||
const n = computeActivePlayersCount(10, {
|
||||
...defaultSettings,
|
||||
displayActiveTarget: 80,
|
||||
displayActiveSpread: 0,
|
||||
});
|
||||
assert.equal(n, 80);
|
||||
});
|
||||
|
||||
test('synthetic activity is Playing-only with unique handles from personas', () => {
|
||||
|
||||
@ -238,6 +238,7 @@ export const marketingLiveActivitySettingsBodySchema = atLeastOneField(
|
||||
realActiveThreshold: z.number().int().positive().optional(),
|
||||
maxSyntheticEntries: z.number().int().min(0).max(100).optional(),
|
||||
displayActiveTarget: z.number().int().positive().optional(),
|
||||
displayActiveSpread: z.number().int().min(0).max(500).optional(),
|
||||
activeWindowMinutes: z.number().int().positive().max(1440).optional(),
|
||||
feedRealFetch: z.number().int().positive().max(100).optional(),
|
||||
clientRefreshSeconds: z.number().int().min(10).max(120).optional(),
|
||||
|
||||
@ -34,6 +34,7 @@ type LiveActivitySettings = {
|
||||
realActiveThreshold: number;
|
||||
maxSyntheticEntries: number;
|
||||
displayActiveTarget: number;
|
||||
displayActiveSpread: number;
|
||||
activeWindowMinutes: number;
|
||||
feedRealFetch: number;
|
||||
clientRefreshSeconds: number;
|
||||
@ -97,6 +98,7 @@ export function MarketingAdminPage() {
|
||||
if (settingsQuery.data) {
|
||||
const data = {
|
||||
...settingsQuery.data,
|
||||
displayActiveSpread: settingsQuery.data.displayActiveSpread ?? 40,
|
||||
maxSyntheticWithdrawals: settingsQuery.data.maxSyntheticWithdrawals ?? 12,
|
||||
syntheticWithdrawalAmounts: settingsQuery.data.syntheticWithdrawalAmounts?.length
|
||||
? settingsQuery.data.syntheticWithdrawalAmounts
|
||||
@ -170,6 +172,7 @@ export function MarketingAdminPage() {
|
||||
form.realActiveThreshold !== settingsQuery.data.realActiveThreshold ||
|
||||
form.maxSyntheticEntries !== settingsQuery.data.maxSyntheticEntries ||
|
||||
form.displayActiveTarget !== settingsQuery.data.displayActiveTarget ||
|
||||
form.displayActiveSpread !== settingsQuery.data.displayActiveSpread ||
|
||||
form.activeWindowMinutes !== settingsQuery.data.activeWindowMinutes ||
|
||||
form.feedRealFetch !== settingsQuery.data.feedRealFetch ||
|
||||
form.clientRefreshSeconds !== settingsQuery.data.clientRefreshSeconds ||
|
||||
@ -243,6 +246,18 @@ export function MarketingAdminPage() {
|
||||
helperText={t('admin.marketing.displayActiveTargetHelper')}
|
||||
fullWidth
|
||||
/>
|
||||
<TextField
|
||||
label={t('admin.marketing.displayActiveSpread')}
|
||||
type="number"
|
||||
value={form.displayActiveSpread}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, displayActiveSpread: Number(e.target.value) || 0 })
|
||||
}
|
||||
helperText={t('admin.marketing.displayActiveSpreadHelper')}
|
||||
fullWidth
|
||||
/>
|
||||
</Stack>
|
||||
<Stack direction={{ xs: 'column', md: 'row' }} spacing={2}>
|
||||
<TextField
|
||||
label={t('admin.marketing.maxSyntheticEntries')}
|
||||
type="number"
|
||||
@ -253,8 +268,6 @@ export function MarketingAdminPage() {
|
||||
helperText={t('admin.marketing.maxSyntheticEntriesHelper')}
|
||||
fullWidth
|
||||
/>
|
||||
</Stack>
|
||||
<Stack direction={{ xs: 'column', md: 'row' }} spacing={2}>
|
||||
<TextField
|
||||
label={t('admin.marketing.clientRefreshSeconds')}
|
||||
type="number"
|
||||
@ -332,6 +345,7 @@ export function MarketingAdminPage() {
|
||||
realActiveThreshold: form.realActiveThreshold,
|
||||
maxSyntheticEntries: form.maxSyntheticEntries,
|
||||
displayActiveTarget: form.displayActiveTarget,
|
||||
displayActiveSpread: form.displayActiveSpread,
|
||||
activeWindowMinutes: form.activeWindowMinutes,
|
||||
feedRealFetch: form.feedRealFetch,
|
||||
clientRefreshSeconds: form.clientRefreshSeconds,
|
||||
|
||||
@ -2172,7 +2172,10 @@ export const en = {
|
||||
realActiveThreshold: 'Real active threshold',
|
||||
realActiveThresholdHelper: 'Use synthetics only while real distinct players are below this count',
|
||||
displayActiveTarget: 'Display active target',
|
||||
displayActiveTargetHelper: 'Title counter target when synthetics are active',
|
||||
displayActiveTargetHelper: 'Ceiling for the title counter when synthetics are active',
|
||||
displayActiveSpread: 'Display active spread',
|
||||
displayActiveSpreadHelper:
|
||||
'How much the Playing count wanders below the target over time (e.g. target 250 + spread 40 → ~210–250)',
|
||||
maxSyntheticEntries: 'Max synthetic entries',
|
||||
maxSyntheticEntriesHelper: 'Cap of fictive rows added to the Playing list',
|
||||
clientRefreshSeconds: 'Client refresh (seconds)',
|
||||
|
||||
@ -2192,7 +2192,10 @@ export const fr = {
|
||||
realActiveThresholdHelper:
|
||||
'Utiliser les fictifs seulement si les joueurs distincts réels sont sous ce seuil',
|
||||
displayActiveTarget: 'Cible compteur affiché',
|
||||
displayActiveTargetHelper: 'Cible du compteur titre quand les fictifs sont actifs',
|
||||
displayActiveTargetHelper: 'Plafond du compteur titre quand les fictifs sont actifs',
|
||||
displayActiveSpread: 'Variation du compteur',
|
||||
displayActiveSpreadHelper:
|
||||
'Amplitude sous la cible au fil du temps (ex. cible 250 + variation 40 → ~210–250)',
|
||||
maxSyntheticEntries: 'Max entrées synthétiques',
|
||||
maxSyntheticEntriesHelper: 'Plafond de lignes fictives ajoutées à la liste Playing',
|
||||
clientRefreshSeconds: 'Refresh client (secondes)',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user