Commit c78c84b4 authored by Rudolf Copi Eckelberg's avatar Rudolf Copi Eckelberg

Changes to new formats in simulations

parent 52d776a5
Pipeline #7739 failed with stage
in 2 minutes and 24 seconds
......@@ -15,11 +15,11 @@ let SimulationSchema = new Schema({
required: true,
},
location: Object,
time: Number,
timeCut: Number,
failure_rate: Array,
goals_care: Array,
goals_inclusion: Array,
enrollments: Array,
enrollments: Object,
timestamp: Date,
});
......@@ -29,7 +29,7 @@ SimulationSchema.methods.setTime = function (t) {
// Throw an error?
return false;
}
this.time = t;
this.timeCut = t;
return true;
};
SimulationSchema.methods.setLocation = function (l) {
......@@ -53,26 +53,8 @@ SimulationSchema.methods.setInclusionGoals = function (g) {
return true;
};
SimulationSchema.methods.setEnrollments = function (e) {
try{
e = JSON.parse(e);
} catch (err) {
return false;
}
// TODO input sanitization
let success = true;
for(let i=0; i<e.length; i++){
if(!(e[i] instanceof Array)){
return false;
}
if(e[i].length !== this.time){
return false;
}
e[i].forEach((n, i, array) => {
if(n !== parseInt(n, 10)){
success = false;
}
});
}
if (success) this.enrollments = e;
return success;
......@@ -80,7 +62,7 @@ SimulationSchema.methods.setEnrollments = function (e) {
SimulationSchema.methods.update = function (property, value) {
let success = true;
switch(property){
case 'time':
case 'timeCut':
if (!this.setTime(value)) success = false;
break;
case 'location':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment