Skip to content

Commit

Permalink
Add or remove compartments from models (#102)
Browse files Browse the repository at this point in the history
* Add `.add` and `.remove`  to `Model` class in `model` module

Adds `.add` and `.remove` functions to the Model class in the model module, which add and remove compartments.

CHANGELIST:
  * Add `.add` and `.remove` functions to model class
  * Version bump
  * Update changelog

Signed-off-by: @Quantalabs <npm.quantalabs@gmail.com>

* Update docs

* Build code for web support

Rebuild web code with browserify and terser

* Add testing

* Bug Fix
  • Loading branch information
Quantalabs authored Sep 6, 2021
1 parent 73ab7f5 commit 8bddc04
Show file tree
Hide file tree
Showing 39 changed files with 270 additions and 86 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# v2.2.0

- Add `.remove` and `.add` functions to `Model` class in `model` module to add and remove compartments.

# v2.1.2

- Fix error from previous release

# v2.1.1

- Fix key error in `model`

# v2.1.0
- Adds `manipulate` to manipulate outputs with `plots`
- Adds `mexport` and `mimport` to `model`, which allow for exporting and importing models to `.js` and `.json` files.
Expand Down
58 changes: 58 additions & 0 deletions EpiJS/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,64 @@ class Model {
}
}
}

/**
* Remove a compartment from the model.
* @param {Object} compartment - The compartment to remove.
* @example
*
* let susceptible = new Idiom("S-(B*S*I/p)");
* let infected = new Idiom("I+(B*S*I/p)-(u*I)");
* let recovered = new Idiom("R+(u*I)");
*
* let key = {
* "S": 10000,
* "B": 0.3,
* "I": 100,
* "R": 0,
* "p": 10100,
* "u": 0.2
* };
*
* let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)
*
* sirm.remove(recovered) // Removes the recovered compartment.
*/
remove(compartment) {
for (var x = 0; x < this.compartments.length; x++) {
if (this.compartments[x][0] === compartment) {
this.compartments.splice(x, 1)
}
}
}

/**
* Add a compartment to the model.
* @param {Array} compartment - The compartment to add, should be a list, with the first value being the compartment, and the second being it's value in the key.
* @param {Number} index - The index to add the compartment at.
* @example
*
* let susceptible = new Idiom("S-(B*S*I/p)");
* let infected = new Idiom("I+(B*S*I/p)-(u*I)");
* let recovered = new Idiom("R+(u*I)");
*
* let key = {
* "S": 10000,
* "B": 0.3,
* "I": 100,
* "R": 0,
* "p": 10100,
* "u": 0.2
* };
*
* let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)
*
* sirm.remove(susceptible) // Removes the susceptible compartment.
* sirm.add([susceptible, "S"], 0) // Adds the susceptible compartment back to the beginning
*/
add(compartment, index) {
this.compartments.splice(index, 0, compartment)
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions docs/.vuepress/dist/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<link rel="shortcut icon" href="https://i.ibb.co/HKt7Bn3/Logo-Makr-4sk-LGO.png">
<meta name="description" content="A disease modeling package for JS.">

<link rel="preload" href="/latest/assets/css/0.styles.b9717b67.css" as="style"><link rel="preload" href="/latest/assets/js/app.aff1c8ab.js" as="script"><link rel="preload" href="/latest/assets/js/6.852d803a.js" as="script"><link rel="prefetch" href="/latest/assets/js/10.a77dd4da.js"><link rel="prefetch" href="/latest/assets/js/11.611be703.js"><link rel="prefetch" href="/latest/assets/js/12.4e73897a.js"><link rel="prefetch" href="/latest/assets/js/13.656464db.js"><link rel="prefetch" href="/latest/assets/js/14.1ebbcd48.js"><link rel="prefetch" href="/latest/assets/js/15.5ca88985.js"><link rel="prefetch" href="/latest/assets/js/16.5683af4a.js"><link rel="prefetch" href="/latest/assets/js/17.33651cd7.js"><link rel="prefetch" href="/latest/assets/js/2.9dda8840.js"><link rel="prefetch" href="/latest/assets/js/3.7383f13d.js"><link rel="prefetch" href="/latest/assets/js/4.e52e661e.js"><link rel="prefetch" href="/latest/assets/js/5.0ae7634d.js"><link rel="prefetch" href="/latest/assets/js/7.43ae9a22.js"><link rel="prefetch" href="/latest/assets/js/8.4f988444.js"><link rel="prefetch" href="/latest/assets/js/9.94dfc0ef.js">
<link rel="preload" href="/latest/assets/css/0.styles.b9717b67.css" as="style"><link rel="preload" href="/latest/assets/js/app.91f8e8e3.js" as="script"><link rel="preload" href="/latest/assets/js/6.66b67ff0.js" as="script"><link rel="prefetch" href="/latest/assets/js/10.932528a4.js"><link rel="prefetch" href="/latest/assets/js/11.872dc73d.js"><link rel="prefetch" href="/latest/assets/js/12.87248bdf.js"><link rel="prefetch" href="/latest/assets/js/13.69389283.js"><link rel="prefetch" href="/latest/assets/js/14.2151a125.js"><link rel="prefetch" href="/latest/assets/js/15.1b080847.js"><link rel="prefetch" href="/latest/assets/js/16.a484d9e5.js"><link rel="prefetch" href="/latest/assets/js/17.113e2690.js"><link rel="prefetch" href="/latest/assets/js/2.b0282dab.js"><link rel="prefetch" href="/latest/assets/js/3.6af3db70.js"><link rel="prefetch" href="/latest/assets/js/4.2a5d96fc.js"><link rel="prefetch" href="/latest/assets/js/5.33ec2a2e.js"><link rel="prefetch" href="/latest/assets/js/7.bbf703d4.js"><link rel="prefetch" href="/latest/assets/js/8.22d960c1.js"><link rel="prefetch" href="/latest/assets/js/9.570eb5e8.js">
<link rel="stylesheet" href="/latest/assets/css/0.styles.b9717b67.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><div class="theme-default-content"><h1>404</h1> <blockquote>How did we get here?</blockquote> <a href="/latest/" class="router-link-active">
<div id="app" data-server-rendered="true"><div class="theme-container"><div class="theme-default-content"><h1>404</h1> <blockquote>There's nothing here.</blockquote> <a href="/latest/" class="router-link-active">
Take me home.
</a></div></div><div class="global-ui"></div></div>
<script src="/latest/assets/js/app.aff1c8ab.js" defer></script><script src="/latest/assets/js/6.852d803a.js" defer></script>
<script src="/latest/assets/js/app.91f8e8e3.js" defer></script><script src="/latest/assets/js/6.66b67ff0.js" defer></script>
</body>
</html>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8bddc04

Please sign in to comment.