Repository: neherlab/covid19_scenarios
File: src/components/Main/Results/OutcomeRatesTable.tsx (TypeScript)

Code before:
    deathFrac    += freq * params.infectionSeverityRatio[d.ageGroup] * (d.critical / 100) * (d.fatal / 100)
  })

  let mildFrac = 1 - severeFrac - criticalFrac - deathFrac
  */

  const endResult = result.deterministicTrajectory[result.deterministicTrajectory.length - 1]

  const totalDeath = endResult.dead.total
  const totalSevere = endResult.discharged.total
  const totalCritical = endResult.intensive.total
  const totalCases = endResult.recovered.total + totalDeath

  const severeFrac = (1.0 * totalSevere) / totalCases
  const criticalFrac = (1.0 * totalCritical) / totalCases
  const deathFrac = (1.0 * totalDeath) / totalCases
  const mildFrac = 1 - severeFrac - criticalFrac - deathFrac

  const peakSevere = Math.round(Math.max(...result.deterministicTrajectory.map((x) => x.hospitalized.total)))
  const peakCritical = Math.round(
    Math.max(...result.deterministicTrajectory.map((x) => x.critical.total + x.overflow.total)),
  )

  const totalFormatter = (value: number) => (showHumanized ? humanizeFormatter(value) : decimalFormatter(value))

  // TODO: replace this with the table component (similar to severity table)
  return (
    <Row data-testid="OutcomeRatesTable">
      <Col lg={6}>
        <h5>{t('Proportions')}</h5>
        <table>
          <thead>
            <tr>
              <th>{t('Outcome')} &emsp; </th>
              <th>{t('Population average')}</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>{t('Mild')} [%]: </td>
              <td>{percentageFormatter(mildFrac)}</td>
            </tr>
            <tr>
              <td>{t('Severe')} [%]: </td>
              <td>{percentageFormatter(severeFrac)}</td>
            </tr>
            <tr>
              <td>{t('Critical')} [%]: </td>
              <td>{percentageFormatter(criticalFrac)}</td>
            </tr>
            <tr>

Review comment (suggestion):
This is causing some substantial inaccuracy of the tabular results.  e.g for US simulation, the total dead is 1.67M, that's being rounded all the way up to 2M.  Would it be better to round to a couple of decimal places?  330k difference is quite big.

Code after:
    severeFrac   += freq * params.infectionSeverityRatio[d.ageGroup]
    criticalFrac += freq * params.infectionSeverityRatio[d.ageGroup] * (d.critical / 100)
    deathFrac    += freq * params.infectionSeverityRatio[d.ageGroup] * (d.critical / 100) * (d.fatal / 100)
  })

  let mildFrac = 1 - severeFrac - criticalFrac - deathFrac
  */

  const endResult = result.deterministicTrajectory[result.deterministicTrajectory.length - 1]

  const totalDeath = endResult.dead.total
  const totalSevere = endResult.discharged.total
  const totalCritical = endResult.intensive.total
  const totalCases = endResult.recovered.total + totalDeath

  const severeFrac = (1.0 * totalSevere) / totalCases
  const criticalFrac = (1.0 * totalCritical) / totalCases
  const deathFrac = (1.0 * totalDeath) / totalCases
  const mildFrac = 1 - severeFrac - criticalFrac - deathFrac

  const peakSevere = Math.round(Math.max(...result.deterministicTrajectory.map((x) => x.hospitalized.total)))
  const peakCritical = Math.round(
    Math.max(...result.deterministicTrajectory.map((x) => x.critical.total + x.overflow.total)),
  )

  const totalFormatter = (value: number) => formatNumber(value)

  // TODO: replace this with the table component (similar to severity table)
  return (
    <Row data-testid="OutcomeRatesTable">
      <Col lg={6}>
        <h5>{t('Proportions')}</h5>
        <table>
          <thead>
            <tr>
              <th>{t('Outcome')} &emsp; </th>
              <th>{t('Population average')}</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>{t('Mild')} [%]: </td>
              <td>{percentageFormatter(mildFrac)}</td>
            </tr>
            <tr>
              <td>{t('Severe')} [%]: </td>
              <td>{percentageFormatter(severeFrac)}</td>
            </tr>
            <tr>
              <td>{t('Critical')} [%]: </td>
              <td>{percentageFormatter(criticalFrac)}</td>