Skip to content

Commit

Permalink
Show the number of review requests per week
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Jun 20, 2024
1 parent cf12bd3 commit e715883
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@effect/platform": "^0.57.4",
"@effect/platform-node": "^0.51.13",
"@effect/schema": "^0.68.1",
"@js-temporal/polyfill": "^0.4.4",
"@observablehq/framework": "^1.9.0",
"d3-dsv": "^3.0.1",
"d3-time-format": "^4.1.0",
Expand Down
3 changes: 2 additions & 1 deletion src/data/requests.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { HttpClient, Terminal } from '@effect/platform'
import { NodeTerminal } from '@effect/platform-node'
import { Schema } from '@effect/schema'
import { Effect } from 'effect'
import * as Temporal from '../lib/Temporal.js'

const Requests = Schema.Array(Schema.Struct({}))
const Requests = Schema.Array(Schema.Struct({ timestamp: Temporal.InstantFromStringSchema }))

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

export const { Instant } = Temporal

export type Instant = Temporal.Instant

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

export const InstantFromStringSchema: Schema.Schema<Instant, string> = Schema.transformOrFail(
Schema.String,
InstantFromSelfSchema,
{
decode: (date, _, ast) =>
ParseResult.try({
try: () => Instant.from(date),
catch: () => new ParseResult.Type(ast, date),
}),
encode: instant => ParseResult.succeed(instant.toString()),
},
)
32 changes: 31 additions & 1 deletion src/requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ toc: false
# Review requests 🤞

```js
const requests = FileAttachment('./data/requests.json').json()
const parseTimestamp = d3.utcParse('%Y-%m-%dT%H:%M:%S.%LZ')

const requests = FileAttachment('./data/requests.json')
.json()
.then(data => data.map(request => ({ ...request, timestamp: parseTimestamp(request.timestamp) })))
```

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

```js
function requestsTimeline({ width } = {}) {
return Plot.plot({
title: 'Requests per week',
width: Math.max(width, 600),
height: 400,
color: {},
y: { grid: true, label: 'Requests' },
x: { label: '' },
marks: [
Plot.rectY(
requests,
Plot.binX({ y: 'count' }, { x: 'timestamp', interval: d3.utcWeek, fill: 'var(--theme-foreground-focus)' }),
),
Plot.ruleY([0]),
],
})
}
```

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

0 comments on commit e715883

Please sign in to comment.