This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.js
121 lines (108 loc) · 3.03 KB
/
database.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
const mongoose = require("mongoose");
const DATABASE =
process.env.DATABASE ||
"mongodb+srv://admin_renis:" +
"renishis" +
"@cluster0-ervkr.mongodb.net/RSPV_Data?retryWrites=true&w=majority";
mongoose.connect(DATABASE, {
useNewUrlParser: true,
useUnifiedTopology: true,
}); // Online conection with my Mongo database online
const answerSchema = new mongoose.Schema({
uid: String,
date: Date,
passage: Number,
position: Number,
answer: String,
readingDuration: Number,
interactions: {
slower: Number,
faster: Number,
pause: Number,
forward: Number,
rewind: Number,
},
});
const demographicSchema = new mongoose.Schema({
uid: String,
date: Date,
ageRange: String,
englishLevel: String,
vision: String,
source: String,
rsvpExperience: String,
device: String,
light: String,
});
const textOrderSchema = new mongoose.Schema({
uid: String,
textOrder: [Number],
});
const Answer = new mongoose.model("Answer", answerSchema);
const Demographic = new mongoose.model("Demographic", demographicSchema);
const TextOrder = new mongoose.model("TextOrder", textOrderSchema);
/** save an answer to the text snippet comprehension question, including interaction statistics
*
* @param {object} answer
* @param {string} answer.uid
* @param {Date} answer.date
* @param {number} answer.passage
* @param {number} answer.position
* @param {string} answer.answer (yes or no)
* @param {number} answer.readingDuration (in seconds)
* @param {object} answer.interactions
* @param {number} answer.interactions.slower
* @param {number} answer.interactions.faster
* @param {number} answer.interactions.pause
* @param {number} answer.interactions.forward
* @param {number} answer.interactions.rewind
*/
async function saveAnswer(answer) {
await new Answer(answer).save();
}
async function getAllAnswers() {
const answers = await Answer.find({});
return answers.map((model) => model.toObject());
}
/**
* save demographic background data
*
* @param {object} demographic
* @param {string} demographic.uid;
* @param {Date} demographic.date;
* @param {string} demographic.ageRange;
* @param {string} demographic.englishLevel;
* @param {string} demographic.vision;
* @param {string} demographic.source;
* @param {string} demographic.rsvpExperience;
* @param {string} demographic.device;
* @param {string} demographic.light;
*/
async function saveDemographic(demographic) {
await new Demographic(demographic).save();
}
async function getAllDemographics() {
const answers = await Demographic.find({});
return answers.map((model) => model.toObject());
}
/**
* save the text order
* @param {object} args
* @param {string} args.uid
* @param {number[]} args.textOrder
*/
async function saveTextOrder(args) {
await new TextOrder(args).save();
}
async function getAllTextOrders() {
const orders = await TextOrder.find({});
return orders.map((model) => model.toObject());
}
module.exports = {
saveAnswer,
getAllAnswers,
saveDemographic,
getAllDemographics,
saveTextOrder,
getAllTextOrders,
};