Skip to content

Commit 815c7bc

Browse files
committed
Optimize data handling: Implement rounding and gzip compression for CSV output
- Implement rounding to four decimal places for specific numerical columns. - gzip compression for CSV outputs to reduce file size and improve bandwidth usage during data transfers.
1 parent cae60b1 commit 815c7bc

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

.github/workflows/website.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ jobs:
4646
with:
4747
name: 'Data'
4848

49+
- name: 'Filter and compress results file.'
50+
run: python tests/IVIMmodels/unit_tests/reduce_output_size.py
51+
4952
- name: move data to the dashboard folder
5053
run: |
51-
mv test_output.csv website/dashboard
54+
mv test_output.csv.gz website/dashboard
5255
5356
- name: Build documentation
5457
run: |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pandas as pd
2+
3+
df = pd.read_csv('test_output.csv')
4+
5+
# Columns to be rounded to four decimal places
6+
columns_to_round = [
7+
'f', 'Dp', 'D', 'f_fitted', 'Dp_fitted', 'D_fitted',
8+
'bval_0.0', 'bval_1.0', 'bval_2.0', 'bval_5.0', 'bval_10.0', 'bval_20.0',
9+
'bval_30.0', 'bval_50.0', 'bval_75.0', 'bval_100.0', 'bval_150.0', 'bval_250.0',
10+
'bval_350.0', 'bval_400.0', 'bval_550.0', 'bval_700.0', 'bval_850.0', 'bval_1000.0'
11+
]
12+
for column in columns_to_round:
13+
df[column] = df[column].round(4)
14+
15+
#df = df.loc[:, ~df.columns.str.startswith('bval')]
16+
17+
#compress and save the file.
18+
df.to_csv('test_output.csv.gz', compression='gzip', index=False)

website/dashboard/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js"></script>
99
<script src="https://cdn.plot.ly/plotly-2.30.0.min.js"></script>
1010
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
11+
<script src="https://cdn.jsdelivr.net/npm/pako@1.0.11/dist/pako.min.js"></script>
1112
<script src="index.js"></script>
1213
<link rel="stylesheet" href="index.css">
1314
</head>

website/dashboard/index.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,31 @@ document.addEventListener('DOMContentLoaded', function() {
205205

206206
showLoading();
207207

208-
Papa.parse('test_output.csv', {
209-
download: true,
210-
header: true,
211-
complete: results => {
212-
data = results;
213-
hideLoading();
214-
populateOptions(data);
215-
drawBoxPlot();
216-
drawRegionBoxPlot();
217-
208+
fetch('test_output.csv.gz')
209+
.then(response => {
210+
if (!response.ok) {
211+
throw new Error('Network response was not ok');
218212
}
213+
return response.arrayBuffer();
214+
})
215+
.then(buffer => {
216+
// Use pako to decompress the data
217+
var decompressed = pako.inflate(new Uint8Array(buffer), { to: 'string' });
218+
// Now use Papa Parse to parse the decompressed CSV data
219+
Papa.parse(decompressed, {
220+
header: true,
221+
complete: results => {
222+
console.log(results);
223+
data = results;
224+
hideLoading();
225+
populateOptions(data);
226+
drawBoxPlot();
227+
drawRegionBoxPlot();
228+
}
229+
});
230+
})
231+
.catch(error => {
232+
console.error('There has been a problem with your fetch operation:', error);
219233
});
220234

221235
function populateOptions(data) {

0 commit comments

Comments
 (0)