Commit
·
b41495f
1
Parent(s):
2c4b215
cleanup generating calendar data
Browse files- src/pages/index.tsx +16 -6
src/pages/index.tsx
CHANGED
|
@@ -36,15 +36,25 @@ export default function OpenSourceHeatmap() {
|
|
| 36 |
startDate.setMonth(today.getMonth() - 11);
|
| 37 |
startDate.setDate(1);
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
for (let d = new Date(startDate); d <= today; d.setDate(d.getDate() + 1)) {
|
| 40 |
const dateString = d.toISOString().split('T')[0];
|
| 41 |
|
| 42 |
-
Object.entries(PROVIDERS_MAP).forEach(([provider
|
| 43 |
-
const count =
|
| 44 |
-
item.createdAt.startsWith(dateString) &&
|
| 45 |
-
authors.some(author => item.id.startsWith(author))
|
| 46 |
-
).length;
|
| 47 |
-
|
| 48 |
data[provider].push({ date: dateString, count, level: 0 });
|
| 49 |
});
|
| 50 |
}
|
|
|
|
| 36 |
startDate.setMonth(today.getMonth() - 11);
|
| 37 |
startDate.setDate(1);
|
| 38 |
|
| 39 |
+
// create a map to store counts for each provider and date
|
| 40 |
+
const countMap: Record<string, Record<string, number>> = {};
|
| 41 |
+
|
| 42 |
+
modelData.forEach(item => {
|
| 43 |
+
const dateString = item.createdAt.split('T')[0];
|
| 44 |
+
Object.entries(PROVIDERS_MAP).forEach(([provider, { authors }]) => {
|
| 45 |
+
if (authors.some(author => item.id.startsWith(author))) {
|
| 46 |
+
countMap[provider] = countMap[provider] || {};
|
| 47 |
+
countMap[provider][dateString] = (countMap[provider][dateString] || 0) + 1;
|
| 48 |
+
}
|
| 49 |
+
});
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
// fill in with 0s for days with no activity
|
| 53 |
for (let d = new Date(startDate); d <= today; d.setDate(d.getDate() + 1)) {
|
| 54 |
const dateString = d.toISOString().split('T')[0];
|
| 55 |
|
| 56 |
+
Object.entries(PROVIDERS_MAP).forEach(([provider]) => {
|
| 57 |
+
const count = countMap[provider]?.[dateString] || 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
data[provider].push({ date: dateString, count, level: 0 });
|
| 59 |
});
|
| 60 |
}
|