Skip to content

Commit

Permalink
Show the number of PREreviews per month
Browse files Browse the repository at this point in the history
Refs #19
  • Loading branch information
thewilkybarkid committed Jul 1, 2024
1 parent b8c205d commit 23bd911
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/data/reviews.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import { HttpClient, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Config, Effect, Redacted } from 'effect'
import * as Temporal from '../lib/Temporal.js'

const Reviews = Schema.Array(Schema.Struct({}))
const Reviews = Schema.Array(
Schema.Struct({
createdAt: Temporal.PlainDateFromStringSchema,
}),
)

const program = Effect.gen(function* () {
const terminal = yield* Terminal.Terminal
Expand Down
18 changes: 17 additions & 1 deletion src/lib/Temporal.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { ParseResult, Schema } from '@effect/schema'
import { Temporal } from '@js-temporal/polyfill'

export const { Instant } = Temporal
export const { Instant, PlainDate } = Temporal

export type Instant = Temporal.Instant
export type PlainDate = Temporal.PlainDate

export const InstantFromSelfSchema = Schema.instanceOf(Temporal.Instant)

export const PlainDateFromSelfSchema = Schema.instanceOf(PlainDate)

export const InstantFromStringSchema: Schema.Schema<Instant, string> = Schema.transformOrFail(
Schema.String,
InstantFromSelfSchema,
Expand All @@ -19,3 +22,16 @@ export const InstantFromStringSchema: Schema.Schema<Instant, string> = Schema.tr
encode: instant => ParseResult.succeed(instant.toString()),
},
)

export const PlainDateFromStringSchema: Schema.Schema<PlainDate, string> = Schema.transformOrFail(
Schema.String,
PlainDateFromSelfSchema,
{
decode: (date, _, ast) =>
ParseResult.try({
try: () => PlainDate.from(date, { overflow: 'reject' }),
catch: () => new ParseResult.Type(ast, date),
}),
encode: plainDate => ParseResult.succeed(plainDate.toString()),
},
)
42 changes: 41 additions & 1 deletion src/reviews.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ toc: false
# PREreviews ✍️

```js
const reviews = FileAttachment('./data/reviews.json').json()
const parseDate = d3.utcParse('%Y-%m-%d')

const reviews = FileAttachment('./data/reviews.json')
.json()
.then(data => data.map(review => ({ ...review, createdAt: parseDate(review.createdAt) })))
```

```js
const now = new Date()
const firstReview = d3.min(reviews, review => review.createdAt)
```

<div class="grid grid-cols-4">
Expand All @@ -16,3 +25,34 @@ const reviews = FileAttachment('./data/reviews.json').json()
<span class="big">${reviews.length.toLocaleString("en-US")}</span>
</div>
</div>

```js
function reviewsTimeline({ width } = {}) {
return Plot.plot({
title: 'PREreviews per month',
width: Math.max(width, 600),
height: 400,
y: { grid: true, label: 'PREreviews', tickFormat: Math.floor, interval: 1 },
x: { label: '', domain: [d3.utcMonth.floor(firstReview), d3.utcMonth.ceil(now)] },
marks: [
Plot.rectY(
reviews,
Plot.binX(
{ y: 'count' },
{
x: 'createdAt',
interval: d3.utcMonth,
tip: true,
},
),
),
],
})
}
```

<div class="grid grid-cols-1">
<div class="card">
${resize((width) => reviewsTimeline({width}))}
</div>
</div>

0 comments on commit 23bd911

Please sign in to comment.