|
| 1 | +import { Table } from '../../knip/src/util/table.ts'; |
| 2 | +import { getGitHubTotals } from './get-monthly-sponsorships-github.ts'; |
| 3 | +import { getOpenCollectiveTotals } from './get-monthly-sponsorships-opencollective.ts'; |
| 4 | + |
| 5 | +const START_DATE = new Date('2023-11-01'); |
| 6 | +const END_DATE = new Date(); |
| 7 | +END_DATE.setDate(1); |
| 8 | +END_DATE.setHours(-1); |
| 9 | + |
| 10 | +const main = async () => { |
| 11 | + const [monthlyGHS, monthlyGHSRO, monthlyOC, monthlyOCRO] = await Promise.all([ |
| 12 | + getGitHubTotals({ startDate: START_DATE, endDate: END_DATE, recurringOnly: false }), |
| 13 | + getGitHubTotals({ startDate: START_DATE, endDate: END_DATE, recurringOnly: true }), |
| 14 | + getOpenCollectiveTotals({ startDate: START_DATE, endDate: END_DATE, recurringOnly: false }), |
| 15 | + getOpenCollectiveTotals({ startDate: START_DATE, endDate: END_DATE, recurringOnly: true }), |
| 16 | + ]); |
| 17 | + |
| 18 | + const monthly = new Map<string, number[]>(); |
| 19 | + for (const [month, amount] of monthlyGHS) monthly.set(month, [...(monthly.get(month) || []), amount]); |
| 20 | + for (const [month, amount] of monthlyOC) monthly.set(month, [...(monthly.get(month) || []), amount]); |
| 21 | + |
| 22 | + const monthlyRO = new Map<string, number[]>(); |
| 23 | + for (const [month, amount] of monthlyGHSRO) monthlyRO.set(month, [...(monthlyRO.get(month) || []), amount]); |
| 24 | + for (const [month, amount] of monthlyOCRO) monthlyRO.set(month, [...(monthlyRO.get(month) || []), amount]); |
| 25 | + |
| 26 | + const table = new Table(); |
| 27 | + const digits = (n: number) => (v: any) => (typeof v === 'number' ? v.toFixed(n) : v); |
| 28 | + const sum = Array.from(monthly.values()).reduce((a, c) => a + c.reduce((a, b) => a + b, 0), 0); |
| 29 | + const sumGHS = Array.from(monthlyGHS.values()).reduce((a, c) => a + c, 0); |
| 30 | + const sumOC = Array.from(monthlyOC.values()).reduce((a, c) => a + c, 0); |
| 31 | + const sumRO = Array.from(monthlyRO.values()).reduce((a, c) => a + c.reduce((a, b) => a + b, 0), 0); |
| 32 | + for (const [key, value] of [ |
| 33 | + ['months', monthly.size], |
| 34 | + ['github', sumGHS], |
| 35 | + ['OC', sumOC], |
| 36 | + ['sum', sum], |
| 37 | + ['avg', sum / monthly.size], |
| 38 | + ['recurring sum', sumRO], |
| 39 | + ['recurring avg', sumRO / monthlyRO.size], |
| 40 | + ]) { |
| 41 | + table.row(); |
| 42 | + table.cell('key', key); |
| 43 | + table.cell('value', value, digits(0)); |
| 44 | + } |
| 45 | + |
| 46 | + console.log(table.toString()); |
| 47 | + |
| 48 | + const url = new URL('/', 'https://try.venz.dev'); |
| 49 | + url.searchParams.set('type', 'pivot'); |
| 50 | + url.searchParams.set('lp', 'tr'); |
| 51 | + url.searchParams.set('br', '0'); |
| 52 | + url.searchParams.set('labelX', 'month'); |
| 53 | + url.searchParams.set('labelY', 'amount ($)'); |
| 54 | + url.searchParams.append('l', 'GitHub Sponsors'); |
| 55 | + url.searchParams.append('color', '#fbfbfb'); |
| 56 | + url.searchParams.append('l', 'Open Collective'); |
| 57 | + url.searchParams.append('color', '#2487ff'); |
| 58 | + for (const [month, amount] of monthly) { |
| 59 | + url.searchParams.append('label', month); |
| 60 | + url.searchParams.append('data', amount.join(',')); |
| 61 | + } |
| 62 | + |
| 63 | + console.log('\nVenz link'); |
| 64 | + const text = `${url.origin}?${decodeURIComponent(url.searchParams.toString()).replaceAll('#', '%23')}`; |
| 65 | + console.log(text); |
| 66 | +}; |
| 67 | + |
| 68 | +main().catch(console.error); |
0 commit comments