From 6447b060b6b5339a62c08ff777a119a574f11912 Mon Sep 17 00:00:00 2001 From: Vlad-Stefan Harbuz Date: Sun, 4 Aug 2024 12:09:25 +0100 Subject: [PATCH] Add calculations to member page --- src/content/members/sentry.json | 30 +++++++++++++ src/content/members/test.json | 30 +++++++++++++ src/pages/members/[id].astro | 77 ++++++++++++++++++--------------- 3 files changed, 103 insertions(+), 34 deletions(-) create mode 100644 src/content/members/sentry.json create mode 100644 src/content/members/test.json diff --git a/src/content/members/sentry.json b/src/content/members/sentry.json new file mode 100644 index 00000000..a208cce8 --- /dev/null +++ b/src/content/members/sentry.json @@ -0,0 +1,30 @@ +{ + "domain": "sentry.io", + "datetimeModified": "2024-07-19T12:24:46Z", + "description": "Sentry has given to Open Source for soooooo many years.", + "name": "Sentry", + "urlLogoWithBackground": "https://fossfunders.com/logos/sentry.svg", + "urlLearnMore": "https://open.sentry.io/osspledge/", + "annualReports": [ + { + "dateYearEnding": "2023-01-31", + "averageNumberOfDevs": 135, + "monetaryPayments": [ + { + "amount": 435000, + "urlDetails": "https://thanks.dev/d/gh/getsentry/dependencies" + }, + { + "amount": 50000, + "urlDetails": "https://github.com/orgs/getsentry/sponsoring" + }, + { + "amount": 15000, + "urlDetails": "https://blog.sentry.io/we-just-gave-500-000-dollars-to-open-source-maintainers/" + } + ], + "monetaryValueOfTime": 100000, + "monetaryValueOfMaterials": 500000 + } + ] +} \ No newline at end of file diff --git a/src/content/members/test.json b/src/content/members/test.json new file mode 100644 index 00000000..a208cce8 --- /dev/null +++ b/src/content/members/test.json @@ -0,0 +1,30 @@ +{ + "domain": "sentry.io", + "datetimeModified": "2024-07-19T12:24:46Z", + "description": "Sentry has given to Open Source for soooooo many years.", + "name": "Sentry", + "urlLogoWithBackground": "https://fossfunders.com/logos/sentry.svg", + "urlLearnMore": "https://open.sentry.io/osspledge/", + "annualReports": [ + { + "dateYearEnding": "2023-01-31", + "averageNumberOfDevs": 135, + "monetaryPayments": [ + { + "amount": 435000, + "urlDetails": "https://thanks.dev/d/gh/getsentry/dependencies" + }, + { + "amount": 50000, + "urlDetails": "https://github.com/orgs/getsentry/sponsoring" + }, + { + "amount": 15000, + "urlDetails": "https://blog.sentry.io/we-just-gave-500-000-dollars-to-open-source-maintainers/" + } + ], + "monetaryValueOfTime": 100000, + "monetaryValueOfMaterials": 500000 + } + ] +} \ No newline at end of file diff --git a/src/pages/members/[id].astro b/src/pages/members/[id].astro index 8c5f1991..4608cd6f 100644 --- a/src/pages/members/[id].astro +++ b/src/pages/members/[id].astro @@ -12,22 +12,35 @@ const { member } = Astro.props; const reports = member.data.annualReports; function getPlatformName(url: string) { + let platformNames = { + 'github.com': 'GitHub Sponsors', + 'thanks.dev': 'Thanks.dev', + }; let host = ''; - let name = 'Other'; try { host = new URL(url).host; } catch (err) { - host = ''; } - switch(host) { - case 'github.com': - name = 'GitHub Sponsors'; - break; - case 'thanks.dev': - name = 'Thanks.dev'; - break; - } - return name; + return platformNames[host] || 'Other'; +} + +function getReportCashTotal(report) { + return report.monetaryPayments.map((d) => d.amount).reduce((acc, d) => acc + d, 0); +} + +function getReportFullTotal(report) { + return getReportCashTotal(report) + report.monetaryValueOfTime + report.monetaryValueOfMaterials; +} + +function getDollarsPerDev(report) { + return getReportCashTotal(report) / report.averageNumberOfDevs; +} + +function fmtCurrency(num) { + return '$' + num.toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }); } --- @@ -43,62 +56,58 @@ function getPlatformName(url: string) {

{member.data.description}

- Learn more ... + Learn more → {reports.map(report =>

Year Ending {report.dateYearEnding}

- $3700 / dev + {fmtCurrency(getDollarsPerDev(report))} / dev

Payments to Independent Maintainers

- - + + {report.monetaryPayments.map(entry => - + )} - - + + - - + + - +
PlatformAmount ($)PlatformAmount ($)
{entry.urlDetails && {getPlatformName(entry.urlDetails)}}{entry.amount}{fmtCurrency(entry.amount)}
total500000Total{fmtCurrency(getReportCashTotal(report))}
average number of devs{report.averageNumberOfDevs}Average number of devs{fmtCurrency(report.averageNumberOfDevs)}
$ / dev3700{fmtCurrency(getDollarsPerDev(report))}

Other Contributions

- + - - - - - - + + - - + + - - + + - - + +
ItemItem Amount ($)
value of time{report.monetaryValueOfTime}
value of materials{report.monetaryValueOfMaterials}Value of time{fmtCurrency(report.monetaryValueOfTime)}
600000Value of materials{fmtCurrency(report.monetaryValueOfMaterials)}
payments to independent maintainers500000Payments to independent maintainers{fmtCurrency(getReportCashTotal(report))}
total1100000Total{fmtCurrency(getReportFullTotal(report))}
)}