From dc51758f0e075d326ada855ccb803d2b437224cc Mon Sep 17 00:00:00 2001 From: Jeffrey Yasskin Date: Tue, 17 Oct 2023 16:47:30 -0700 Subject: [PATCH] Draw bug age distributions as box & whisker plots. --- frontend/src/components/BugStats.astro | 123 +++++++++++++++++++++++-- frontend/src/layouts/Layout.astro | 10 +- frontend/src/lib/formatRoundAge.ts | 8 +- frontend/src/lib/repo-summaries.ts | 12 ++- frontend/src/pages/index.astro | 83 ++++++++++------- 5 files changed, 183 insertions(+), 53 deletions(-) diff --git a/frontend/src/components/BugStats.astro b/frontend/src/components/BugStats.astro index 1aedaee..e49e5eb 100644 --- a/frontend/src/components/BugStats.astro +++ b/frontend/src/components/BugStats.astro @@ -1,21 +1,126 @@ --- +import type { Temporal } from "@js-temporal/polyfill"; import { formatRoundAge } from "@lib/formatRoundAge"; import type { AgeStats } from "@lib/repo-summaries"; interface Props { ageStats: AgeStats; description: string; + /** The global maximum bug age, to render at the right side of the chart. */ + maxAge: Temporal.Duration; } -const { ageStats, description } = Astro.props; +const { ageStats, description, maxAge } = Astro.props; -const percentiles = [10, 25, 50, 75, 90]; +const maxAgeS = maxAge.total("seconds"); +const p10Frac = + Math.round((ageStats[10].total("seconds") / maxAgeS) * 1000) / 10; +const p25Frac = + Math.round((ageStats[25].total("seconds") / maxAgeS) * 1000) / 10; +const p50Frac = + Math.round((ageStats[50].total("seconds") / maxAgeS) * 1000) / 10; +const p75Frac = + Math.round((ageStats[75].total("seconds") / maxAgeS) * 1000) / 10; +const p90Frac = + Math.round((ageStats[90].total("seconds") / maxAgeS) * 1000) / 10; +const meanFrac = + Math.round((ageStats.mean.total("seconds") / maxAgeS) * 1000) / 10; --- -
-

{ageStats.count}{' '}{description}: mean age {formatRoundAge(ageStats.mean)}

- - {percentiles.map((p) => )} - {percentiles.map((p) => )} + + +
{p}th %ile
{formatRoundAge(ageStats[p])}
-
+ +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • + + + + diff --git a/frontend/src/layouts/Layout.astro b/frontend/src/layouts/Layout.astro index 1a88ce6..e9fcc54 100644 --- a/frontend/src/layouts/Layout.astro +++ b/frontend/src/layouts/Layout.astro @@ -19,9 +19,13 @@ const { title } = Astro.props;