Skip to content

Commit

Permalink
Fix bug in subcompartments
Browse files Browse the repository at this point in the history
Fix minor bug in subcompartments that returned an object as population, even when there were no subcompartments.
  • Loading branch information
Quantalabs committed Jan 5, 2022
1 parent 88cb0c2 commit f8e2399
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
8 changes: 3 additions & 5 deletions EpiJS/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ class Model {
}
key = newkey
if (x === time - 1) {
var return_val = {}
let return_val = {}
for (y in this.compartments) {
return_val[this.compartments[y][1]] = key[this.compartments[y][1]]
// Check for sub-compartmnets
if(this.compartments[y][0].compartments && Object.keys(this.compartments[y][0].compartments).length === 0 && Object.getPrototypeOf(this.compartments[y][0].compartments) === Object.prototype) {
if(Object.keys(this.compartments[y][0].compartments).length !== 0) {
return_val[this.compartments[y][1]] = {
"population": key[this.compartments[y][1]],
"compartments": {}
Expand All @@ -91,9 +92,6 @@ class Model {
return_val[this.compartments[y][1]]["compartments"][z] = this.compartments[y][0].getSubData(z, key)
}
}
else {
return_val[this.compartments[y][1]] = key[this.compartments[y][1]]
}
}
return return_val
}
Expand Down
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var x = {
x: {
x: {
x: 10
},
y: 10
},
y: {
x: {
x: 10
},
y: 0
}
}

for (var z in x) {
// Check if x[z].x is not an empty object
if (Object.keys(x[z].x).length !== 0) {
console.log('object: ', z)
}
}
2 changes: 2 additions & 0 deletions tests/scripts/comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ let susceptible2 = new Idiom("S-(B*S*I/p)");
let infected2 = new Idiom("I+(B*S*I/p)-(u*I)");
let recovered2 = new Idiom("R+(u*I)");

infected2.addSub('asymptomatic', 10)

let S = new Susceptible(["I*0.4/N"], [], true);
let I = new Infected([0.2], [['S', 'I*0.4/N']], true);
let R = new Recovered([], [['I', 0.4]], true);
Expand Down
2 changes: 1 addition & 1 deletion web/index.min.js

Large diffs are not rendered by default.

0 comments on commit f8e2399

Please sign in to comment.