This repository was archived by the owner on Jan 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressStatistics.tsx
88 lines (76 loc) · 3.21 KB
/
ProgressStatistics.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react';
import { Box, SimpleGrid, useColorModeValue } from '@chakra-ui/react';
import { useAppSelector } from '../../app/hooks';
import { selectMatchedNodes } from '../packageData/apiSlice';
import { selectAllAnnotationsOnTargets, selectAnnotationStore } from '../annotations/annotationSlice';
import { Pie } from 'react-chartjs-2';
import { ArcElement, Chart as ChartJS, Title, Tooltip } from 'chart.js';
ChartJS.register(ArcElement, Title, Tooltip);
export const ProgressStatistics = function () {
const completeOrCorrectBg = useColorModeValue('rgba(56, 161, 105, 0.2)', 'rgba(104, 211, 145, 0.2)');
const completeOrCorrectBorder = useColorModeValue('rgba(47, 133, 90, 1)', 'rgba(153, 230, 179, 1)');
const uncheckedBg = useColorModeValue('rgba(204, 204, 204, 0.2)', 'rgba(136, 136, 136, 0.2)');
const uncheckedBorder = useColorModeValue('rgba(170, 170, 170, 1)', 'rgba(170, 170, 170, 1)');
const textColor = useColorModeValue('#000', '#FFF');
// Completion Progress
const completed = useAppSelector(selectAnnotationStore).completeAnnotations;
const matchedNodes = useAppSelector(selectMatchedNodes);
const numberOfMatchedNodes = matchedNodes.length;
const numberOfCompleteMatchedNodes = matchedNodes.filter((it) => it.id in completed).length;
const completionData = {
labels: ['Complete', 'Unchecked'],
datasets: [
{
data: [numberOfCompleteMatchedNodes, numberOfMatchedNodes - numberOfCompleteMatchedNodes],
backgroundColor: [completeOrCorrectBg, uncheckedBg],
borderColor: [completeOrCorrectBorder, uncheckedBorder],
borderWidth: 1,
},
],
};
const completionOptions = {
plugins: {
title: {
display: true,
text: 'Completion Progress',
color: textColor,
},
},
};
// Review Progress
const allAnnotations = useAppSelector(selectAllAnnotationsOnTargets(matchedNodes.map((it) => it.id)));
const numberOfAnnotations = allAnnotations.length;
const numberOfReviewedAnnotations = allAnnotations.filter((it) => (it.reviewers?.length ?? 0) > 0).length;
const correctnessData = {
labels: ['Correct', 'Unchecked'],
datasets: [
{
data: [numberOfReviewedAnnotations, numberOfAnnotations - numberOfReviewedAnnotations],
backgroundColor: [completeOrCorrectBg, uncheckedBg],
borderColor: [completeOrCorrectBorder, uncheckedBorder],
borderWidth: 1,
},
],
};
const correctnessOptions = {
plugins: {
title: {
display: true,
text: 'Review Progress',
color: textColor,
},
},
};
return (
<Box width="100%">
<SimpleGrid columns={{ base: 1, fullHD: 2 }} width="100%">
<Box>
<Pie data={completionData} options={completionOptions} />
</Box>
<Box>
<Pie data={correctnessData} options={correctnessOptions} />
</Box>
</SimpleGrid>
</Box>
);
};