This repository was archived by the owner on Mar 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
110 lines (92 loc) · 2.68 KB
/
app.js
File metadata and controls
110 lines (92 loc) · 2.68 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
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
var
express = require('express'),
fs = require('fs'),
csv = require('fast-csv'),
body_parser = require('body-parser');
// instantiate app
var app = express();
// static files middleware
app.use(express.static(__dirname + '/public'));
app.use('/jsPsych', express.static(__dirname + '/jsPsych'));
// body parsing middleware
app.use(body_parser.json({limit: '10mb'}));
// set template engine
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
// setup views
app.set('views', __dirname + '/public/views');
// ICF route
app.get('/', function(request, response) {
response.render('experiment.html', {
js_filename: 'instructions',
jspsych_plugins: ['instructions']
});
});
var experiment_plugins = [
'text',
'instructions',
'multi-stim-multi-response',
'single-stim',
'survey-multi-choice',
'survey-text',
];
// practice route
app.get('/practice', function(request, response) {
response.render('experiment.html', {
js_filename: 'practice',
jspsych_plugins: experiment_plugins
});
});
// experiment route
app.get('/experiment', function(request, response) {
response.render('experiment.html', {
js_filename: 'experiment',
jspsych_plugins: experiment_plugins
});
});
// post-test questions route
app.get('/follow_up', function(request, response) {
response.render('experiment.html', {
js_filename: 'follow_up',
jspsych_plugins: ['survey-multi-choice', 'text', 'survey-text']
});
});
// experiment finished route
app.get('/finish', function(request, response) {
response.render('finished.html');
});
// unit tests
app.get('/tests', function(request, response) {
response.render('tests.html');
});
// experiment data route
app.post('/experiment-data', function(request, response) {
var
headers = [
"internal_node_id", "trial_index", "trial_type", "time_elapsed",
"participant_id",
"num_trials", "trials_per_block", "practice_condition",
"stimulus", "key_press", "rt",
"correct", "response", "expected", "font_size",
"responses" // jspsych-survey-*
],
file_path = ["data", request.body.pathname, request.body.filename + ".csv"].join('/');
// devise data file path
file_path = [
__dirname,
"data",
request.body.pathname,
request.body.filename + ".csv"
].join('/');
// save data file
csv
.writeToPath(file_path, request.body.data, {headers: headers})
.on("finish", function(){
console.log("Finished writing to '" + file_path + "'");
});
response.end();
});
// start server
var server = app.listen(3001, function(){
console.log("Listening on port %d", server.address().port);
});