Skip to content

Commit

Permalink
Filter reviews by requests
Browse files Browse the repository at this point in the history
Refs #26
  • Loading branch information
thewilkybarkid committed Aug 6, 2024
1 parent 1640988 commit 2d4c0dc
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/reviews.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const languageNames = new Intl.DisplayNames(['en-US'], { type: 'language' })
const languageName = code => (code ? languageNames.of(code) : 'Unknown')

const preprintServers = FileAttachment('./data/preprint-servers.json').json()
const requests = FileAttachment('./data/requests.json').json()
const reviews = FileAttachment('./data/reviews.json')
.json()
.then(data => data.map(review => ({ ...review, createdAt: parseDate(review.createdAt) })))
Expand All @@ -21,6 +22,7 @@ const reviews = FileAttachment('./data/reviews.json')
const now = new Date()
const firstReview = d3.min(reviews, review => review.createdAt)

const preprintsWithRequest = new d3.InternSet(d3.group(requests, request => request.preprint).keys())
const preprintServerName = id => preprintServers[id]

const reviewType = id => {
Expand Down Expand Up @@ -51,17 +53,23 @@ const chosenType = view(
format: type => reviewType(type) ?? 'All',
}),
)

const chosenRequest = view(Inputs.toggle({ label: 'Requested review' }))
```
```js
const reviewsInTimePeriod = chosenYear
? reviews.filter(review => review.createdAt.getUTCFullYear() === chosenYear)
: reviews

const reviewsSelected = chosenType
? reviewsInTimePeriod.filter(review => review.type === chosenType)
const reviewsWithRequest = chosenRequest
? reviewsInTimePeriod.filter(review => preprintsWithRequest.has(review.preprint))
: reviewsInTimePeriod

const reviewsSelected = chosenType
? reviewsWithRequest.filter(review => review.type === chosenType)
: reviewsWithRequest

const languageColor = Plot.scale({
color: {
type: 'categorical',
Expand All @@ -82,9 +90,9 @@ const languageColor = Plot.scale({
<div class="grid grid-cols-4">
<div class="card">
<h2>${chosenType ? reviewType(chosenType) : ''} PREreviews ${chosenYear ? ` in ${chosenYear}` : ''}</h2>
<h2>${chosenRequest ? 'Requested ' : ''}${chosenType ? reviewType(chosenType) : ''} PREreviews ${chosenYear ? ` in ${chosenYear}` : ''}</h2>
<span class="big">${reviewsSelected.length.toLocaleString("en-US")}</span>
${chosenType ? html`
${chosenRequest | chosenType ? html`
<div>${d3.format(".1%")(reviewsSelected.length / reviewsInTimePeriod.length)} of all PREreviews</div>
` : ''}
</div>
Expand All @@ -93,7 +101,7 @@ const languageColor = Plot.scale({
```js
function reviewsTimeline({ width } = {}) {
return Plot.plot({
title: `${chosenType ? reviewType(chosenType) : ''} PREreviews per ${chosenYear ? 'week' : 'month'}`,
title: `${chosenRequest ? 'Requested ' : ''}${chosenType ? reviewType(chosenType) : ''} PREreviews per ${chosenYear ? 'week' : 'month'}`,
width: Math.max(width, 600),
height: 400,
color: {
Expand Down Expand Up @@ -140,7 +148,7 @@ function reviewsTimeline({ width } = {}) {
```js
function reviewsByPreprintServer({ width } = {}) {
return Plot.plot({
title: `${chosenType ? reviewType(chosenType) : ''} PREreviews ${chosenYear ? `in ${chosenYear}` : ''} by preprint server`,
title: `${chosenRequest ? 'Requested ' : ''}${chosenType ? reviewType(chosenType) : ''} PREreviews ${chosenYear ? `in ${chosenYear}` : ''} by preprint server`,
width: Math.max(width, 600),
color: {
...languageColor,
Expand Down

0 comments on commit 2d4c0dc

Please sign in to comment.