add period comparison deltas to analytics stat cards
All checks were successful
deploy / deploy (push) Successful in 1m21s

Each stat card now shows the percentage change vs the equivalent
previous period (e.g. 30d compares last 30 days vs 30 days before).
Handles zero-baseline with "new" label and caps extreme deltas at
>999%. Seed data extended to 2 years for meaningful 12m comparisons.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-23 01:01:25 +00:00
parent 08fcd60eb6
commit 6eda1de1bc
5 changed files with 244 additions and 30 deletions

View File

@@ -1,8 +1,8 @@
# Generates realistic analytics demo data spanning 12 months.
# Generates realistic analytics demo data spanning 2 years.
#
# mix run priv/repo/seeds/analytics.exs
#
# Clears existing analytics events first, then creates ~50k events with
# Clears existing analytics events first, then creates ~90k events with
# realistic traffic patterns, referrers, device mix, and e-commerce funnel.
alias Berrypod.Repo
@@ -13,9 +13,9 @@ alias Berrypod.Analytics.Event
# How many unique "visitors" to simulate per day (base — actual varies by day)
base_daily_visitors = 40
# Date range: 12 months back from today
# Date range: 2 years back from today
end_date = Date.utc_today()
start_date = Date.add(end_date, -364)
start_date = Date.add(end_date, -729)
# ── Reference data ──
@@ -150,8 +150,8 @@ end
# Monthly growth curve — traffic grows over time (new shop ramping up)
month_multiplier = fn date ->
months_ago = Date.diff(end_date, date) / 30.0
# Start at 0.3x and grow to 1.0x over the year
max(0.3, 1.0 - months_ago * 0.06)
# Start at 0.2x two years ago and grow to 1.0x now
max(0.2, 1.0 - months_ago * 0.035)
end
# Seasonal bumps (Nov-Dec holiday shopping, Jan sale)