-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_block_csv.js
More file actions
38 lines (35 loc) · 1.33 KB
/
Copy pathmake_block_csv.js
File metadata and controls
38 lines (35 loc) · 1.33 KB
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
const fs = require('fs');
const csv = require('csv-parser');
const make_block_csv = function (participant_id, participant_dir, block_num, stimuli) {
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
let data =stimuli.map((stim,i) => {
let dat = {
subject_id: stim.subject_id,
question: stim.Q_num,
block_num: block_num,
set: stim.set,
mode: stim.mode,
mode_pitches:stim.mode_pitches,
probe_pitches:stim.probe_pitches,
transposition:stim.transposition,
probe: stim.probe,
test:stim.test,
type:stim.type,
probe_file:stim.probe_file,
test_file:stim.test_file,
practice:stim.practice
}
return dat
})
fs.writeFile(participant_dir + "csv/" + "block_" + block_num + ".json", JSON.stringify(data), function(err) {
if(err) {
return console.log(err);
}
});
const csvWriter = createCsvWriter({
path: participant_dir + "csv/" + "block_" + block_num + ".csv",
header: Object.keys(data[0]).map(el=>{return {id:el,title:el}})
}).writeRecords(data)
.then(()=> console.log("CSV file subject",participant_id,"block", block_num,"was successfully created."));
}
module.exports = make_block_csv