Don't show Daily movers if there are none. Threshold is 1%

This commit is contained in:
James Grugett 2022-09-17 19:47:04 -05:00
parent 3bddda37d2
commit d8e9e7812a
2 changed files with 22 additions and 10 deletions

View File

@ -20,18 +20,21 @@ export function ProbChangeTable(props: {
const { positiveChanges, negativeChanges } = changes
const threshold = 0.075
const countOverThreshold = Math.max(
positiveChanges.findIndex((c) => c.probChanges.day < threshold) + 1,
negativeChanges.findIndex((c) => c.probChanges.day > -threshold) + 1
const threshold = 0.01
const positiveAboveThreshold = positiveChanges.filter(
(c) => c.probChanges.day > threshold
)
const maxRows = Math.min(positiveChanges.length, negativeChanges.length)
const rows = full
? maxRows
: Math.min(3, Math.min(maxRows, countOverThreshold))
const negativeAboveThreshold = negativeChanges.filter(
(c) => c.probChanges.day < threshold
)
const maxRows = Math.min(
positiveAboveThreshold.length,
negativeAboveThreshold.length
)
const rows = full ? maxRows : Math.min(3, maxRows)
const filteredPositiveChanges = positiveChanges.slice(0, rows)
const filteredNegativeChanges = negativeChanges.slice(0, rows)
const filteredPositiveChanges = positiveAboveThreshold.slice(0, rows)
const filteredNegativeChanges = negativeAboveThreshold.slice(0, rows)
if (rows === 0) return <div className="px-4 text-gray-500">None</div>

View File

@ -242,6 +242,15 @@ function DailyMoversSection(props: { userId: string | null | undefined }) {
const { userId } = props
const changes = useProbChangesAlgolia(userId ?? '')
if (changes) {
const { positiveChanges, negativeChanges } = changes
if (
!positiveChanges.find((c) => c.probChanges.day >= 0.01) ||
!negativeChanges.find((c) => c.probChanges.day <= -0.01)
)
return null
}
return (
<Col className="gap-2">
<SectionHeader label="Daily movers" href="/daily-movers" />