forked from GenSpectrum/cov-spectrum-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoreMetrics.tsx
47 lines (44 loc) · 1.66 KB
/
CoreMetrics.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Card, NamedCardStyle } from './NamedCard';
import Metric from '../widgets/Metrics';
import { GridCell, PackedGrid } from './PackedGrid';
import { DateCountSampleDataset } from '../data/sample/DateCountSampleDataset';
import { useMemo } from 'react';
export type CoreMetricsProps = {
variantSampleSet: DateCountSampleDataset;
wholeSampleSet: DateCountSampleDataset;
};
export const CoreMetrics = ({ variantSampleSet, wholeSampleSet }: CoreMetricsProps) => {
const { totalSequences, overallProportion } = useMemo(() => {
const totalVariantSequences = variantSampleSet.payload.reduce((prev, curr) => prev + curr.count, 0);
const totalOverallSequences = wholeSampleSet.payload.reduce((prev, curr) => prev + curr.count, 0);
return {
totalSequences: totalVariantSequences,
overallProportion: totalVariantSequences / totalOverallSequences,
};
}, [variantSampleSet, wholeSampleSet]);
return (
<>
<PackedGrid maxColumns={3}>
<GridCell minWidth={150}>
<Card namedCardStyle={NamedCardStyle.NORMAL}>
<Metric
value={totalSequences}
title='Total sequences'
helpText='The total number of sequenced samples'
/>
</Card>
</GridCell>
<GridCell minWidth={150}>
<Card namedCardStyle={NamedCardStyle.NORMAL}>
<Metric
value={(overallProportion * 100).toFixed(2)}
title='Overall proportion'
helpText='The proportion among all sequenced samples in the selected time frame'
percent={true}
/>
</Card>
</GridCell>
</PackedGrid>
</>
);
};