Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
refactor(reddit): move analytics into named helpers
spacesdrive4aa8e6da7239
diff --git a/backend/services/fixtures/reddit.errors.golden.json b/backend/services/fixtures/reddit.errors.golden.jsonnew file mode 100644index 0000000..543e5aa--- /dev/null+++ b/backend/services/fixtures/reddit.errors.golden.json@@ -0,0 +1,23 @@+[+ {+ "error": "Reddit user not found - check the username"+ },+ {+ "error": "Session cookie is invalid or expired - open reddit.com in your browser, copy a fresh reddit_session value from DevTools (Application > Cookies > reddit.com), delete this account, and re-add it"+ },+ {+ "error": "Reddit rate limit hit - try again in a moment"+ },+ {+ "error": "Reddit API 500: Server Error"+ },+ {+ "error": "Bad request"+ },+ {+ "error": "Reddit API error"+ },+ {+ "value": "[undefined]"+ }+]diff --git a/backend/services/fixtures/reddit.posts.golden.json b/backend/services/fixtures/reddit.posts.golden.jsonnew file mode 100644index 0000000..ebe7447--- /dev/null+++ b/backend/services/fixtures/reddit.posts.golden.json@@ -0,0 +1,177 @@+{+ "posts": [+ {+ "id": "a",+ "title": "Self post",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 10,+ "upvoteRatio": 0.9,+ "numComments": 3,+ "url": "https://reddit.com/a",+ "permalink": "https://reddit.com/r/webdev/comments/a/self/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-07-25T17:20:00.000Z",+ "flair": "Discussion",+ "awardsCount": 1+ },+ {+ "id": "b",+ "title": "Video",+ "subreddit": "videos",+ "subredditPrefixed": "r/videos",+ "score": 0,+ "upvoteRatio": 0,+ "numComments": 0,+ "url": "",+ "permalink": "https://reddit.com/r/videos/comments/b/v/",+ "thumbnail": "https://thumb/b.jpg",+ "mediaType": "video",+ "isSelf": false,+ "isVideo": true,+ "isNsfw": true,+ "createdAt": "2026-07-26T21:06:40.500Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "c",+ "title": "Image",+ "subreddit": "pics",+ "subredditPrefixed": "r/pics",+ "score": 0,+ "upvoteRatio": 0,+ "numComments": 0,+ "url": "",+ "permalink": "https://reddit.com/r/pics/comments/c/i/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "d",+ "title": "Link",+ "subreddit": "news",+ "subredditPrefixed": "r/news",+ "score": 0,+ "upvoteRatio": 0,+ "numComments": 0,+ "url": "",+ "permalink": "https://reddit.com/r/news/comments/d/l/",+ "thumbnail": "",+ "mediaType": "link",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "e",+ "title": "Bare",+ "subreddit": "misc",+ "subredditPrefixed": "r/misc",+ "score": 0,+ "upvoteRatio": 0,+ "numComments": 0,+ "url": "",+ "permalink": "https://reddit.com/r/misc/comments/e/b/",+ "thumbnail": "",+ "mediaType": "link",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "",+ "flair": "",+ "awardsCount": 0+ }+ ],+ "limited": [+ {+ "id": "a",+ "title": "Self post",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 10,+ "upvoteRatio": 0.9,+ "numComments": 3,+ "url": "https://reddit.com/a",+ "permalink": "https://reddit.com/r/webdev/comments/a/self/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-07-25T17:20:00.000Z",+ "flair": "Discussion",+ "awardsCount": 1+ },+ {+ "id": "b",+ "title": "Video",+ "subreddit": "videos",+ "subredditPrefixed": "r/videos",+ "score": 0,+ "upvoteRatio": 0,+ "numComments": 0,+ "url": "",+ "permalink": "https://reddit.com/r/videos/comments/b/v/",+ "thumbnail": "https://thumb/b.jpg",+ "mediaType": "video",+ "isSelf": false,+ "isVideo": true,+ "isNsfw": true,+ "createdAt": "2026-07-26T21:06:40.500Z",+ "flair": "",+ "awardsCount": 0+ }+ ],+ "requests": [+ {+ "url": "https://www.reddit.com/user/ribbon/submitted.json?limit=100&sort=new",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json",+ "Cookie": "reddit_session=COOKIE"+ }+ },+ {+ "url": "https://www.reddit.com/user/ribbon/submitted.json?limit=97&sort=new&after=t3_c",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json",+ "Cookie": "reddit_session=COOKIE"+ }+ },+ {+ "url": "https://www.reddit.com/user/ribbon/submitted.json?limit=95&sort=new&after=t3_e",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json",+ "Cookie": "reddit_session=COOKIE"+ }+ },+ {+ "url": "https://www.reddit.com/user/ribbon/submitted.json?limit=2&sort=new",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json",+ "Cookie": "reddit_session=COOKIE"+ }+ }+ ]+}diff --git a/backend/services/fixtures/reddit.profile.golden.json b/backend/services/fixtures/reddit.profile.golden.jsonnew file mode 100644index 0000000..1e32c0b--- /dev/null+++ b/backend/services/fixtures/reddit.profile.golden.json@@ -0,0 +1,70 @@+{+ "profiles": [+ {+ "username": "ribbon",+ "totalKarma": 900,+ "postKarma": 600,+ "commentKarma": 300,+ "awardeeKarma": 5,+ "awarderKarma": 2,+ "iconUrl": "https://i/a.png?x=1&y=2",+ "createdAt": "2020-09-13T12:26:40.000Z",+ "isGold": true,+ "isMod": true,+ "verified": true+ },+ {+ "username": "plain",+ "totalKarma": 10,+ "postKarma": 4,+ "commentKarma": 6,+ "awardeeKarma": 0,+ "awarderKarma": 0,+ "iconUrl": "https://i/s.png",+ "createdAt": "",+ "isGold": false,+ "isMod": false,+ "verified": false+ },+ {+ "username": "empty",+ "totalKarma": "[NaN]",+ "postKarma": 0,+ "commentKarma": 0,+ "awardeeKarma": 0,+ "awarderKarma": 0,+ "iconUrl": "",+ "createdAt": "",+ "isGold": false,+ "isMod": false,+ "verified": false+ }+ ],+ "requests": [+ {+ "url": "https://www.reddit.com/user/ribbon/about.json",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json",+ "Cookie": "reddit_session=COOKIE"+ }+ },+ {+ "url": "https://www.reddit.com/user/plain/about.json",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json"+ }+ },+ {+ "url": "https://www.reddit.com/user/empty/about.json",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json"+ }+ }+ ]+}diff --git a/backend/services/fixtures/reddit.tracked.golden.json b/backend/services/fixtures/reddit.tracked.golden.jsonnew file mode 100644index 0000000..57d509f--- /dev/null+++ b/backend/services/fixtures/reddit.tracked.golden.json@@ -0,0 +1,89 @@+{+ "outcomes": [+ {+ "value": {+ "postId": "p1",+ "title": "Tracked",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "author": "[deleted]",+ "score": 77,+ "upvoteRatio": 0.93,+ "numComments": 8,+ "permalink": "https://reddit.com/r/webdev/comments/p1/tracked/",+ "isNsfw": false,+ "createdAt": "2026-07-25T17:20:00.000Z",+ "lastFetchedAt": "2026-09-01T12:00:00.000Z"+ }+ },+ {+ "value": {+ "postId": "p2",+ "title": "Sparse",+ "subreddit": "misc",+ "subredditPrefixed": "r/misc",+ "author": "[deleted]",+ "score": 0,+ "upvoteRatio": 0,+ "numComments": 0,+ "permalink": "https://reddit.com/r/misc/comments/p2/",+ "isNsfw": false,+ "createdAt": "",+ "lastFetchedAt": "2026-09-01T12:00:00.000Z"+ }+ },+ {+ "error": "Unexpected Reddit response - post may be deleted or private"+ },+ {+ "error": "Post not found or has been deleted"+ },+ {+ "error": "Invalid URL - paste the full post link from reddit.com"+ },+ {+ "error": "Not a Reddit URL - paste a link from reddit.com"+ },+ {+ "error": "Not a Reddit post URL - paste the full post link including /r/.../comments/..."+ }+ ],+ "requests": [+ {+ "url": "https://www.reddit.com/r/webdev/comments/p1/tracked.json",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json",+ "Cookie": "reddit_session=COOKIE"+ }+ },+ {+ "url": "https://www.reddit.com/r/misc/comments/p2.json",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json",+ "Cookie": "reddit_session=COOKIE"+ }+ },+ {+ "url": "https://www.reddit.com/r/misc/comments/p3/x.json",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json",+ "Cookie": "reddit_session=COOKIE"+ }+ },+ {+ "url": "https://www.reddit.com/r/misc/comments/p4/x.json",+ "method": "GET",+ "headers": {+ "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",+ "Accept": "application/json",+ "Cookie": "reddit_session=COOKIE"+ }+ }+ ]+}diff --git a/backend/services/fixtures/redditAnalytics.empty.golden.json b/backend/services/fixtures/redditAnalytics.empty.golden.jsonnew file mode 100644index 0000000..6b417e1--- /dev/null+++ b/backend/services/fixtures/redditAnalytics.empty.golden.json@@ -0,0 +1,62 @@+{+ "empty": {+ "fetchedPosts": 0,+ "totalScore": 0,+ "avgScore": 0,+ "medianScore": 0,+ "totalComments": 0,+ "avgComments": 0,+ "avgUpvoteRatio": 0,+ "totalAwards": 0,+ "avgAwards": 0,+ "topPosts": [],+ "worstPosts": [],+ "subredditBreakdown": [],+ "mediaTypeDistribution": {},+ "postsByDayOfWeek": [],+ "postsByHour": [],+ "monthlyBreakdown": [],+ "engagementTimeline": [],+ "postsLast7Days": 0,+ "postsLast30Days": 0,+ "postsLast90Days": 0,+ "postFrequency": {+ "perWeek": 0,+ "perMonth": 0+ },+ "viralityScore": 0,+ "consistencyScore": 0,+ "bestPostingDay": "",+ "bestPostingHour": ""+ },+ "missing": {+ "fetchedPosts": 0,+ "totalScore": 0,+ "avgScore": 0,+ "medianScore": 0,+ "totalComments": 0,+ "avgComments": 0,+ "avgUpvoteRatio": 0,+ "totalAwards": 0,+ "avgAwards": 0,+ "topPosts": [],+ "worstPosts": [],+ "subredditBreakdown": [],+ "mediaTypeDistribution": {},+ "postsByDayOfWeek": [],+ "postsByHour": [],+ "monthlyBreakdown": [],+ "engagementTimeline": [],+ "postsLast7Days": 0,+ "postsLast30Days": 0,+ "postsLast90Days": 0,+ "postFrequency": {+ "perWeek": 0,+ "perMonth": 0+ },+ "viralityScore": 0,+ "consistencyScore": 0,+ "bestPostingDay": "",+ "bestPostingHour": ""+ }+}diff --git a/backend/services/fixtures/redditAnalytics.generated.golden.json b/backend/services/fixtures/redditAnalytics.generated.golden.jsonnew file mode 100644index 0000000..865b7f5--- /dev/null+++ b/backend/services/fixtures/redditAnalytics.generated.golden.json@@ -0,0 +1,722 @@+{+ "fetchedPosts": 30,+ "totalScore": 5855,+ "avgScore": 195,+ "medianScore": 195,+ "totalComments": 825,+ "avgComments": 28,+ "avgUpvoteRatio": 48.5,+ "totalAwards": 30,+ "avgAwards": 1,+ "topPosts": [+ {+ "id": "g15",+ "title": "Post g15",+ "subreddit": "sub15",+ "subredditPrefixed": "r/sub15",+ "score": 395,+ "upvoteRatio": 0.95,+ "numComments": 45,+ "url": "https://reddit.com/r/sub15/comments/g15/",+ "permalink": "https://reddit.com/r/sub15/comments/g15/post/",+ "thumbnail": "",+ "mediaType": "link",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-07-24T08:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "g07",+ "title": "Post g07",+ "subreddit": "sub7",+ "subredditPrefixed": "r/sub7",+ "score": 371,+ "upvoteRatio": 0.91,+ "numComments": 49,+ "url": "https://reddit.com/r/sub7/comments/g07/",+ "permalink": "https://reddit.com/r/sub7/comments/g07/post/",+ "thumbnail": "",+ "mediaType": "link",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-13T08:00:00.000Z",+ "flair": "",+ "awardsCount": 1+ },+ {+ "id": "g22",+ "title": "Post g22",+ "subreddit": "sub22",+ "subredditPrefixed": "r/sub22",+ "score": 366,+ "upvoteRatio": 0.86,+ "numComments": 34,+ "url": "https://reddit.com/r/sub22/comments/g22/",+ "permalink": "https://reddit.com/r/sub22/comments/g22/post/",+ "thumbnail": "",+ "mediaType": "video",+ "isSelf": false,+ "isVideo": true,+ "isNsfw": false,+ "createdAt": "2026-07-06T20:00:00.000Z",+ "flair": "",+ "awardsCount": 1+ },+ {+ "id": "g14",+ "title": "Post g14",+ "subreddit": "sub14",+ "subredditPrefixed": "r/sub14",+ "score": 342,+ "upvoteRatio": 0.82,+ "numComments": 38,+ "url": "https://reddit.com/r/sub14/comments/g14/",+ "permalink": "https://reddit.com/r/sub14/comments/g14/post/",+ "thumbnail": "",+ "mediaType": "video",+ "isSelf": false,+ "isVideo": true,+ "isNsfw": false,+ "createdAt": "2026-07-26T20:00:00.000Z",+ "flair": "",+ "awardsCount": 2+ },+ {+ "id": "g29",+ "title": "Post g29",+ "subreddit": "sub4",+ "subredditPrefixed": "r/sub4",+ "score": 337,+ "upvoteRatio": 0.77,+ "numComments": 23,+ "url": "https://reddit.com/r/sub4/comments/g29/",+ "permalink": "https://reddit.com/r/sub4/comments/g29/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-06-19T08:00:00.000Z",+ "flair": "",+ "awardsCount": 2+ },+ {+ "id": "g06",+ "title": "Post g06",+ "subreddit": "sub6",+ "subredditPrefixed": "r/sub6",+ "score": 318,+ "upvoteRatio": 0.78,+ "numComments": 42,+ "url": "https://reddit.com/r/sub6/comments/g06/",+ "permalink": "https://reddit.com/r/sub6/comments/g06/post/",+ "thumbnail": "",+ "mediaType": "video",+ "isSelf": false,+ "isVideo": true,+ "isNsfw": false,+ "createdAt": "2026-08-15T20:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "g21",+ "title": "Post g21",+ "subreddit": "sub21",+ "subredditPrefixed": "r/sub21",+ "score": 313,+ "upvoteRatio": 0.73,+ "numComments": 27,+ "url": "https://reddit.com/r/sub21/comments/g21/",+ "permalink": "https://reddit.com/r/sub21/comments/g21/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-07-09T08:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "g13",+ "title": "Post g13",+ "subreddit": "sub13",+ "subredditPrefixed": "r/sub13",+ "score": 289,+ "upvoteRatio": 0.69,+ "numComments": 31,+ "url": "https://reddit.com/r/sub13/comments/g13/",+ "permalink": "https://reddit.com/r/sub13/comments/g13/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-07-29T08:00:00.000Z",+ "flair": "",+ "awardsCount": 1+ },+ {+ "id": "g28",+ "title": "Post g28",+ "subreddit": "sub3",+ "subredditPrefixed": "r/sub3",+ "score": 284,+ "upvoteRatio": 0.64,+ "numComments": 16,+ "url": "https://reddit.com/r/sub3/comments/g28/",+ "permalink": "https://reddit.com/r/sub3/comments/g28/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-06-21T20:00:00.000Z",+ "flair": "",+ "awardsCount": 1+ },+ {+ "id": "g05",+ "title": "Post g05",+ "subreddit": "sub5",+ "subredditPrefixed": "r/sub5",+ "score": 265,+ "upvoteRatio": 0.65,+ "numComments": 35,+ "url": "https://reddit.com/r/sub5/comments/g05/",+ "permalink": "https://reddit.com/r/sub5/comments/g05/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-18T08:00:00.000Z",+ "flair": "",+ "awardsCount": 2+ }+ ],+ "worstPosts": [+ {+ "id": "g00",+ "title": "Post g00",+ "subreddit": "sub0",+ "subredditPrefixed": "r/sub0",+ "score": 0,+ "upvoteRatio": 0,+ "numComments": 0,+ "url": "https://reddit.com/r/sub0/comments/g00/",+ "permalink": "https://reddit.com/r/sub0/comments/g00/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-30T20:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "g23",+ "title": "Post g23",+ "subreddit": "sub23",+ "subredditPrefixed": "r/sub23",+ "score": 19,+ "upvoteRatio": 0.99,+ "numComments": 41,+ "url": "https://reddit.com/r/sub23/comments/g23/",+ "permalink": "https://reddit.com/r/sub23/comments/g23/post/",+ "thumbnail": "",+ "mediaType": "link",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-07-04T08:00:00.000Z",+ "flair": "",+ "awardsCount": 2+ },+ {+ "id": "g08",+ "title": "Post g08",+ "subreddit": "sub8",+ "subredditPrefixed": "r/sub8",+ "score": 24,+ "upvoteRatio": 0.04,+ "numComments": 56,+ "url": "https://reddit.com/r/sub8/comments/g08/",+ "permalink": "https://reddit.com/r/sub8/comments/g08/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-10T20:00:00.000Z",+ "flair": "",+ "awardsCount": 2+ },+ {+ "id": "g16",+ "title": "Post g16",+ "subreddit": "sub16",+ "subredditPrefixed": "r/sub16",+ "score": 48,+ "upvoteRatio": 0.08,+ "numComments": 52,+ "url": "https://reddit.com/r/sub16/comments/g16/",+ "permalink": "https://reddit.com/r/sub16/comments/g16/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-07-21T20:00:00.000Z",+ "flair": "",+ "awardsCount": 1+ },+ {+ "id": "g01",+ "title": "Post g01",+ "subreddit": "sub1",+ "subredditPrefixed": "r/sub1",+ "score": 53,+ "upvoteRatio": 0.13,+ "numComments": 7,+ "url": "https://reddit.com/r/sub1/comments/g01/",+ "permalink": "https://reddit.com/r/sub1/comments/g01/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-28T08:00:00.000Z",+ "flair": "",+ "awardsCount": 1+ }+ ],+ "subredditBreakdown": [+ {+ "subreddit": "sub0",+ "posts": 2,+ "totalScore": 125,+ "totalComments": 55,+ "avgScore": 63,+ "avgComments": 28+ },+ {+ "subreddit": "sub1",+ "posts": 2,+ "totalScore": 231,+ "totalComments": 9,+ "avgScore": 116,+ "avgComments": 5+ },+ {+ "subreddit": "sub2",+ "posts": 2,+ "totalScore": 337,+ "totalComments": 23,+ "avgScore": 169,+ "avgComments": 12+ },+ {+ "subreddit": "sub3",+ "posts": 2,+ "totalScore": 443,+ "totalComments": 37,+ "avgScore": 222,+ "avgComments": 19+ },+ {+ "subreddit": "sub4",+ "posts": 2,+ "totalScore": 549,+ "totalComments": 51,+ "avgScore": 275,+ "avgComments": 26+ },+ {+ "subreddit": "sub5",+ "posts": 1,+ "totalScore": 265,+ "totalComments": 35,+ "avgScore": 265,+ "avgComments": 35+ },+ {+ "subreddit": "sub6",+ "posts": 1,+ "totalScore": 318,+ "totalComments": 42,+ "avgScore": 318,+ "avgComments": 42+ },+ {+ "subreddit": "sub7",+ "posts": 1,+ "totalScore": 371,+ "totalComments": 49,+ "avgScore": 371,+ "avgComments": 49+ },+ {+ "subreddit": "sub8",+ "posts": 1,+ "totalScore": 24,+ "totalComments": 56,+ "avgScore": 24,+ "avgComments": 56+ },+ {+ "subreddit": "sub9",+ "posts": 1,+ "totalScore": 77,+ "totalComments": 3,+ "avgScore": 77,+ "avgComments": 3+ },+ {+ "subreddit": "sub10",+ "posts": 1,+ "totalScore": 130,+ "totalComments": 10,+ "avgScore": 130,+ "avgComments": 10+ },+ {+ "subreddit": "sub11",+ "posts": 1,+ "totalScore": 183,+ "totalComments": 17,+ "avgScore": 183,+ "avgComments": 17+ },+ {+ "subreddit": "sub12",+ "posts": 1,+ "totalScore": 236,+ "totalComments": 24,+ "avgScore": 236,+ "avgComments": 24+ },+ {+ "subreddit": "sub13",+ "posts": 1,+ "totalScore": 289,+ "totalComments": 31,+ "avgScore": 289,+ "avgComments": 31+ },+ {+ "subreddit": "sub14",+ "posts": 1,+ "totalScore": 342,+ "totalComments": 38,+ "avgScore": 342,+ "avgComments": 38+ },+ {+ "subreddit": "sub15",+ "posts": 1,+ "totalScore": 395,+ "totalComments": 45,+ "avgScore": 395,+ "avgComments": 45+ },+ {+ "subreddit": "sub16",+ "posts": 1,+ "totalScore": 48,+ "totalComments": 52,+ "avgScore": 48,+ "avgComments": 52+ },+ {+ "subreddit": "sub17",+ "posts": 1,+ "totalScore": 101,+ "totalComments": 59,+ "avgScore": 101,+ "avgComments": 59+ },+ {+ "subreddit": "sub18",+ "posts": 1,+ "totalScore": 154,+ "totalComments": 6,+ "avgScore": 154,+ "avgComments": 6+ },+ {+ "subreddit": "sub19",+ "posts": 1,+ "totalScore": 207,+ "totalComments": 13,+ "avgScore": 207,+ "avgComments": 13+ }+ ],+ "mediaTypeDistribution": {+ "text": 8,+ "image": 8,+ "video": 7,+ "link": 7+ },+ "postsByDayOfWeek": [+ {+ "day": "Sunday",+ "shortDay": "Sun",+ "posts": 5,+ "avgScore": 177,+ "avgComments": 27+ },+ {+ "day": "Monday",+ "shortDay": "Mon",+ "posts": 4,+ "avgScore": 175,+ "avgComments": 41+ },+ {+ "day": "Tuesday",+ "shortDay": "Tue",+ "posts": 4,+ "avgScore": 157,+ "avgComments": 29+ },+ {+ "day": "Wednesday",+ "shortDay": "Wed",+ "posts": 4,+ "avgScore": 181,+ "avgComments": 25+ },+ {+ "day": "Thursday",+ "shortDay": "Thu",+ "posts": 4,+ "avgScore": 263,+ "avgComments": 28+ },+ {+ "day": "Friday",+ "shortDay": "Fri",+ "posts": 5,+ "avgScore": 240,+ "avgComments": 20+ },+ {+ "day": "Saturday",+ "shortDay": "Sat",+ "posts": 4,+ "avgScore": 169,+ "avgComments": 27+ }+ ],+ "bestPostingDay": "Thursday",+ "postsByHour": [+ {+ "hour": 0,+ "label": "0:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 1,+ "label": "1:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 2,+ "label": "2:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 3,+ "label": "3:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 4,+ "label": "4:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 5,+ "label": "5:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 6,+ "label": "6:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 7,+ "label": "7:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 8,+ "label": "8:00",+ "posts": 15,+ "avgScore": 208+ },+ {+ "hour": 9,+ "label": "9:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 10,+ "label": "10:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 11,+ "label": "11:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 12,+ "label": "12:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 13,+ "label": "13:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 14,+ "label": "14:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 15,+ "label": "15:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 16,+ "label": "16:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 17,+ "label": "17:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 18,+ "label": "18:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 19,+ "label": "19:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 20,+ "label": "20:00",+ "posts": 15,+ "avgScore": 182+ },+ {+ "hour": 21,+ "label": "21:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 22,+ "label": "22:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 23,+ "label": "23:00",+ "posts": 0,+ "avgScore": 0+ }+ ],+ "bestPostingHour": "8:00",+ "monthlyBreakdown": [+ {+ "month": "2026-06",+ "posts": 5,+ "score": 1155,+ "comments": 105,+ "avgScore": 231+ },+ {+ "month": "2026-07",+ "posts": 13,+ "score": 2802,+ "comments": 438,+ "avgScore": 216+ },+ {+ "month": "2026-08",+ "posts": 12,+ "score": 1898,+ "comments": 282,+ "avgScore": 158+ }+ ],+ "engagementTimeline": [+ {+ "month": "2026-06",+ "posts": 5,+ "score": 1155,+ "comments": 105,+ "avgScore": 231+ },+ {+ "month": "2026-07",+ "posts": 13,+ "score": 2802,+ "comments": 438,+ "avgScore": 216+ },+ {+ "month": "2026-08",+ "posts": 12,+ "score": 1898,+ "comments": 282,+ "avgScore": 158+ }+ ],+ "postsLast7Days": 3,+ "postsLast30Days": 12,+ "postsLast90Days": 30,+ "postFrequency": {+ "perWeek": 2.9,+ "perMonth": 12.4+ },+ "viralityScore": 2,+ "consistencyScore": 63+}diff --git a/backend/services/fixtures/redditAnalytics.rich.golden.json b/backend/services/fixtures/redditAnalytics.rich.golden.jsonnew file mode 100644index 0000000..19aa6e4--- /dev/null+++ b/backend/services/fixtures/redditAnalytics.rich.golden.json@@ -0,0 +1,619 @@+{+ "fetchedPosts": 11,+ "totalScore": 1979,+ "avgScore": 180,+ "medianScore": 35,+ "totalComments": 488,+ "avgComments": 44,+ "avgUpvoteRatio": 78.5,+ "totalAwards": 18,+ "avgAwards": 1.64,+ "topPosts": [+ {+ "id": "r10",+ "title": "Post r10",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 1200,+ "upvoteRatio": 0.98,+ "numComments": 340,+ "url": "https://reddit.com/r/webdev/comments/r10/",+ "permalink": "https://reddit.com/r/webdev/comments/r10/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-05-01T15:45:00.000Z",+ "flair": "",+ "awardsCount": 12+ },+ {+ "id": "r01",+ "title": "Post r01",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 420,+ "upvoteRatio": 0.97,+ "numComments": 61,+ "url": "https://reddit.com/r/webdev/comments/r01/",+ "permalink": "https://reddit.com/r/webdev/comments/r01/post/",+ "thumbnail": "",+ "mediaType": "link",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-31T09:15:00.000Z",+ "flair": "",+ "awardsCount": 2+ },+ {+ "id": "r08",+ "title": "Post r08",+ "subreddit": "node",+ "subredditPrefixed": "r/node",+ "score": 150,+ "upvoteRatio": 0.95,+ "numComments": 22,+ "url": "https://reddit.com/r/node/comments/r08/",+ "permalink": "https://reddit.com/r/node/comments/r08/post/",+ "thumbnail": "",+ "mediaType": "video",+ "isSelf": false,+ "isVideo": true,+ "isNsfw": false,+ "createdAt": "2026-06-20T23:59:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "r07",+ "title": "Post r07",+ "subreddit": "reactjs",+ "subredditPrefixed": "r/reactjs",+ "score": 88,+ "upvoteRatio": 0.92,+ "numComments": 30,+ "url": "https://reddit.com/r/reactjs/comments/r07/",+ "permalink": "https://reddit.com/r/reactjs/comments/r07/post/",+ "thumbnail": "",+ "mediaType": "link",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-07-02T12:00:00.000Z",+ "flair": "",+ "awardsCount": 3+ },+ {+ "id": "r02",+ "title": "Post r02",+ "subreddit": "javascript",+ "subredditPrefixed": "r/javascript",+ "score": 35,+ "upvoteRatio": 0.88,+ "numComments": 12,+ "url": "https://reddit.com/r/javascript/comments/r02/",+ "permalink": "https://reddit.com/r/javascript/comments/r02/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-29T18:40:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "r03",+ "title": "Post r03",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 35,+ "upvoteRatio": 0.9,+ "numComments": 4,+ "url": "https://reddit.com/r/webdev/comments/r03/",+ "permalink": "https://reddit.com/r/webdev/comments/r03/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-25T09:05:00.000Z",+ "flair": ""+ },+ {+ "id": "r09",+ "title": "Post r09",+ "subreddit": "reactjs",+ "subredditPrefixed": "r/reactjs",+ "score": 35,+ "upvoteRatio": 0.81,+ "numComments": 7,+ "url": "https://reddit.com/r/reactjs/comments/r09/",+ "permalink": "https://reddit.com/r/reactjs/comments/r09/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-06-03T00:00:00.000Z",+ "flair": ""+ },+ {+ "id": "r04",+ "title": "Post r04",+ "subreddit": "node",+ "subredditPrefixed": "r/node",+ "score": 12,+ "upvoteRatio": 0.75,+ "numComments": 1,+ "url": "https://reddit.com/r/node/comments/r04/",+ "permalink": "https://reddit.com/r/node/comments/r04/post/",+ "thumbnail": "",+ "mediaType": "video",+ "isSelf": false,+ "isVideo": true,+ "isNsfw": false,+ "createdAt": "",+ "flair": "",+ "awardsCount": 1+ },+ {+ "id": "r11",+ "title": "Post r11",+ "subreddit": "javascript",+ "subredditPrefixed": "r/javascript",+ "score": 7,+ "upvoteRatio": 0.66,+ "numComments": 2,+ "url": "https://reddit.com/r/javascript/comments/r11/",+ "permalink": "https://reddit.com/r/javascript/comments/r11/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2025-12-31T23:30:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "r06",+ "title": "Post r06",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 0,+ "upvoteRatio": 0.5,+ "numComments": 0,+ "url": "https://reddit.com/r/webdev/comments/r06/",+ "permalink": "https://reddit.com/r/webdev/comments/r06/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-07-14T06:30:00.000Z",+ "flair": "",+ "awardsCount": 0+ }+ ],+ "worstPosts": [+ {+ "id": "r05",+ "title": "Post r05",+ "subreddit": "javascript",+ "subredditPrefixed": "r/javascript",+ "score": -3,+ "upvoteRatio": 0.31,+ "numComments": 9,+ "url": "https://reddit.com/r/javascript/comments/r05/",+ "permalink": "https://reddit.com/r/javascript/comments/r05/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-10T21:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "r06",+ "title": "Post r06",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 0,+ "upvoteRatio": 0.5,+ "numComments": 0,+ "url": "https://reddit.com/r/webdev/comments/r06/",+ "permalink": "https://reddit.com/r/webdev/comments/r06/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-07-14T06:30:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "r11",+ "title": "Post r11",+ "subreddit": "javascript",+ "subredditPrefixed": "r/javascript",+ "score": 7,+ "upvoteRatio": 0.66,+ "numComments": 2,+ "url": "https://reddit.com/r/javascript/comments/r11/",+ "permalink": "https://reddit.com/r/javascript/comments/r11/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2025-12-31T23:30:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "r04",+ "title": "Post r04",+ "subreddit": "node",+ "subredditPrefixed": "r/node",+ "score": 12,+ "upvoteRatio": 0.75,+ "numComments": 1,+ "url": "https://reddit.com/r/node/comments/r04/",+ "permalink": "https://reddit.com/r/node/comments/r04/post/",+ "thumbnail": "",+ "mediaType": "video",+ "isSelf": false,+ "isVideo": true,+ "isNsfw": false,+ "createdAt": "",+ "flair": "",+ "awardsCount": 1+ },+ {+ "id": "r09",+ "title": "Post r09",+ "subreddit": "reactjs",+ "subredditPrefixed": "r/reactjs",+ "score": 35,+ "upvoteRatio": 0.81,+ "numComments": 7,+ "url": "https://reddit.com/r/reactjs/comments/r09/",+ "permalink": "https://reddit.com/r/reactjs/comments/r09/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-06-03T00:00:00.000Z",+ "flair": ""+ }+ ],+ "subredditBreakdown": [+ {+ "subreddit": "webdev",+ "posts": 4,+ "totalScore": 1655,+ "totalComments": 405,+ "avgScore": 414,+ "avgComments": 101+ },+ {+ "subreddit": "javascript",+ "posts": 3,+ "totalScore": 39,+ "totalComments": 23,+ "avgScore": 13,+ "avgComments": 8+ },+ {+ "subreddit": "node",+ "posts": 2,+ "totalScore": 162,+ "totalComments": 23,+ "avgScore": 81,+ "avgComments": 12+ },+ {+ "subreddit": "reactjs",+ "posts": 2,+ "totalScore": 123,+ "totalComments": 37,+ "avgScore": 62,+ "avgComments": 19+ }+ ],+ "mediaTypeDistribution": {+ "link": 2,+ "text": 4,+ "image": 3,+ "video": 2+ },+ "postsByDayOfWeek": [+ {+ "day": "Sunday",+ "shortDay": "Sun",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Monday",+ "shortDay": "Mon",+ "posts": 2,+ "avgScore": 216,+ "avgComments": 31+ },+ {+ "day": "Tuesday",+ "shortDay": "Tue",+ "posts": 2,+ "avgScore": 16,+ "avgComments": 7+ },+ {+ "day": "Wednesday",+ "shortDay": "Wed",+ "posts": 2,+ "avgScore": 675,+ "avgComments": 181+ },+ {+ "day": "Thursday",+ "shortDay": "Thu",+ "posts": 1,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Friday",+ "shortDay": "Fri",+ "posts": 1,+ "avgScore": 35,+ "avgComments": 7+ },+ {+ "day": "Saturday",+ "shortDay": "Sat",+ "posts": 2,+ "avgScore": 62,+ "avgComments": 21+ }+ ],+ "bestPostingDay": "Wednesday",+ "postsByHour": [+ {+ "hour": 0,+ "label": "0:00",+ "posts": 1,+ "avgScore": 150+ },+ {+ "hour": 1,+ "label": "1:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 2,+ "label": "2:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 3,+ "label": "3:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 4,+ "label": "4:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 5,+ "label": "5:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 6,+ "label": "6:00",+ "posts": 1,+ "avgScore": -3+ },+ {+ "hour": 7,+ "label": "7:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 8,+ "label": "8:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 9,+ "label": "9:00",+ "posts": 2,+ "avgScore": 228+ },+ {+ "hour": 10,+ "label": "10:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 11,+ "label": "11:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 12,+ "label": "12:00",+ "posts": 1,+ "avgScore": 0+ },+ {+ "hour": 13,+ "label": "13:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 14,+ "label": "14:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 15,+ "label": "15:00",+ "posts": 1,+ "avgScore": 35+ },+ {+ "hour": 16,+ "label": "16:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 17,+ "label": "17:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 18,+ "label": "18:00",+ "posts": 1,+ "avgScore": 35+ },+ {+ "hour": 19,+ "label": "19:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 20,+ "label": "20:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 21,+ "label": "21:00",+ "posts": 1,+ "avgScore": 12+ },+ {+ "hour": 22,+ "label": "22:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 23,+ "label": "23:00",+ "posts": 2,+ "avgScore": 644+ }+ ],+ "bestPostingHour": "23:00",+ "monthlyBreakdown": [+ {+ "month": "2025-12",+ "posts": 1,+ "score": 7,+ "comments": 2,+ "avgScore": 7+ },+ {+ "month": "2026-05",+ "posts": 1,+ "score": 1200,+ "comments": 340,+ "avgScore": 1200+ },+ {+ "month": "2026-06",+ "posts": 2,+ "score": 185,+ "comments": 29,+ "avgScore": 93+ },+ {+ "month": "2026-07",+ "posts": 2,+ "score": 88,+ "comments": 30,+ "avgScore": 44+ },+ {+ "month": "2026-08",+ "posts": 4,+ "score": 487,+ "comments": 86,+ "avgScore": 122+ }+ ],+ "engagementTimeline": [+ {+ "month": "2025-12",+ "posts": 1,+ "score": 7,+ "comments": 2,+ "avgScore": 7+ },+ {+ "month": "2026-05",+ "posts": 1,+ "score": 1200,+ "comments": 340,+ "avgScore": 1200+ },+ {+ "month": "2026-06",+ "posts": 2,+ "score": 185,+ "comments": 29,+ "avgScore": 93+ },+ {+ "month": "2026-07",+ "posts": 2,+ "score": 88,+ "comments": 30,+ "avgScore": 44+ },+ {+ "month": "2026-08",+ "posts": 4,+ "score": 487,+ "comments": 86,+ "avgScore": 122+ }+ ],+ "postsLast7Days": 2,+ "postsLast30Days": 4,+ "postsLast90Days": 7,+ "postFrequency": {+ "perWeek": 0.3,+ "perMonth": 1.4+ },+ "viralityScore": 6.7,+ "consistencyScore": 34+}diff --git a/backend/services/fixtures/redditAnalytics.small.golden.json b/backend/services/fixtures/redditAnalytics.small.golden.jsonnew file mode 100644index 0000000..2c0ec51--- /dev/null+++ b/backend/services/fixtures/redditAnalytics.small.golden.json@@ -0,0 +1,631 @@+{+ "single": {+ "fetchedPosts": 1,+ "totalScore": 420,+ "avgScore": 420,+ "medianScore": 420,+ "totalComments": 61,+ "avgComments": 61,+ "avgUpvoteRatio": 97,+ "totalAwards": 2,+ "avgAwards": 2,+ "topPosts": [+ {+ "id": "r01",+ "title": "Post r01",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 420,+ "upvoteRatio": 0.97,+ "numComments": 61,+ "url": "https://reddit.com/r/webdev/comments/r01/",+ "permalink": "https://reddit.com/r/webdev/comments/r01/post/",+ "thumbnail": "",+ "mediaType": "link",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-31T09:15:00.000Z",+ "flair": "",+ "awardsCount": 2+ }+ ],+ "worstPosts": [+ {+ "id": "r01",+ "title": "Post r01",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 420,+ "upvoteRatio": 0.97,+ "numComments": 61,+ "url": "https://reddit.com/r/webdev/comments/r01/",+ "permalink": "https://reddit.com/r/webdev/comments/r01/post/",+ "thumbnail": "",+ "mediaType": "link",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-31T09:15:00.000Z",+ "flair": "",+ "awardsCount": 2+ }+ ],+ "subredditBreakdown": [+ {+ "subreddit": "webdev",+ "posts": 1,+ "totalScore": 420,+ "totalComments": 61,+ "avgScore": 420,+ "avgComments": 61+ }+ ],+ "mediaTypeDistribution": {+ "link": 1+ },+ "postsByDayOfWeek": [+ {+ "day": "Sunday",+ "shortDay": "Sun",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Monday",+ "shortDay": "Mon",+ "posts": 1,+ "avgScore": 420,+ "avgComments": 61+ },+ {+ "day": "Tuesday",+ "shortDay": "Tue",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Wednesday",+ "shortDay": "Wed",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Thursday",+ "shortDay": "Thu",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Friday",+ "shortDay": "Fri",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Saturday",+ "shortDay": "Sat",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ }+ ],+ "bestPostingDay": "Monday",+ "postsByHour": [+ {+ "hour": 0,+ "label": "0:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 1,+ "label": "1:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 2,+ "label": "2:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 3,+ "label": "3:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 4,+ "label": "4:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 5,+ "label": "5:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 6,+ "label": "6:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 7,+ "label": "7:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 8,+ "label": "8:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 9,+ "label": "9:00",+ "posts": 1,+ "avgScore": 420+ },+ {+ "hour": 10,+ "label": "10:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 11,+ "label": "11:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 12,+ "label": "12:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 13,+ "label": "13:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 14,+ "label": "14:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 15,+ "label": "15:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 16,+ "label": "16:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 17,+ "label": "17:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 18,+ "label": "18:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 19,+ "label": "19:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 20,+ "label": "20:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 21,+ "label": "21:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 22,+ "label": "22:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 23,+ "label": "23:00",+ "posts": 0,+ "avgScore": 0+ }+ ],+ "bestPostingHour": "9:00",+ "monthlyBreakdown": [+ {+ "month": "2026-08",+ "posts": 1,+ "score": 420,+ "comments": 61,+ "avgScore": 420+ }+ ],+ "engagementTimeline": [+ {+ "month": "2026-08",+ "posts": 1,+ "score": 420,+ "comments": 61,+ "avgScore": 420+ }+ ],+ "postsLast7Days": 1,+ "postsLast30Days": 1,+ "postsLast90Days": 1,+ "postFrequency": {+ "perWeek": 0,+ "perMonth": 0+ },+ "viralityScore": 1,+ "consistencyScore": 0+ },+ "pair": {+ "fetchedPosts": 2,+ "totalScore": 70,+ "avgScore": 35,+ "medianScore": 35,+ "totalComments": 16,+ "avgComments": 8,+ "avgUpvoteRatio": 89,+ "totalAwards": 0,+ "avgAwards": 0,+ "topPosts": [+ {+ "id": "r02",+ "title": "Post r02",+ "subreddit": "javascript",+ "subredditPrefixed": "r/javascript",+ "score": 35,+ "upvoteRatio": 0.88,+ "numComments": 12,+ "url": "https://reddit.com/r/javascript/comments/r02/",+ "permalink": "https://reddit.com/r/javascript/comments/r02/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-29T18:40:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "r03",+ "title": "Post r03",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 35,+ "upvoteRatio": 0.9,+ "numComments": 4,+ "url": "https://reddit.com/r/webdev/comments/r03/",+ "permalink": "https://reddit.com/r/webdev/comments/r03/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-25T09:05:00.000Z",+ "flair": ""+ }+ ],+ "worstPosts": [+ {+ "id": "r03",+ "title": "Post r03",+ "subreddit": "webdev",+ "subredditPrefixed": "r/webdev",+ "score": 35,+ "upvoteRatio": 0.9,+ "numComments": 4,+ "url": "https://reddit.com/r/webdev/comments/r03/",+ "permalink": "https://reddit.com/r/webdev/comments/r03/post/",+ "thumbnail": "",+ "mediaType": "image",+ "isSelf": false,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-25T09:05:00.000Z",+ "flair": ""+ },+ {+ "id": "r02",+ "title": "Post r02",+ "subreddit": "javascript",+ "subredditPrefixed": "r/javascript",+ "score": 35,+ "upvoteRatio": 0.88,+ "numComments": 12,+ "url": "https://reddit.com/r/javascript/comments/r02/",+ "permalink": "https://reddit.com/r/javascript/comments/r02/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-29T18:40:00.000Z",+ "flair": "",+ "awardsCount": 0+ }+ ],+ "subredditBreakdown": [+ {+ "subreddit": "javascript",+ "posts": 1,+ "totalScore": 35,+ "totalComments": 12,+ "avgScore": 35,+ "avgComments": 12+ },+ {+ "subreddit": "webdev",+ "posts": 1,+ "totalScore": 35,+ "totalComments": 4,+ "avgScore": 35,+ "avgComments": 4+ }+ ],+ "mediaTypeDistribution": {+ "text": 1,+ "image": 1+ },+ "postsByDayOfWeek": [+ {+ "day": "Sunday",+ "shortDay": "Sun",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Monday",+ "shortDay": "Mon",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Tuesday",+ "shortDay": "Tue",+ "posts": 1,+ "avgScore": 35,+ "avgComments": 4+ },+ {+ "day": "Wednesday",+ "shortDay": "Wed",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Thursday",+ "shortDay": "Thu",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Friday",+ "shortDay": "Fri",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Saturday",+ "shortDay": "Sat",+ "posts": 1,+ "avgScore": 35,+ "avgComments": 12+ }+ ],+ "bestPostingDay": "Tuesday",+ "postsByHour": [+ {+ "hour": 0,+ "label": "0:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 1,+ "label": "1:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 2,+ "label": "2:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 3,+ "label": "3:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 4,+ "label": "4:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 5,+ "label": "5:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 6,+ "label": "6:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 7,+ "label": "7:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 8,+ "label": "8:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 9,+ "label": "9:00",+ "posts": 1,+ "avgScore": 35+ },+ {+ "hour": 10,+ "label": "10:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 11,+ "label": "11:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 12,+ "label": "12:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 13,+ "label": "13:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 14,+ "label": "14:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 15,+ "label": "15:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 16,+ "label": "16:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 17,+ "label": "17:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 18,+ "label": "18:00",+ "posts": 1,+ "avgScore": 35+ },+ {+ "hour": 19,+ "label": "19:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 20,+ "label": "20:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 21,+ "label": "21:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 22,+ "label": "22:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 23,+ "label": "23:00",+ "posts": 0,+ "avgScore": 0+ }+ ],+ "bestPostingHour": "9:00",+ "monthlyBreakdown": [+ {+ "month": "2026-08",+ "posts": 2,+ "score": 70,+ "comments": 16,+ "avgScore": 35+ }+ ],+ "engagementTimeline": [+ {+ "month": "2026-08",+ "posts": 2,+ "score": 70,+ "comments": 16,+ "avgScore": 35+ }+ ],+ "postsLast7Days": 1,+ "postsLast30Days": 2,+ "postsLast90Days": 2,+ "postFrequency": {+ "perWeek": 3.2,+ "perMonth": 13.6+ },+ "viralityScore": 1,+ "consistencyScore": 0+ }+}diff --git a/backend/services/fixtures/redditAnalytics.zero.golden.json b/backend/services/fixtures/redditAnalytics.zero.golden.jsonnew file mode 100644index 0000000..9d2bff0--- /dev/null+++ b/backend/services/fixtures/redditAnalytics.zero.golden.json@@ -0,0 +1,368 @@+{+ "fetchedPosts": 3,+ "totalScore": 0,+ "avgScore": 0,+ "medianScore": 0,+ "totalComments": 1,+ "avgComments": 0,+ "avgUpvoteRatio": 50,+ "totalAwards": 0,+ "avgAwards": 0,+ "topPosts": [+ {+ "id": "z1",+ "title": "Post z1",+ "subreddit": "test",+ "subredditPrefixed": "r/test",+ "score": 0,+ "upvoteRatio": 0.5,+ "numComments": 0,+ "url": "https://reddit.com/r/test/comments/z1/",+ "permalink": "https://reddit.com/r/test/comments/z1/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-01T10:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "z2",+ "title": "Post z2",+ "subreddit": "test",+ "subredditPrefixed": "r/test",+ "score": 0,+ "upvoteRatio": 0.5,+ "numComments": 1,+ "url": "https://reddit.com/r/test/comments/z2/",+ "permalink": "https://reddit.com/r/test/comments/z2/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-02T10:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "z3",+ "title": "Post z3",+ "subreddit": "test",+ "subredditPrefixed": "r/test",+ "score": 0,+ "upvoteRatio": 0.5,+ "numComments": 0,+ "url": "https://reddit.com/r/test/comments/z3/",+ "permalink": "https://reddit.com/r/test/comments/z3/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-03T10:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ }+ ],+ "worstPosts": [+ {+ "id": "z3",+ "title": "Post z3",+ "subreddit": "test",+ "subredditPrefixed": "r/test",+ "score": 0,+ "upvoteRatio": 0.5,+ "numComments": 0,+ "url": "https://reddit.com/r/test/comments/z3/",+ "permalink": "https://reddit.com/r/test/comments/z3/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-03T10:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "z2",+ "title": "Post z2",+ "subreddit": "test",+ "subredditPrefixed": "r/test",+ "score": 0,+ "upvoteRatio": 0.5,+ "numComments": 1,+ "url": "https://reddit.com/r/test/comments/z2/",+ "permalink": "https://reddit.com/r/test/comments/z2/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-02T10:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ },+ {+ "id": "z1",+ "title": "Post z1",+ "subreddit": "test",+ "subredditPrefixed": "r/test",+ "score": 0,+ "upvoteRatio": 0.5,+ "numComments": 0,+ "url": "https://reddit.com/r/test/comments/z1/",+ "permalink": "https://reddit.com/r/test/comments/z1/post/",+ "thumbnail": "",+ "mediaType": "text",+ "isSelf": true,+ "isVideo": false,+ "isNsfw": false,+ "createdAt": "2026-08-01T10:00:00.000Z",+ "flair": "",+ "awardsCount": 0+ }+ ],+ "subredditBreakdown": [+ {+ "subreddit": "test",+ "posts": 3,+ "totalScore": 0,+ "totalComments": 1,+ "avgScore": 0,+ "avgComments": 0+ }+ ],+ "mediaTypeDistribution": {+ "text": 3+ },+ "postsByDayOfWeek": [+ {+ "day": "Sunday",+ "shortDay": "Sun",+ "posts": 1,+ "avgScore": 0,+ "avgComments": 1+ },+ {+ "day": "Monday",+ "shortDay": "Mon",+ "posts": 1,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Tuesday",+ "shortDay": "Tue",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Wednesday",+ "shortDay": "Wed",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Thursday",+ "shortDay": "Thu",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Friday",+ "shortDay": "Fri",+ "posts": 0,+ "avgScore": 0,+ "avgComments": 0+ },+ {+ "day": "Saturday",+ "shortDay": "Sat",+ "posts": 1,+ "avgScore": 0,+ "avgComments": 0+ }+ ],+ "bestPostingDay": "Sunday",+ "postsByHour": [+ {+ "hour": 0,+ "label": "0:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 1,+ "label": "1:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 2,+ "label": "2:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 3,+ "label": "3:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 4,+ "label": "4:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 5,+ "label": "5:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 6,+ "label": "6:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 7,+ "label": "7:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 8,+ "label": "8:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 9,+ "label": "9:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 10,+ "label": "10:00",+ "posts": 3,+ "avgScore": 0+ },+ {+ "hour": 11,+ "label": "11:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 12,+ "label": "12:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 13,+ "label": "13:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 14,+ "label": "14:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 15,+ "label": "15:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 16,+ "label": "16:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 17,+ "label": "17:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 18,+ "label": "18:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 19,+ "label": "19:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 20,+ "label": "20:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 21,+ "label": "21:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 22,+ "label": "22:00",+ "posts": 0,+ "avgScore": 0+ },+ {+ "hour": 23,+ "label": "23:00",+ "posts": 0,+ "avgScore": 0+ }+ ],+ "bestPostingHour": "",+ "monthlyBreakdown": [+ {+ "month": "2026-08",+ "posts": 3,+ "score": 0,+ "comments": 1,+ "avgScore": 0+ }+ ],+ "engagementTimeline": [+ {+ "month": "2026-08",+ "posts": 3,+ "score": 0,+ "comments": 1,+ "avgScore": 0+ }+ ],+ "postsLast7Days": 0,+ "postsLast30Days": 1,+ "postsLast90Days": 3,+ "postFrequency": {+ "perWeek": 10.5,+ "perMonth": 45+ },+ "viralityScore": 0,+ "consistencyScore": 100+}diff --git a/backend/services/fixtures/redditFixtures.js b/backend/services/fixtures/redditFixtures.jsnew file mode 100644index 0000000..3b6ae31--- /dev/null+++ b/backend/services/fixtures/redditFixtures.js@@ -0,0 +1,61 @@+export const FIXED_NOW = Date.parse('2026-09-01T12:00:00Z');++function redditPost(id, subreddit, createdAt, counts, mediaType = 'text') {+ const [score, numComments, upvoteRatio, awardsCount] = counts;+ const post = {+ id,+ title: `Post ${id}`,+ subreddit,+ subredditPrefixed: `r/${subreddit}`,+ score,+ upvoteRatio,+ numComments,+ url: `https://reddit.com/r/${subreddit}/comments/${id}/`,+ permalink: `https://reddit.com/r/${subreddit}/comments/${id}/post/`,+ thumbnail: '',+ mediaType,+ isSelf: mediaType === 'text',+ isVideo: mediaType === 'video',+ isNsfw: false,+ createdAt,+ flair: '',+ };+ if (awardsCount !== undefined) post.awardsCount = awardsCount;+ return post;+}++export const richPosts = [+ redditPost('r01', 'webdev', '2026-08-31T09:15:00.000Z', [420, 61, 0.97, 2], 'link'),+ redditPost('r02', 'javascript', '2026-08-29T18:40:00.000Z', [35, 12, 0.88, 0]),+ redditPost('r03', 'webdev', '2026-08-25T09:05:00.000Z', [35, 4, 0.9], 'image'),+ redditPost('r04', 'node', '', [12, 1, 0.75, 1], 'video'),+ redditPost('r05', 'javascript', '2026-08-10T21:00:00.000Z', [-3, 9, 0.31, 0]),+ redditPost('r06', 'webdev', '2026-07-14T06:30:00.000Z', [0, 0, 0.5, 0], 'image'),+ redditPost('r07', 'reactjs', '2026-07-02T12:00:00.000Z', [88, 30, 0.92, 3], 'link'),+ redditPost('r08', 'node', '2026-06-20T23:59:00.000Z', [150, 22, 0.95, 0], 'video'),+ redditPost('r09', 'reactjs', '2026-06-03T00:00:00.000Z', [35, 7, 0.81]),+ redditPost('r10', 'webdev', '2026-05-01T15:45:00.000Z', [1200, 340, 0.98, 12], 'image'),+ redditPost('r11', 'javascript', '2025-12-31T23:30:00.000Z', [7, 2, 0.66, 0]),+];++export const zeroScorePosts = [+ redditPost('z1', 'test', '2026-08-01T10:00:00.000Z', [0, 0, 0.5, 0]),+ redditPost('z2', 'test', '2026-08-02T10:00:00.000Z', [0, 1, 0.5, 0]),+ redditPost('z3', 'test', '2026-08-03T10:00:00.000Z', [0, 0, 0.5, 0]),+];++export const generatedPosts = Array.from({ length: 30 }, (_, index) => redditPost(+ `g${String(index).padStart(2, '0')}`,+ `sub${index % 25}`,+ new Date(Date.UTC(2026, 7, 30, 20) - index * 2.5 * 86400000).toISOString(),+ [(index * 53) % 400, (index * 7) % 60, ((index * 13) % 100) / 100, index % 3],+ ['text', 'image', 'video', 'link'][index % 4],+));++export const rawRedditPosts = [+ { id: 'a', title: 'Self post', subreddit: 'webdev', subreddit_name_prefixed: 'r/webdev', score: 10, upvote_ratio: 0.9, num_comments: 3, url: 'https://reddit.com/a', permalink: '/r/webdev/comments/a/self/', thumbnail: 'self', is_self: true, created_utc: 1785000000, link_flair_text: 'Discussion', total_awards_received: 1 },+ { id: 'b', title: 'Video', subreddit: 'videos', is_video: true, post_hint: 'image', permalink: '/r/videos/comments/b/v/', thumbnail: 'https://thumb/b.jpg', over_18: true, created_utc: 1785100000.5 },+ { id: 'c', title: 'Image', subreddit: 'pics', post_hint: 'image', is_self: true, permalink: '/r/pics/comments/c/i/', thumbnail: 'default' },+ { id: 'd', title: 'Link', subreddit: 'news', post_hint: 'link', permalink: '/r/news/comments/d/l/', score: 0, upvote_ratio: 0 },+ { id: 'e', title: 'Bare', subreddit: 'misc', permalink: '/r/misc/comments/e/b/', thumbnail: null, is_video: false, is_self: false },+];diff --git a/backend/services/reddit.js b/backend/services/reddit.jsindex 23ce73f..18105c6 100644--- a/backend/services/reddit.js+++ b/backend/services/reddit.js@@ -1,9 +1,8 @@-// fetch is a global in Cloudflare Workers - no import needed.-// Reddit API access requires a session cookie from the user's logged-in browser session.-// Cookies are stored as-is and sent with every request.+export { computeRedditAnalytics } from './redditAnalytics.js';+// fetch is a worker global; requests send the user's reddit_session cookie as storedconst REDDIT_BASE = 'https://www.reddit.com';-// Reddit requires: <platform>:<appid>:<version> (by /u/<username>)+// reddit requires <platform>:<appid>:<version> (by /u/<username>)const USER_AGENT = 'script:twiligent:v1.0 (by /u/spacesdrive)';async function redditFetch(path, cookie) {@@ -23,35 +22,64 @@ async function redditFetch(path, cookie) {export async function fetchRedditProfile(username, cookie) {const data = await redditFetch(`/user/${username}/about.json`, cookie);- const u = data.data;+ const user = data.data;return {- username: u.name,- totalKarma: u.total_karma ?? (u.link_karma + u.comment_karma),- postKarma: u.link_karma ?? 0,- commentKarma: u.comment_karma ?? 0,- awardeeKarma: u.awardee_karma ?? 0,- awarderKarma: u.awarder_karma ?? 0,- iconUrl: (u.icon_img || u.snoovatar_img || '').replace(/&/g, '&'),- createdAt: u.created_utc ? new Date(u.created_utc * 1000).toISOString() : '',- isGold: u.is_gold ?? false,- isMod: u.is_mod ?? false,- verified: u.verified ?? false,+ username: user.name,+ totalKarma: user.total_karma ?? (user.link_karma + user.comment_karma),+ postKarma: user.link_karma ?? 0,+ commentKarma: user.comment_karma ?? 0,+ awardeeKarma: user.awardee_karma ?? 0,+ awarderKarma: user.awarder_karma ?? 0,+ iconUrl: (user.icon_img || user.snoovatar_img || '').replace(/&/g, '&'),+ createdAt: user.created_utc ? new Date(user.created_utc * 1000).toISOString() : '',+ isGold: user.is_gold ?? false,+ isMod: user.is_mod ?? false,+ verified: user.verified ?? false,+ };+}++function redditMediaType(post) {+ if (post.is_video) return 'video';+ if (post.post_hint === 'image') return 'image';+ if (post.is_self) return 'text';+ return 'link';+}++function normalizeRedditPost(post) {+ return {+ id: post.id,+ title: post.title,+ subreddit: post.subreddit,+ subredditPrefixed: post.subreddit_name_prefixed ?? `r/${post.subreddit}`,+ score: post.score ?? 0,+ upvoteRatio: post.upvote_ratio ?? 0,+ numComments: post.num_comments ?? 0,+ url: post.url ?? '',+ permalink: `https://reddit.com${post.permalink}`,+ thumbnail: (post.thumbnail && post.thumbnail.startsWith('http')) ? post.thumbnail : '',+ mediaType: redditMediaType(post),+ isSelf: post.is_self ?? false,+ isVideo: post.is_video ?? false,+ isNsfw: post.over_18 ?? false,+ createdAt: post.created_utc ? new Date(post.created_utc * 1000).toISOString() : '',+ flair: post.link_flair_text ?? '',+ awardsCount: post.total_awards_received ?? 0,};}export async function fetchRedditPosts(username, cookie, limit = 100) {- let allPosts = [];+ const allPosts = [];let after = null;let pages = 0;while (pages < 10 && allPosts.length < limit) {- const qs = new URLSearchParams({+ const query = new URLSearchParams({limit: String(Math.min(100, limit - allPosts.length)),sort: 'new',});- if (after) qs.set('after', after);+ if (after) query.set('after', after);- const data = await redditFetch(`/user/${username}/submitted.json?${qs}`, cookie);+ const data = await redditFetch(`/user/${username}/submitted.json?${query}`, cookie);const children = data.data?.children ?? [];if (children.length === 0) break;@@ -61,198 +89,21 @@ export async function fetchRedditPosts(username, cookie, limit = 100) {pages++;}- return allPosts.slice(0, limit).map(p => ({- id: p.id,- title: p.title,- subreddit: p.subreddit,- subredditPrefixed: p.subreddit_name_prefixed ?? `r/${p.subreddit}`,- score: p.score ?? 0,- upvoteRatio: p.upvote_ratio ?? 0,- numComments: p.num_comments ?? 0,- url: p.url ?? '',- permalink: `https://reddit.com${p.permalink}`,- thumbnail: (p.thumbnail && p.thumbnail.startsWith('http')) ? p.thumbnail : '',- mediaType: p.is_video ? 'video' : (p.post_hint === 'image' ? 'image' : p.is_self ? 'text' : 'link'),- isSelf: p.is_self ?? false,- isVideo: p.is_video ?? false,- isNsfw: p.over_18 ?? false,- createdAt: p.created_utc ? new Date(p.created_utc * 1000).toISOString() : '',- flair: p.link_flair_text ?? '',- awardsCount: p.total_awards_received ?? 0,- }));-}--export function computeRedditAnalytics(profile, posts) {- const empty = {- fetchedPosts: 0, totalScore: 0, avgScore: 0, medianScore: 0,- totalComments: 0, avgComments: 0, avgUpvoteRatio: 0,- totalAwards: 0, avgAwards: 0,- topPosts: [], worstPosts: [], subredditBreakdown: [],- mediaTypeDistribution: {}, postsByDayOfWeek: [], postsByHour: [],- monthlyBreakdown: [], engagementTimeline: [],- postsLast7Days: 0, postsLast30Days: 0, postsLast90Days: 0,- postFrequency: { perWeek: 0, perMonth: 0 },- viralityScore: 0, consistencyScore: 0,- bestPostingDay: '', bestPostingHour: '',- };-- if (!posts || posts.length === 0) return empty;-- const totalScore = posts.reduce((s, p) => s + p.score, 0);- const totalComments = posts.reduce((s, p) => s + p.numComments, 0);- const totalAwards = posts.reduce((s, p) => s + (p.awardsCount ?? 0), 0);- const avgScore = Math.round(totalScore / posts.length);- const avgComments = Math.round(totalComments / posts.length);- const avgAwards = parseFloat((totalAwards / posts.length).toFixed(2));-- const avgUpvoteRatio = parseFloat(- (posts.reduce((s, p) => s + p.upvoteRatio, 0) / posts.length * 100).toFixed(1)- );-- const sortedScores = [...posts].map(p => p.score).sort((a, b) => a - b);- const mid = Math.floor(sortedScores.length / 2);- const medianScore = sortedScores.length % 2- ? sortedScores[mid]- : Math.round((sortedScores[mid - 1] + sortedScores[mid]) / 2);-- const byScore = [...posts].sort((a, b) => b.score - a.score);-- // Subreddit breakdown- const subMap = {};- posts.forEach(p => {- const sub = p.subreddit;- if (!subMap[sub]) subMap[sub] = { subreddit: sub, posts: 0, totalScore: 0, totalComments: 0 };- subMap[sub].posts++;- subMap[sub].totalScore += p.score;- subMap[sub].totalComments += p.numComments;- });- const subredditBreakdown = Object.values(subMap)- .map(s => ({- ...s,- avgScore: Math.round(s.totalScore / s.posts),- avgComments: Math.round(s.totalComments / s.posts),- }))- .sort((a, b) => b.posts - a.posts)- .slice(0, 20);-- // Media type distribution- const mediaTypeDistribution = {};- posts.forEach(p => { mediaTypeDistribution[p.mediaType] = (mediaTypeDistribution[p.mediaType] ?? 0) + 1; });-- // Day of week and hour analysis- const dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];- const dayBuckets = Array(7).fill(null).map(() => ({ count: 0, score: 0, comments: 0 }));- const hourBuckets = Array(24).fill(null).map(() => ({ count: 0, score: 0 }));- const dates = posts- .map(p => p.createdAt ? new Date(p.createdAt) : null)- .filter(Boolean);-- dates.forEach((d, i) => {- const day = d.getDay();- dayBuckets[day].count++;- dayBuckets[day].score += posts[i]?.score ?? 0;- dayBuckets[day].comments += posts[i]?.numComments ?? 0;- const h = d.getHours();- hourBuckets[h].count++;- hourBuckets[h].score += posts[i]?.score ?? 0;- });-- const postsByDayOfWeek = dayBuckets.map((b, i) => ({- day: dayNames[i], shortDay: dayNames[i].slice(0, 3),- posts: b.count,- avgScore: b.count > 0 ? Math.round(b.score / b.count) : 0,- avgComments: b.count > 0 ? Math.round(b.comments / b.count) : 0,- }));- const bestDayObj = postsByDayOfWeek.reduce(- (best, d) => d.avgScore > best.avgScore ? d : best,- postsByDayOfWeek[0]- );-- const postsByHour = hourBuckets.map((b, i) => ({- hour: i, label: `${i}:00`,- posts: b.count,- avgScore: b.count > 0 ? Math.round(b.score / b.count) : 0,- }));- const bestHourObj = postsByHour.reduce(- (best, h) => h.avgScore > best.avgScore ? h : best,- postsByHour[0]- );-- // Monthly breakdown- const monthMap = {};- posts.forEach(p => {- if (!p.createdAt) return;- const d = new Date(p.createdAt);- if (isNaN(d)) return;- const key = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`;- if (!monthMap[key]) monthMap[key] = { posts: 0, score: 0, comments: 0 };- monthMap[key].posts++;- monthMap[key].score += p.score;- monthMap[key].comments += p.numComments;- });- const monthlyBreakdown = Object.entries(monthMap)- .sort(([a], [b]) => a.localeCompare(b))- .map(([month, s]) => ({- month, posts: s.posts, score: s.score, comments: s.comments,- avgScore: Math.round(s.score / s.posts),- }));-- // Recency counts- const now = Date.now();- const postsLast7Days = dates.filter(d => (now - d.getTime()) <= 7 * 86400000).length;- const postsLast30Days = dates.filter(d => (now - d.getTime()) <= 30 * 86400000).length;- const postsLast90Days = dates.filter(d => (now - d.getTime()) <= 90 * 86400000).length;-- // Post frequency- let perWeek = 0, perMonth = 0;- if (dates.length >= 2) {- const newest = Math.max(...dates.map(d => d.getTime()));- const oldest = Math.min(...dates.map(d => d.getTime()));- const spanDays = Math.max(1, (newest - oldest) / 86400000);- perWeek = parseFloat((posts.length / spanDays * 7).toFixed(1));- perMonth = parseFloat((posts.length / spanDays * 30).toFixed(1));- }-- // Virality and consistency- const bestScore = byScore[0]?.score ?? 0;- const viralityScore = avgScore > 0 ? parseFloat((bestScore / avgScore).toFixed(1)) : 0;-- let consistencyScore = 0;- if (posts.length >= 3) {- const scores = posts.map(p => p.score);- const mean = scores.reduce((s, v) => s + v, 0) / scores.length;- const variance = scores.reduce((s, v) => s + Math.pow(v - mean, 2), 0) / scores.length;- const stdDev = Math.sqrt(variance);- const cv = mean > 0 ? stdDev / mean : (stdDev > 0 ? 10 : 0);- consistencyScore = Math.max(0, Math.min(100, Math.round(100 / (1 + cv))));- }-- return {- fetchedPosts: posts.length,- totalScore, avgScore, medianScore,- totalComments, avgComments, avgUpvoteRatio,- totalAwards, avgAwards,- topPosts: byScore.slice(0, 10),- worstPosts: byScore.slice(-5).reverse(),- subredditBreakdown,- mediaTypeDistribution,- postsByDayOfWeek, bestPostingDay: bestDayObj?.day ?? '',- postsByHour, bestPostingHour: bestHourObj?.posts > 0 ? bestHourObj.label : '',- monthlyBreakdown, engagementTimeline: monthlyBreakdown,- postsLast7Days, postsLast30Days, postsLast90Days,- postFrequency: { perWeek, perMonth },- viralityScore, consistencyScore,- };+ return allPosts.slice(0, limit).map(normalizeRedditPost);}-// No-op: kept for compatibility with server.js cron handler.+// no-op kept because the server.js cron handler still calls itexport async function autoRefreshRedditSessions() {}function parseRedditPostUrl(rawUrl) {- let u;- try { u = new URL(rawUrl); } catch { throw new Error('Invalid URL - paste the full post link from reddit.com'); }- if (!u.hostname.includes('reddit.com')) throw new Error('Not a Reddit URL - paste a link from reddit.com');- const match = u.pathname.match(/^(\/r\/[^/]+\/comments\/[^/]+(?:\/[^/]+)?)\/?$/);+ let parsedUrl;+ try {+ parsedUrl = new URL(rawUrl);+ } catch {+ throw new Error('Invalid URL - paste the full post link from reddit.com');+ }+ if (!parsedUrl.hostname.includes('reddit.com')) throw new Error('Not a Reddit URL - paste a link from reddit.com');+ const match = parsedUrl.pathname.match(/^(\/r\/[^/]+\/comments\/[^/]+(?:\/[^/]+)?)\/?$/);if (!match) throw new Error('Not a Reddit post URL - paste the full post link including /r/.../comments/...');return match[1];}diff --git a/backend/services/reddit.test.js b/backend/services/reddit.test.jsnew file mode 100644index 0000000..b7f60b5--- /dev/null+++ b/backend/services/reddit.test.js@@ -0,0 +1,86 @@+import { test, describe, before, after, afterEach, mock } from 'node:test';+import { fetchRedditProfile, fetchRedditPosts, fetchTrackedPostData, autoRefreshRedditSessions } from './reddit.js';+import { assertGolden } from './fixtures/golden.js';+import { installFetch, reply } from './fixtures/fakeFetch.js';+import { FIXED_NOW, rawRedditPosts } from './fixtures/redditFixtures.js';++let fetchMock = null;+afterEach(() => fetchMock?.restore());++async function outcomeOf(promise) {+ try {+ return { value: await promise };+ } catch (err) {+ return { error: err.message };+ }+}++function listing(children, after = null) {+ return reply({ data: { children: children.map(data => ({ data })), after } });+}++describe('reddit api golden output', () => {+ before(() => mock.timers.enable({ apis: ['Date'], now: FIXED_NOW }));+ after(() => mock.timers.reset());++ test('maps a profile with and without optional fields', async () => {+ const bodies = [+ { data: { name: 'ribbon', total_karma: 900, link_karma: 600, comment_karma: 300, awardee_karma: 5, awarder_karma: 2, icon_img: 'https://i/a.png?x=1&y=2', created_utc: 1600000000, is_gold: true, is_mod: true, verified: true } },+ { data: { name: 'plain', link_karma: 4, comment_karma: 6, snoovatar_img: 'https://i/s.png' } },+ { data: { name: 'empty' } },+ ];+ fetchMock = installFetch((_request, count) => reply(bodies[count - 1]));+ const profiles = [+ await fetchRedditProfile('ribbon', 'COOKIE'),+ await fetchRedditProfile('plain', ''),+ await fetchRedditProfile('empty', null),+ ];+ assertGolden({ profiles, requests: fetchMock.requests }, 'reddit.profile');+ });++ test('maps posts, follows pages and stops at the limit', async () => {+ fetchMock = installFetch((request) => {+ const after = new URL(request.url).searchParams.get('after');+ if (!after) return listing(rawRedditPosts.slice(0, 3), 't3_c');+ if (after === 't3_c') return listing(rawRedditPosts.slice(3), 't3_e');+ return listing([]);+ });+ const posts = await fetchRedditPosts('ribbon', 'COOKIE');+ const limited = await fetchRedditPosts('ribbon', 'COOKIE', 2);+ assertGolden({ posts, limited, requests: fetchMock.requests }, 'reddit.posts');+ });++ test('maps a tracked post and rejects bad links and responses', async () => {+ const bodies = [+ [{ data: { children: [{ data: { id: 'p1', title: 'Tracked', subreddit: 'webdev', score: 77, upvote_ratio: 0.93, num_comments: 8, permalink: '/r/webdev/comments/p1/tracked/', over_18: false, created_utc: 1785000000 } }] } }],+ [{ data: { children: [{ data: { id: 'p2', title: 'Sparse', subreddit: 'misc', permalink: '/r/misc/comments/p2/' } }] } }],+ { kind: 'Listing' },+ [{ data: { children: [] } }],+ ];+ fetchMock = installFetch((_request, count) => reply(bodies[count - 1]));+ const outcomes = [];+ const links = [+ 'https://www.reddit.com/r/webdev/comments/p1/tracked/',+ 'https://old.reddit.com/r/misc/comments/p2',+ 'https://reddit.com/r/misc/comments/p3/x/',+ 'https://reddit.com/r/misc/comments/p4/x',+ 'not a url',+ 'https://example.com/r/misc/comments/p5/',+ 'https://reddit.com/user/ribbon/',+ ];+ for (const link of links) outcomes.push(await outcomeOf(fetchTrackedPostData(link, 'COOKIE')));+ assertGolden({ outcomes, requests: fetchMock.requests }, 'reddit.tracked');+ });++ test('turns http failures and api errors into messages', async () => {+ const script = [+ reply({}, 404, 'Not Found'), reply({}, 403, 'Forbidden'), reply({}, 429, 'Too Many Requests'),+ reply({}, 500, 'Server Error'), reply({ error: 400, message: 'Bad request' }), reply({ error: 401 }),+ ];+ fetchMock = installFetch((_request, count) => script[count - 1]);+ const outcomes = [];+ for (let i = 0; i < script.length; i++) outcomes.push(await outcomeOf(fetchRedditProfile('ribbon', 'COOKIE')));+ outcomes.push(await outcomeOf(autoRefreshRedditSessions()));+ assertGolden(outcomes, 'reddit.errors');+ });+});diff --git a/backend/services/redditAnalytics.js b/backend/services/redditAnalytics.jsnew file mode 100644index 0000000..d3549c7--- /dev/null+++ b/backend/services/redditAnalytics.js@@ -0,0 +1,153 @@+import {+ DAY_NAMES, sumOf, roundedAverage, medianOf, countWithinDays, postFrequency,+ consistencyScore, bestToAverageRatio, pickHighest, monthKey,+} from './analyticsMath.js';++const MAX_SUBREDDITS = 20;++function emptyRedditAnalytics() {+ return {+ fetchedPosts: 0, totalScore: 0, avgScore: 0, medianScore: 0,+ totalComments: 0, avgComments: 0, avgUpvoteRatio: 0,+ totalAwards: 0, avgAwards: 0,+ topPosts: [], worstPosts: [], subredditBreakdown: [],+ mediaTypeDistribution: {}, postsByDayOfWeek: [], postsByHour: [],+ monthlyBreakdown: [], engagementTimeline: [],+ postsLast7Days: 0, postsLast30Days: 0, postsLast90Days: 0,+ postFrequency: { perWeek: 0, perMonth: 0 },+ viralityScore: 0, consistencyScore: 0,+ bestPostingDay: '', bestPostingHour: '',+ };+}++function summarizeScores(posts) {+ const totalScore = sumOf(posts, post => post.score);+ const totalComments = sumOf(posts, post => post.numComments);+ const totalAwards = sumOf(posts, post => post.awardsCount ?? 0);+ const upvoteRatioSum = sumOf(posts, post => post.upvoteRatio);+ return {+ totalScore,+ avgScore: Math.round(totalScore / posts.length),+ medianScore: medianOf(posts.map(post => post.score)),+ totalComments,+ avgComments: Math.round(totalComments / posts.length),+ avgUpvoteRatio: parseFloat((upvoteRatioSum / posts.length * 100).toFixed(1)),+ totalAwards,+ avgAwards: parseFloat((totalAwards / posts.length).toFixed(2)),+ };+}++function buildSubredditBreakdown(posts) {+ const subreddits = {};+ posts.forEach(post => {+ const name = post.subreddit;+ if (!subreddits[name]) subreddits[name] = { subreddit: name, posts: 0, totalScore: 0, totalComments: 0 };+ subreddits[name].posts++;+ subreddits[name].totalScore += post.score;+ subreddits[name].totalComments += post.numComments;+ });+ return Object.values(subreddits)+ .map(entry => ({+ ...entry,+ avgScore: Math.round(entry.totalScore / entry.posts),+ avgComments: Math.round(entry.totalComments / entry.posts),+ }))+ .sort((first, second) => second.posts - first.posts)+ .slice(0, MAX_SUBREDDITS);+}++function buildMediaTypeDistribution(posts) {+ const distribution = {};+ posts.forEach(post => { distribution[post.mediaType] = (distribution[post.mediaType] ?? 0) + 1; });+ return distribution;+}++// dates skips posts without a date but is indexed against posts; kept to match stored analytics+function fillTimeBuckets(dates, posts) {+ const dayBuckets = Array(7).fill(null).map(() => ({ count: 0, score: 0, comments: 0 }));+ const hourBuckets = Array(24).fill(null).map(() => ({ count: 0, score: 0 }));+ dates.forEach((date, i) => {+ const dayBucket = dayBuckets[date.getDay()];+ dayBucket.count++;+ dayBucket.score += posts[i]?.score ?? 0;+ dayBucket.comments += posts[i]?.numComments ?? 0;+ const hourBucket = hourBuckets[date.getHours()];+ hourBucket.count++;+ hourBucket.score += posts[i]?.score ?? 0;+ });+ return { dayBuckets, hourBuckets };+}++function summarizeTiming(dates, posts) {+ const { dayBuckets, hourBuckets } = fillTimeBuckets(dates, posts);+ const postsByDayOfWeek = dayBuckets.map((bucket, i) => ({+ day: DAY_NAMES[i], shortDay: DAY_NAMES[i].slice(0, 3),+ posts: bucket.count,+ avgScore: roundedAverage(bucket.score, bucket.count),+ avgComments: roundedAverage(bucket.comments, bucket.count),+ }));+ const postsByHour = hourBuckets.map((bucket, i) => ({+ hour: i, label: `${i}:00`,+ posts: bucket.count,+ avgScore: roundedAverage(bucket.score, bucket.count),+ }));+ const bestDay = pickHighest(postsByDayOfWeek, 'avgScore');+ const bestHour = pickHighest(postsByHour, 'avgScore');+ return {+ postsByDayOfWeek, bestPostingDay: bestDay?.day ?? '',+ postsByHour, bestPostingHour: bestHour?.posts > 0 ? bestHour.label : '',+ };+}++function buildMonthlyBreakdown(posts) {+ const months = {};+ posts.forEach(post => {+ if (!post.createdAt) return;+ const date = new Date(post.createdAt);+ if (isNaN(date)) return;+ const key = monthKey(date);+ if (!months[key]) months[key] = { posts: 0, score: 0, comments: 0 };+ months[key].posts++;+ months[key].score += post.score;+ months[key].comments += post.numComments;+ });+ return Object.entries(months)+ .sort(([first], [second]) => first.localeCompare(second))+ .map(([month, totals]) => ({+ month, posts: totals.posts, score: totals.score, comments: totals.comments,+ avgScore: Math.round(totals.score / totals.posts),+ }));+}++function countRecentPosts(dates) {+ const now = Date.now();+ return {+ postsLast7Days: countWithinDays(dates, now, 7),+ postsLast30Days: countWithinDays(dates, now, 30),+ postsLast90Days: countWithinDays(dates, now, 90),+ };+}++export function computeRedditAnalytics(_profile, posts) {+ if (!posts || posts.length === 0) return emptyRedditAnalytics();++ const scores = summarizeScores(posts);+ const byScore = [...posts].sort((first, second) => second.score - first.score);+ const dates = posts.map(post => (post.createdAt ? new Date(post.createdAt) : null)).filter(Boolean);+ const monthlyBreakdown = buildMonthlyBreakdown(posts);++ return {+ fetchedPosts: posts.length,+ ...scores,+ topPosts: byScore.slice(0, 10),+ worstPosts: byScore.slice(-5).reverse(),+ subredditBreakdown: buildSubredditBreakdown(posts),+ mediaTypeDistribution: buildMediaTypeDistribution(posts),+ ...summarizeTiming(dates, posts),+ monthlyBreakdown, engagementTimeline: monthlyBreakdown,+ ...countRecentPosts(dates),+ postFrequency: postFrequency(dates, posts.length),+ viralityScore: bestToAverageRatio(byScore[0]?.score ?? 0, scores.avgScore),+ consistencyScore: consistencyScore(posts.map(post => post.score)),+ };+}diff --git a/backend/services/redditAnalytics.test.js b/backend/services/redditAnalytics.test.jsnew file mode 100644index 0000000..2af8469--- /dev/null+++ b/backend/services/redditAnalytics.test.js@@ -0,0 +1,39 @@+process.env.TZ = 'UTC';++import { test, describe, before, after, mock } from 'node:test';+import { computeRedditAnalytics } from './redditAnalytics.js';+import { assertGolden } from './fixtures/golden.js';+import { FIXED_NOW, richPosts, zeroScorePosts, generatedPosts } from './fixtures/redditFixtures.js';++const profile = { username: 'ribbon', totalKarma: 900 };++describe('computeRedditAnalytics golden output', () => {+ before(() => mock.timers.enable({ apis: ['Date'], now: FIXED_NOW }));+ after(() => mock.timers.reset());++ test('empty and missing posts return the empty state', () => {+ assertGolden({+ empty: computeRedditAnalytics(profile, []),+ missing: computeRedditAnalytics(profile, null),+ }, 'redditAnalytics.empty');+ });++ test('a varied account with a missing date, ties and a negative score', () => {+ assertGolden(computeRedditAnalytics(profile, richPosts), 'redditAnalytics.rich');+ });++ test('one and two posts cover the odd and even medians', () => {+ assertGolden({+ single: computeRedditAnalytics(profile, richPosts.slice(0, 1)),+ pair: computeRedditAnalytics(profile, richPosts.slice(1, 3)),+ }, 'redditAnalytics.small');+ });++ test('posts that all scored zero', () => {+ assertGolden(computeRedditAnalytics(profile, zeroScorePosts), 'redditAnalytics.zero');+ });++ test('more than twenty subreddits', () => {+ assertGolden(computeRedditAnalytics(profile, generatedPosts), 'redditAnalytics.generated');+ });+});diff --git a/docs/architecture/backend/SERVICES.md b/docs/architecture/backend/SERVICES.mdindex 9d9b5a9..0b9ba50 100644--- a/docs/architecture/backend/SERVICES.md+++ b/docs/architecture/backend/SERVICES.md@@ -123,7 +123,7 @@ async function ytFetch(path, params, env) {### HTTP Client-All Reddit public JSON API calls go through `redditFetch(path, cookie)`. Requests include a descriptive `User-Agent` header (required by Reddit). Cookie is optional - if provided, it is sent as `Cookie: reddit_session=<value>` for private account access and higher rate limits.+`reddit.js` holds the API code. All Reddit public JSON API calls go through `redditFetch(path, cookie)`, and `normalizeRedditPost()` maps each submitted post to the cached post shape. Requests include a descriptive `User-Agent` header (required by Reddit). Cookie is optional - if provided, it is sent as `Cookie: reddit_session=<value>` for private account access and higher rate limits.### Key Functions@@ -131,7 +131,7 @@ All Reddit public JSON API calls go through `redditFetch(path, cookie)`. Request|---|---|| `fetchRedditProfile(username, cookie)` | Fetches profile data from `/user/{username}/about.json` || `fetchRedditPosts(username, cookie, limit)` | Paginates submitted posts up to `limit` (default 100) via `/user/{username}/submitted.json` |-| `computeRedditAnalytics(profile, posts)` | Computes score stats, subreddit breakdown, posting time patterns, monthly breakdown, virality/consistency scores |+| `computeRedditAnalytics(profile, posts)` | Lives in `redditAnalytics.js` (re-exported by `reddit.js`); computes score stats, subreddit breakdown, media type distribution, posting time patterns, monthly breakdown, virality/consistency scores using the shared helpers in `analyticsMath.js` || `fetchTrackedPostData(postUrl, cookie)` | Fetches score, comments, and metadata for any public Reddit post URL using the `.json` trick; optionally uses a session cookie |### Credentials in responses