-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptAll3.js
259 lines (233 loc) · 8.08 KB
/
scriptAll3.js
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
document.getElementById('upload-csv1').addEventListener('change', function (event) {
handleFileUpload(event, 0);
});
document.getElementById('upload-csv2').addEventListener('change', function (event) {
handleFileUpload(event, 1);
});
const filesData = [null, null];
function handleFileUpload(event, index) {
const file = event.target.files[0];
if (file) {
Papa.parse(file, {
header: true,
dynamicTyping: true,
complete: function (results) {
filesData[index] = results.data;
if (filesData[0] && filesData[1]) {
conversionOfData();
plotAllGraphs();
}
},
error: function (error) {
console.error('Error parsing the CSV file:', error);
}
});
}
}
let FILE1MMCONVERSION, FILE2MMCONVERSION;
function conversionOfData() {
// Calculate the conversion ratio for pixels to mm
const file1rulerDeltaX = [];
const file1rulerDeltaY = [];
const file2rulerDeltaX = [];
const file2rulerDeltaY = [];
filesData[0].forEach(row => {
file1rulerDeltaX.push(row['ruler 0 mm x'] - row['ruler 20 mm x']);
file1rulerDeltaY.push(row['ruler 0 mm y'] - row['ruler 20 mm y']);
});
filesData[1].forEach(row => {
file2rulerDeltaX.push(row['ruler 0 mm x'] - row['ruler 20 mm x']);
file2rulerDeltaY.push(row['ruler 0 mm y'] - row['ruler 20 mm y']);
});
// the GPT fix that doesn't work
// const avgFile1DeltaX = file1rulerDeltaX.reduce((acc, curr) => acc + curr, 0) / file1rulerDeltaX.length;
// const avgFile1DeltaY = file1rulerDeltaY.reduce((acc, curr) => acc + curr, 0) / file1rulerDeltaY.length;
// const avgFile2DeltaX = file2rulerDeltaX.reduce((acc, curr) => acc + curr, 0) / file2rulerDeltaX.length;
// const avgFile2DeltaY = file2rulerDeltaY.reduce((acc, curr) => acc + curr, 0) / file2rulerDeltaY.length;
// const file1Pixels20 = Math.sqrt(avgFile1DeltaX * avgFile1DeltaX + avgFile1DeltaY * avgFile1DeltaY);
// const file2Pixels20 = Math.sqrt(avgFile2DeltaX * avgFile2DeltaX + avgFile2DeltaY * avgFile2DeltaY);
// hard coded using an estimate calculated by hand
FILE1MMCONVERSION = 20 / 30;
FILE2MMCONVERSION = 20 / 30;
}
function plotAllGraphs() {
clearPreviousGraphs();
plotTimeVsApexX();
plotTimeVsApexY();
plotApexXvsApexY();
plotTimeVsDisplacement();
}
function clearPreviousGraphs() {
const chartArea = document.getElementById('chartArea');
chartArea.innerHTML = '';
}
function createChartContainer(title, canvasId) {
const chartArea = document.getElementById('chartArea');
const container = document.createElement('div');
container.className = 'chart-container';
const titleElement = document.createElement('h3');
titleElement.textContent = title;
const canvas = document.createElement('canvas');
canvas.id = canvasId;
container.appendChild(titleElement);
container.appendChild(canvas);
chartArea.appendChild(container);
}
function plotTimeVsApexX() {
createChartContainer('Time vs Apex X', 'timeVsApexX');
const FPH = 100;
const framesToHoursX = [];
const apexXValues1 = [];
const apexXValues2 = [];
filesData[0].forEach((row, index) => {
framesToHoursX.push(index / FPH);
apexXValues1.push(row['apex x'] * FILE1MMCONVERSION);
});
filesData[1].forEach((row, index) => {
apexXValues2.push(row['apex x'] * FILE2MMCONVERSION);
});
const ctx = document.getElementById('timeVsApexX').getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: framesToHoursX,
datasets: [
{
label: 'Apex X (Dataset 1, mm)',
data: apexXValues1,
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderWidth: 1
},
{
label: 'Apex X (Dataset 2, mm)',
data: apexXValues2,
borderColor: 'rgba(255, 99, 132, 1)',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderWidth: 1
}
]
},
options: {
scales: {
x: {
title: {
display: true,
text: 'Time (hours)'
}
},
y: {
title: {
display: true,
text: 'Apex X (mm)'
}
}
}
}
});
}
function plotTimeVsApexY() {
createChartContainer('Time vs Apex Y', 'timeVsApexY');
const FPH = 100;
const framesToHoursY = [];
const apexYValues1 = [];
const apexYValues2 = [];
filesData[0].forEach((row, index) => {
framesToHoursY.push(index / FPH);
apexYValues1.push(row['apex y'] * FILE1MMCONVERSION); // Convert to mm
});
filesData[1].forEach((row, index) => {
apexYValues2.push(row['apex y'] * FILE2MMCONVERSION); // Convert to mm
});
const ctx = document.getElementById('timeVsApexY').getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: framesToHoursY,
datasets: [
{
label: 'Apex Y (Dataset 1, mm)',
data: apexYValues1,
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderWidth: 1
},
{
label: 'Apex Y (Dataset 2, mm)',
data: apexYValues2,
borderColor: 'rgba(255, 99, 132, 1)',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderWidth: 1
}
]
},
options: {
scales: {
x: {
title: {
display: true,
text: 'Time (hours)'
}
},
y: {
title: {
display: true,
text: 'Apex Y (mm)'
}
}
}
}
});
}
function plotApexXvsApexY() {
createChartContainer('Apex X vs Apex Y', 'apexXvsApexY');
const apexXValues1 = [];
const apexYValues1 = [];
const apexXValues2 = [];
const apexYValues2 = [];
filesData[0].forEach(row => {
apexXValues1.push(row['apex x'] * FILE1MMCONVERSION);
apexYValues1.push(row['apex y'] * FILE1MMCONVERSION);
});
filesData[1].forEach(row => {
apexXValues2.push(row['apex x'] * FILE2MMCONVERSION);
apexYValues2.push(row['apex y'] * FILE2MMCONVERSION);
});
const ctx = document.getElementById('apexXvsApexY').getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: apexXValues1,
datasets: [
{
label: 'Apex X vs Apex Y (Dataset 1)',
data: apexYValues1,
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderWidth: 1,
pointRadius: 0, // Hide points
fill: false
},
{
label: 'Apex X vs Apex Y (Dataset 2)',
data: apexYValues2,
borderColor: 'rgba(255, 99, 132, 1)',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderWidth: 1,
pointRadius: 0, // Hide points
fill: false
}
]
},
options: {
scales: {
x: {
title: {
display: true,
text: 'Displacement (mm)'
}
}
}
}
});
}