Skip to content

Commit

Permalink
Merge pull request #2352 from lpsinger/rateUpperBound
Browse files Browse the repository at this point in the history
Render small or zero rate estimates as `<1 alert per week`
  • Loading branch information
dakota002 authored Jun 10, 2024
2 parents d8d6d0c + 40a352b commit b1503e3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/components/NoticeTypeCheckboxes/NoticeTypeCheckboxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ import type { NoticeFormat } from '../NoticeFormat'
import { NestedCheckboxes } from '../nested-checkboxes/NestedCheckboxes'
import { triggerRate } from './rates'

const minRate = 1 / 7

function humanizedCount(count: number, singular: string, plural?: string) {
const noun = count === 1 ? singular : plural ?? `${singular}s`
return `${count} ${noun}`
}

function humanizedRate(rate: number, singular: string, plural?: string) {
let isUpperBound
if (rate < minRate) {
isUpperBound = true
rate = minRate
}

let unit = 'day'
if (rate) {
for (const { factor, unit: proposedUnit } of [
Expand All @@ -30,7 +38,7 @@ function humanizedRate(rate: number, singular: string, plural?: string) {
if (rate > 0.5) break
}
}
return `${humanizedCount(Math.round(rate), singular, plural)} per ${unit}`
return `${isUpperBound ? '< ' : ''}${humanizedCount(Math.round(rate), singular, plural)} per ${unit}`
}

const NoticeTypes = {
Expand Down Expand Up @@ -280,7 +288,7 @@ export function NoticeTypeCheckboxes({
childoncheckhandler={counterfunction}
/>
<div className="text-bold text-ink">
{humanizedCount(selectedCounter, 'notice type')} selected for about{' '}
{humanizedCount(selectedCounter, 'notice type')} selected for{' '}
{humanizedRate(alertEstimate, 'alert')}
</div>
</>
Expand Down

0 comments on commit b1503e3

Please sign in to comment.