ginigen-ai commited on
Commit
19f02ff
·
verified ·
1 Parent(s): eba5474

leaderboard: set VIDraft as primary (display+aggregation key), FINAL-Bench 2nd, GINIGEN accounts last; strict author prefix match

Browse files
Files changed (1) hide show
  1. src/utils/calendar.ts +85 -85
src/utils/calendar.ts CHANGED
@@ -1,85 +1,85 @@
1
- import {
2
- ModelData,
3
- ProviderInfo,
4
- CalendarData,
5
- Activity,
6
- } from "../types/heatmap";
7
-
8
- export const generateCalendarData = (
9
- modelData: ModelData[],
10
- providers: ProviderInfo[]
11
- ): CalendarData => {
12
- const data: Record<string, Activity[]> = Object.fromEntries(
13
- providers.map((provider) => [provider.authors[0], []]),
14
- );
15
-
16
- const today = new Date();
17
-
18
- // Calculate the first date to display GitHub-style:
19
- // 1. Go back 52 weeks (364 days) from today so we cover the last year.
20
- // 2. Shift further back to the previous Sunday (if necessary) so that
21
- // the first column of the heatmap always begins on a Sunday.
22
- const startDate = new Date(today);
23
- startDate.setDate(startDate.getDate() - 364);
24
-
25
- const dayOfWeek = startDate.getDay();
26
- startDate.setDate(startDate.getDate() - dayOfWeek);
27
-
28
- // create a map to store counts for each provider and date
29
- const countMap: Record<string, Record<string, number>> = {};
30
-
31
- modelData.forEach((item) => {
32
- const dateString = item.createdAt.split("T")[0];
33
- providers.forEach(({ authors }) => {
34
- if (authors.some((author) => item.id.startsWith(author))) {
35
- countMap[authors[0]] = countMap[authors[0]] || {};
36
- countMap[authors[0]][dateString] =
37
- (countMap[authors[0]][dateString] || 0) + 1;
38
- }
39
- });
40
- });
41
-
42
- // fill in with 0s for days with no activity
43
- for (let d = new Date(startDate); d <= today; d.setDate(d.getDate() + 1)) {
44
- const dateString = d.toISOString().split("T")[0];
45
-
46
- providers.forEach(({ authors }) => {
47
- const count = countMap[authors[0]]?.[dateString] || 0;
48
- data[authors[0]].push({ date: dateString, count, level: 0 });
49
- });
50
- }
51
-
52
- // calculate average counts for each provider
53
- const avgCounts = Object.fromEntries(
54
- Object.entries(data).map(([provider, days]) => [
55
- provider,
56
- days.reduce((sum, day) => sum + day.count, 0) / days.length || 0,
57
- ]),
58
- );
59
-
60
- const calculateLevel = (count: number, avgCount: number): number => {
61
- if (count === 0) {
62
- return 0;
63
- }
64
- if (count <= avgCount * 0.5) {
65
- return 1;
66
- }
67
- if (count <= avgCount) {
68
- return 2;
69
- }
70
- if (count <= avgCount * 1.5) {
71
- return 3;
72
- }
73
- return 4;
74
- };
75
-
76
- // assign levels based on count relative to average
77
- Object.entries(data).forEach(([provider, days]) => {
78
- const avgCount = avgCounts[provider];
79
- for (const day of days) {
80
- day.level = calculateLevel(day.count, avgCount);
81
- }
82
- });
83
-
84
- return data;
85
- };
 
1
+ import {
2
+ ModelData,
3
+ ProviderInfo,
4
+ CalendarData,
5
+ Activity,
6
+ } from "../types/heatmap";
7
+
8
+ export const generateCalendarData = (
9
+ modelData: ModelData[],
10
+ providers: ProviderInfo[]
11
+ ): CalendarData => {
12
+ const data: Record<string, Activity[]> = Object.fromEntries(
13
+ providers.map((provider) => [provider.authors[0], []]),
14
+ );
15
+
16
+ const today = new Date();
17
+
18
+ // Calculate the first date to display GitHub-style:
19
+ // 1. Go back 52 weeks (364 days) from today so we cover the last year.
20
+ // 2. Shift further back to the previous Sunday (if necessary) so that
21
+ // the first column of the heatmap always begins on a Sunday.
22
+ const startDate = new Date(today);
23
+ startDate.setDate(startDate.getDate() - 364);
24
+
25
+ const dayOfWeek = startDate.getDay();
26
+ startDate.setDate(startDate.getDate() - dayOfWeek);
27
+
28
+ // create a map to store counts for each provider and date
29
+ const countMap: Record<string, Record<string, number>> = {};
30
+
31
+ modelData.forEach((item) => {
32
+ const dateString = item.createdAt.split("T")[0];
33
+ providers.forEach(({ authors }) => {
34
+ if (authors.some((author) => item.id.startsWith(author + "/"))) {
35
+ countMap[authors[0]] = countMap[authors[0]] || {};
36
+ countMap[authors[0]][dateString] =
37
+ (countMap[authors[0]][dateString] || 0) + 1;
38
+ }
39
+ });
40
+ });
41
+
42
+ // fill in with 0s for days with no activity
43
+ for (let d = new Date(startDate); d <= today; d.setDate(d.getDate() + 1)) {
44
+ const dateString = d.toISOString().split("T")[0];
45
+
46
+ providers.forEach(({ authors }) => {
47
+ const count = countMap[authors[0]]?.[dateString] || 0;
48
+ data[authors[0]].push({ date: dateString, count, level: 0 });
49
+ });
50
+ }
51
+
52
+ // calculate average counts for each provider
53
+ const avgCounts = Object.fromEntries(
54
+ Object.entries(data).map(([provider, days]) => [
55
+ provider,
56
+ days.reduce((sum, day) => sum + day.count, 0) / days.length || 0,
57
+ ]),
58
+ );
59
+
60
+ const calculateLevel = (count: number, avgCount: number): number => {
61
+ if (count === 0) {
62
+ return 0;
63
+ }
64
+ if (count <= avgCount * 0.5) {
65
+ return 1;
66
+ }
67
+ if (count <= avgCount) {
68
+ return 2;
69
+ }
70
+ if (count <= avgCount * 1.5) {
71
+ return 3;
72
+ }
73
+ return 4;
74
+ };
75
+
76
+ // assign levels based on count relative to average
77
+ Object.entries(data).forEach(([provider, days]) => {
78
+ const avgCount = avgCounts[provider];
79
+ for (const day of days) {
80
+ day.level = calculateLevel(day.count, avgCount);
81
+ }
82
+ });
83
+
84
+ return data;
85
+ };