Branchwell

Graphley / app · graphley.ai / design / app-store / make-demo-workspace.py

1#!/usr/bin/env python3
2"""Writes a fictional Graphley workspace folder (workspace.json and data.json) for App Store screenshots.
3
4Usage: python3 design/app-store/make-demo-workspace.py <folder>
5Debug builds read it with GRAPHLEY_DEMO_WORKSPACE=<folder>. Every site, app and review here is made up, so
6screenshots never show real numbers. Nothing here ships in the app. The newest day is yesterday.
7"""
8import datetime as dt
9import json
10import math
11import pathlib
12import random
13import sys
14
15ANCHOR = dt.date.today() - dt.timedelta(days=1) # newest day: yesterday
16DAYS = 180 # 90 days on screen plus the 90 before, so every delta has a previous period
17random.seed(20261126)
18
19
20# id, name, url, colour index, visitors per day now, visitors per day 180 days ago, weekend factor,
21# page views per session, key events (event -> share of visitors), top pages
22SITES = [
23 ("harbor-notes", "Harbor Notes", "https://harbornotes.app", 0, 410, 260, 0.72, 2.1,
24 {"mac_installer_download": 0.031, "app_store_click": 0.022},
25 ["/", "/download", "/features", "/pricing-free", "/help/sync", "/changelog", "/blog/quiet-notes", "/privacy"]),
26 ("field-guide", "Field Guide", "https://fieldguide.blog", 1, 270, 210, 1.25, 1.6,
27 {"newsletter_click": 0.018},
28 ["/", "/trails/coastal-loop", "/gear/rain-shells", "/trails/ridge-walk", "/guides/first-overnight", "/about", "/trails/tide-flats", "/newsletter"]),
29 ("tidepool", "Tidepool", "https://tidepool.app", 2, 150, 35, 1.10, 1.8,
30 {"app_store_click": 0.064},
31 ["/", "/tide-tables", "/widgets", "/support", "/press", "/privacy", "/stations", "/changelog"]),
32 ("lantern-docs", "Lantern Docs", "https://lanterndocs.dev", 3, 118, 130, 0.45, 3.4,
33 {"source_click": 0.04},
34 ["/", "/docs/getting-started", "/docs/config", "/docs/cli", "/docs/themes", "/docs/deploy", "/blog/v2", "/docs/faq"]),
35 ("driftwood", "Driftwood", "https://driftwood.studio", 4, 52, 30, 0.80, 2.0,
36 {"mac_installer_download": 0.058},
37 ["/", "/download", "/gallery", "/shortcuts", "/help", "/changelog", "/privacy", "/press"]),
38]
39
40# Short bursts on top of the trend: (site, days ago the burst starts, extra visitors on day one, decay per day)
41BURSTS = [("tidepool", 44, 520, 0.72), ("field-guide", 19, 900, 0.55), ("harbor-notes", 72, 380, 0.65), ("driftwood", 9, 140, 0.6)]
42
43# id, name, site, platforms, downloads per day now, share per platform, rating, ratings count now
44APPS = [
45 ("6400000101", "Tidepool: Tide Times & Charts", "tidepool", ["iPhone", "iPad"], 34, {"iPhone": 0.76, "iPad": 0.24}, 4.8, 212),
46 ("6400000102", "Harbor Notes: Quiet Notebook", "harbor-notes", ["iPhone", "iPad", "Mac", "Mac (website)"], 21, {"iPhone": 0.48, "iPad": 0.14, "Mac": 0.38}, 4.6, 148),
47 ("mac-driftwood", "Driftwood", "driftwood", ["Mac (website)"], 0, {}, None, 0),
48]
49
50CHANNELS = [("Organic Search", 0.41), ("Direct", 0.27), ("Referral", 0.14), ("Organic Social", 0.11), ("Email", 0.04), ("Unassigned", 0.03)]
51SOURCES = [("google / organic", 0.36), ("(direct) / (none)", 0.27), ("duckduckgo / organic", 0.05), ("news.ycombinator.com / referral", 0.06),
52 ("reddit.com / referral", 0.05), ("bing / organic", 0.04), ("mastodon.social / referral", 0.04), ("newsletter / email", 0.04)]
53
54REVIEWS = [
55 ("6400000101", 5, "Finally a calm tide app", "Opens straight to today's tides for my beach. The widget is perfect.", "jmoss", 3),
56 ("6400000101", 5, "Beautiful charts", "Clear, quick and no clutter. Exactly what I wanted on the boat.", "Kelp & Co", 11),
57 ("6400000102", 4, "Lovely on the Mac", "Syncs between my Mac and iPad without a fuss. Wish it had tags.", "pmw", 6),
58 ("6400000101", 5, "Great for surf checks", "I check it every morning before work.", "dawnpatrol", 21),
59 ("6400000102", 5, "Quiet in the best way", "Notes that get out of the way. Fast search.", "ellen.r", 27),
60]
61
62
63def day(offset):
64 return (ANCHOR - dt.timedelta(days=offset)).isoformat()
65
66
67def wobble(scale):
68 return random.gauss(1.0, scale)
69
70
71def visitors(site, offset):
72 sid, _, _, _, now, then, weekend, *_ = site
73 t = 1 - offset / (DAYS - 1) # 0 at the oldest day, 1 at the newest
74 base = then + (now - then) * (t ** 1.3)
75 weekday = (ANCHOR - dt.timedelta(days=offset)).weekday()
76 if weekday >= 5:
77 base *= weekend
78 base *= 1 + 0.05 * math.sin(offset / 6.5)
79 for bid, start, extra, decay in BURSTS:
80 if bid == sid and offset <= start:
81 base += extra * decay ** (start - offset)
82 return max(3, round(base * wobble(0.08)))
83
84
85def main():
86 points = []
87
88 def add(d, subject, metric, value, breakdown=None, event=None):
89 p = {"day": d, "subject": subject, "metric": metric, "value": float(value)}
90 if breakdown:
91 p["breakdown"] = breakdown
92 if event:
93 p["event"] = event
94 points.append(p)
95
96 sites_json = []
97 for site in SITES:
98 sid, name, url, color, _, _, _, ppv, events, pages = site
99 sites_json.append({"id": sid, "name": name, "url": url, "colorIndex": color, "archived": False})
100 last30_views = 0
101 for offset in range(DAYS - 1, -1, -1):
102 d = day(offset)
103 users = visitors(site, offset)
104 sessions = round(users * random.uniform(1.18, 1.36))
105 views = round(sessions * ppv * wobble(0.06))
106 add(d, sid, "users", users)
107 add(d, sid, "newUsers", round(users * random.uniform(0.62, 0.78)))
108 add(d, sid, "sessions", sessions)
109 add(d, sid, "pageViews", views)
110 add(d, sid, "engagedSessions", round(sessions * random.uniform(0.48, 0.62)))
111 for event, share in events.items():
112 n = sum(1 for _ in range(users) if random.random() < share)
113 if n:
114 add(d, sid, "keyEvent", n, event=event)
115 if offset < 30:
116 last30_views += views
117 # Window totals (last 30 days), stored on the newest day like a real refresh.
118 weights = [1 / (i + 1.4) ** 1.05 for i in range(len(pages))]
119 for path, w in zip(pages, weights):
120 add(day(0), sid, "pageViews", round(last30_views * w / sum(weights) * 0.92), breakdown="page:" + path)
121 sessions30 = sum(p["value"] for p in points if p["subject"] == sid and p["metric"] == "sessions" and "breakdown" not in p and p["day"] >= day(29))
122 for label, share in CHANNELS:
123 add(day(0), sid, "sessions", round(sessions30 * share * wobble(0.12)), breakdown="channel:" + label)
124 for label, share in SOURCES:
125 add(day(0), sid, "sessions", round(sessions30 * share * wobble(0.15)), breakdown="source:" + label)
126
127 apps_json = []
128 for aid, name, site, platforms, per_day, shares, rating, count in APPS:
129 app = {"id": aid, "name": name, "siteID": site, "platforms": platforms, "onAppStore": not aid.startswith("mac-")}
130 apps_json.append(app)
131 if not shares:
132 continue
133 for offset in range(DAYS - 1, -1, -1):
134 d = day(offset)
135 t = 1 - offset / (DAYS - 1)
136 base = per_day * (0.35 + 0.65 * t)
137 for bid, start, extra, decay in BURSTS:
138 if bid == site and offset <= start:
139 base += extra * 0.04 * decay ** (start - offset)
140 total = 0
141 for platform, share in shares.items():
142 n = max(0, round(base * share * wobble(0.22)))
143 total += n
144 add(d, aid, "appDownloads", n, breakdown="platform:" + platform)
145 add(d, aid, "appDownloads", total)
146 add(d, aid, "appRedownloads", max(0, round(total * random.uniform(0.08, 0.16))))
147 if offset % 7 == 0: # ratings are read once a day; weekly is plenty here
148 add(d, aid, "ratingCount", round(count * (0.55 + 0.45 * t)))
149 add(d, aid, "rating", round(rating - 0.1 * (1 - t), 2))
150
151 reviews_json = [{
152 "id": f"demo-review-{i}", "appID": aid, "appName": next(a[1] for a in APPS if a[0] == aid), "country": "us", "stars": stars,
153 "title": title, "text": text, "version": "2.3", "author": author, "date": day(ago), "firstSeen": day(ago), "url": "https://graphley.ai",
154 } for i, (aid, stars, title, text, author, ago) in enumerate(REVIEWS)]
155
156 def widget(wid, title, kind, metric="users", days=30, breakdown=None, event=None, wide=None, items=None, subtitle=None):
157 w = {"id": wid, "title": title, "kind": kind, "metric": metric, "subjects": [], "days": days}
158 for k, v in (("breakdown", breakdown), ("event", event), ("wide", wide), ("items", items), ("subtitle", subtitle)):
159 if v is not None:
160 w[k] = v
161 return w
162
163 dashboards = [
164 {"id": "overview", "name": "Portfolio", "widgets": [
165 widget("kpis", "Last 30 days", "kpiRow", items=["visitors", "appDownloads", "macInstaller", "appStoreButton"], subtitle="Each vs the 30 days before"),
166 widget("visitors", "Visitors, all sites", "stackedArea", subtitle="Stacked by site"),
167 widget("downloads", "App Store downloads", "stackedBars", "appDownloads", breakdown="platform", wide=False, subtitle="By platform"),
168 widget("installer", "Mac installer downloads", "stackedBars", "keyEvent", event="mac_installer_download", wide=False, subtitle="Real .dmg downloads, by site"),
169 ]},
170 {"id": "app-store", "name": "App downloads", "widgets": [
171 widget("platforms", "Downloads by app and platform", "appPlatforms", "appDownloads", subtitle="App Store Connect, plus the Mac installer from each app's site"),
172 widget("per-day", "App Store downloads per day", "stackedBars", "appDownloads", breakdown="platform", wide=False),
173 widget("ratings", "Ratings and reviews", "ratings", "rating", wide=False, subtitle="Every storefront"),
174 ]},
175 ]
176
177 refreshed = dt.datetime.now(dt.timezone.utc).replace(microsecond=0) - dt.timedelta(hours=1)
178 workspace = {
179 "sites": sites_json, "apps": apps_json, "socials": [], "dashboards": dashboards, "agentLog": [],
180 "reviews": reviews_json,
181 "settings": {"refreshHour": 9, "agentsCanWrite": True, "agentsCanSetKeys": False, "shareWithIPhone": True,
182 "lastRefreshAt": refreshed.isoformat().replace("+00:00", "Z")},
183 }
184 out = pathlib.Path(sys.argv[1])
185 out.mkdir(parents=True, exist_ok=True)
186 (out / "workspace.json").write_text(json.dumps(workspace, sort_keys=True))
187 (out / "data.json").write_text(json.dumps(points, separators=(",", ":"), sort_keys=True))
188 print(f"wrote {out}: {len(points)} points")
189
190if __name__ == "__main__":
191 main()