From 36953e1a50f5c2aa976f788e3e608fc815e40b5f Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Tue, 2 Jul 2024 13:43:02 +0100 Subject: [PATCH] Show review requests per year Refs #27 --- src/requests.md | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/requests.md b/src/requests.md index 3910a46..c3826d1 100644 --- a/src/requests.md +++ b/src/requests.md @@ -26,6 +26,15 @@ const now = new Date() const firstRequest = d3.min(requests, request => request.timestamp) ``` +```js +const chosenYear = view( + Inputs.select([null, ..._.range(now.getUTCFullYear(), firstRequest.getUTCFullYear() - 1)], { + label: 'Year', + format: year => year ?? 'All-time', + }), +) +``` + ```js const chosenDomain = view( Inputs.select([null, ...Object.keys(openAlexDomains)], { @@ -56,11 +65,15 @@ const chosenField = view( ``` ```js +const requestsInTimePeriod = chosenYear + ? requests.filter(request => request.timestamp.getUTCFullYear() === chosenYear) + : requests + const requestsSelected = chosenField - ? requests.filter(d => d.fields.includes(chosenField)) + ? requestsInTimePeriod.filter(d => d.fields.includes(chosenField)) : chosenDomain - ? requests.filter(d => d.domains.includes(chosenDomain)) - : requests + ? requestsInTimePeriod.filter(d => d.domains.includes(chosenDomain)) + : requestsInTimePeriod ``` ```js @@ -106,16 +119,16 @@ const requestsBySubfield = requestsSelected
-

${chosenField ? `${openAlexFields[chosenField].name} requests` : chosenDomain ? `${openAlexDomains[chosenDomain]} requests` : 'Requests'}

+

${chosenField ? `${openAlexFields[chosenField].name} requests` : chosenDomain ? `${openAlexDomains[chosenDomain]} requests` : 'Requests'} ${chosenYear ? `in ${chosenYear}` : ''}

${requestsSelected.length.toLocaleString("en-US")} ${requestsGroupedByPreprint.size !== requestsSelected.length ? html` for ${requestsGroupedByPreprint.size.toLocaleString("en-US")} preprints ` : ''} ${chosenField ? html` -
${d3.format(".1%")(requestsSelected.length / requests.filter(d => d.domains.includes(chosenDomain)).length)} of all ${openAlexDomains[chosenDomain]} requests
+
${d3.format(".1%")(requestsSelected.length / requestsInTimePeriod.filter(d => d.domains.includes(chosenDomain)).length)} of all ${openAlexDomains[chosenDomain]} requests
` : ''} ${chosenDomain ? html` -
${d3.format(".1%")(requestsSelected.length / requests.length)} of all requests
+
${d3.format(".1%")(requestsSelected.length / requestsInTimePeriod.length)} of all requests
` : ''}
@@ -126,11 +139,11 @@ const requestsBySubfield = requestsSelected ` : ''} ${requestsWithAReviewGroupedByPreprint.size === 0 ? '' : chosenField ? html` -
${d3.format(".1%")(requestsWithAReview.length / requests.filter(d => d.fields.includes(chosenField)).length)} of all ${openAlexFields[chosenField].name} requests
+
${d3.format(".1%")(requestsWithAReview.length / requestsInTimePeriod.filter(d => d.fields.includes(chosenField)).length)} of all ${openAlexFields[chosenField].name} requests ${chosenYear ? `in ${chosenYear}` : ''}
` : chosenDomain ? html` -
${d3.format(".1%")(requestsWithAReview.length / requests.filter(d => d.domains.includes(chosenDomain)).length)} of all ${openAlexDomains[chosenDomain]} requests
+
${d3.format(".1%")(requestsWithAReview.length / requestsInTimePeriod.filter(d => d.domains.includes(chosenDomain)).length)} of all ${openAlexDomains[chosenDomain]} requests ${chosenYear ? `in ${chosenYear}` : ''}
` : html` -
${d3.format(".1%")(requestsWithAReview.length / requests.length)} of all requests
+
${d3.format(".1%")(requestsWithAReview.length / requestsInTimePeriod.length)} of all requests ${chosenYear ? `in ${chosenYear}` : ''}
`}
@@ -151,7 +164,12 @@ function requestsByLanguageTimeline({ width } = {}) { tickFormat: languageName, }, y: { grid: true, label: 'Requests', tickFormat: Math.floor, interval: 1 }, - x: { label: '', domain: [d3.utcSunday.floor(firstRequest), d3.utcSunday.ceil(now)] }, + x: { + label: '', + domain: chosenYear + ? [new Date(chosenYear, 0, 1, 0, 0, 0, 0), new Date(chosenYear + 1, 0, 1, 0, 0, 0, 0)] + : [d3.utcSunday.floor(firstRequest), d3.utcSunday.ceil(now)], + }, marks: [ Plot.rectY( requestsSelected, @@ -186,10 +204,10 @@ function requestsByLanguageTimeline({ width } = {}) { function requestsByFieldTimeline({ width } = {}) { return Plot.plot({ title: chosenField - ? `Subfields of ${openAlexFields[chosenField].name} requests (request may have multiple subfields)` + ? `Subfields of ${openAlexFields[chosenField].name} requests ${chosenYear ? `in ${chosenYear}` : ''} (request may have multiple subfields)` : chosenDomain - ? `Fields of ${openAlexDomains[chosenDomain]} requests (request may have multiple fields)` - : 'Fields of requests (request may have multiple fields)', + ? `Fields of ${openAlexDomains[chosenDomain]} requests ${chosenYear ? `in ${chosenYear}` : ''} (request may have multiple fields)` + : `Fields of requests ${chosenYear ? `in ${chosenYear}` : ''} (request may have multiple fields)`, width: Math.max(width, 600), color: { ...languageColor,