forked from expertiza/reimplementation-front-end
/
Statistics.tsx
213 lines (194 loc) · 7.09 KB
/
Statistics.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Statistics.tsx
import React,{useState, useEffect} from 'react';
import { calculateAverages } from './utils';
import './grades.scss';
import CircularProgress from './CircularProgress';
import ShowReviews from './ShowReviews'; //importing show reviews component
import dummyDataRounds from './Data/heatMapData.json'; // Importing dummy data for rounds
import dummyauthorfeedback from './Data/authorFeedback.json'; // Importing dummy data for author feedback
import BarGraph from './BarGraph';
import teammateData from './Data/teammateData.json';
import AverageMarks from './teamMarks';
//props for statistics component
interface StatisticsProps {
average:string;
}
//statistics component
const Statistics: React.FC<StatisticsProps> = ({average}) => {
const [sortedData, setSortedData] = useState<any[]>([]);
useEffect(() => {
const { averagePeerReviewScore, columnAverages, sortedData } = calculateAverages(dummyDataRounds[0], "asc");
const rowAvgArray = sortedData.map(item => item.RowAvg);
console.log(rowAvgArray);
setSortedData(sortedData.map(item => item.RowAvg));
}, []);
const [statisticsVisible, setstatisticsVisible] = useState<boolean>(false);
const toggleStatisticsVisibility = () => {
setstatisticsVisible(!statisticsVisible);
};
const [showReviews, setShowReviews] = useState(false);
const [ShowAuthorFeedback, setShowAuthorFeedback] = useState(false);
// Function to toggle the visibility of ShowReviews component
const toggleShowReviews = () => {
setShowReviews(!showReviews);
};
// Function to toggle the visibility of ShowAuthorFeedback component
const toggleAuthorFeedback = () => {
setShowAuthorFeedback(!ShowAuthorFeedback);
};
const headerCellStyle: React.CSSProperties = {
padding: '10px',
textAlign: 'center',
};
//calculation for total reviews recieved
let totalReviewsForQuestion1: number = 0;
dummyDataRounds.forEach(round => {
round.forEach(question => {
if (question.questionNumber === "1") {
totalReviewsForQuestion1 += question.reviews.length;
}
});
});
//calculation for total feedback recieved
let totalfeedbackForQuestion1: number = 0;
dummyauthorfeedback.forEach(round => {
round.forEach(question => {
if (question.questionNumber === "1") {
totalfeedbackForQuestion1 += question.reviews.length;
}
});
});
const subHeaderCellStyle: React.CSSProperties = {
padding: '10px',
textAlign: 'center',
};
return (
<div>
<table style={{ width: '90%', borderCollapse: 'collapse' }}>
<thead>
<a href="#" onClick={(e) => { e.preventDefault(); toggleStatisticsVisibility();}}>
{statisticsVisible ? 'hide stats' : 'show stats'}
</a>
{statisticsVisible && (
<tr>
<th style={headerCellStyle}>Stats</th>
<th style={headerCellStyle} colSpan={2}><BarGraph sortedData={sortedData} /></th>
<th style={headerCellStyle} colSpan={2}></th>
{teammateData.length !== 0 && (
<th style={headerCellStyle} colSpan={2}></th>
)}
<th style={headerCellStyle}><CircularProgress size={70} progress={75} strokeWidth={10} /></th>
</tr>
)}
<tr>
<th style={headerCellStyle}></th>
<th style={headerCellStyle} colSpan={2}>Submitted Work</th>
{dummyauthorfeedback[0].length !== 0 && (
<th style={headerCellStyle} colSpan={2}>Author Feedback</th>
)}
{teammateData.length !== 0 && (
<th style={headerCellStyle} colSpan={2}>Teammate Review</th>
)}
</tr>
<tr>
<th style={subHeaderCellStyle}>Contributor</th>
<th style={subHeaderCellStyle}>Average</th>
<th style={subHeaderCellStyle}>Range</th>
{dummyauthorfeedback[0].length !== 0 && (
<th style={subHeaderCellStyle}>Average</th>
)}
{dummyauthorfeedback[0].length !== 0 && (
<th style={subHeaderCellStyle}>Range</th>
)}
{teammateData.length !== 0 && (
<th style={subHeaderCellStyle}>Average</th>
)}
{teammateData.length !== 0 && (
<th style={subHeaderCellStyle}>Range</th>
)}
<th style={subHeaderCellStyle}>Final Score</th>
</tr>
<tr>
<td style={subHeaderCellStyle}>
<div style={{textAlign: 'center' }}>
<a href="#">ssshah26 </a><span>(Siddharth Shah)</span>
<br />
</div>
</td>
<td style={subHeaderCellStyle}>
<div style={{textAlign: 'center' }}>
<div>{average}</div>
<a href="#" onClick={(e) => { e.preventDefault(); toggleShowReviews(); }}>
{showReviews ? 'Hide Reviews' : 'Show Reviews'}
</a><span>({totalReviewsForQuestion1})</span>
</div>
</td>
<td style={subHeaderCellStyle}>
<div style={{textAlign: 'center' }}>
<div>99.99% - 100%</div>
</div>
</td>
<td style={subHeaderCellStyle}>
{dummyauthorfeedback[0].length !== 0 && (
<div style={{textAlign: 'center' }}>
<div>96.67</div>
<a href="#" onClick={(e) => { e.preventDefault(); toggleAuthorFeedback(); }}>
{ShowAuthorFeedback ? 'Hide Author Feedback' : 'Show Author Feedback'}
</a><span>({totalfeedbackForQuestion1})</span>
</div>
)}
<div>
</div>
</td>
<td style={subHeaderCellStyle}>
<div style={{textAlign: 'center' }}>
{dummyauthorfeedback[0].length !== 0 && (
<div>87% - 100%</div>
)}
</div>
</td>
<td style={subHeaderCellStyle}>
<div style={{textAlign: 'center' }}>
{teammateData.length !== 0 && (
<div><AverageMarks data={teammateData} /></div>
)}
</div>
</td>
<td style={subHeaderCellStyle}>
<div style={{textAlign: 'center' }}>
{teammateData.length !== 0 && (
<div>90% - 100%</div>
)}
</div>
</td>
<td style={subHeaderCellStyle}>
{teammateData.length !== 0 && (
<div style={{textAlign: 'center' }}>
<div>75%</div>
<div>(in Finished)</div>
</div>
)}
</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div>
{showReviews && (
<div>
<h2>Reviews</h2>
<ShowReviews data={dummyDataRounds} />
</div>
)}
{ShowAuthorFeedback && (
<div>
<h2>Author Feedback</h2>
<ShowReviews data={dummyauthorfeedback} />
</div>
)}
</div>
</div>
);
};
export default Statistics;