Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable target update #1461

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/job-view/job-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ module.exports = View.extend({
},
render: function (attrs, options) {
View.prototype.render.apply(this, arguments);
if(this.model.status !== "error") {
if(this.model.status === "complete") {
this.renderResultsView();
}
if(!this.readOnly) {
if(!this.readOnly && this.model.status !== "running") {
this.renderLogsView();
}
this.renderSettingsView();
Expand Down
17 changes: 7 additions & 10 deletions client/model-view/model-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,9 @@ module.exports = View.extend({
});
this.model.eventsCollection.on("add change remove", () => {
this.updateSpeciesInUse();
this.updateParametersInUse();
});
this.model.rules.on("add change remove", () => {
this.updateSpeciesInUse();
this.updateParametersInUse();
});
}
},
Expand Down Expand Up @@ -429,14 +427,6 @@ module.exports = View.extend({
updateInUse(reaction.rate);
}
});
events.forEach((event) => {
event.eventAssignments.forEach((assignment) => {
updateInUse(assignment.variable);
});
});
rules.forEach((rule) => {
updateInUse(rule.variable);
});
},
updateSpeciesInUse: function () {
let species = this.model.species;
Expand All @@ -450,6 +440,10 @@ module.exports = View.extend({
specie.inUse = true;
});
}
let updateInUseForRate = (rate) => {
specie = species.get(rate.compID, 'compID')
if(specie) { specie.inUse = true; }
}
let updateInUseForOther = (specie) => {
_.where(species.models, { compID: specie.compID })
.forEach((specie) => {
Expand All @@ -459,6 +453,9 @@ module.exports = View.extend({
reactions.forEach((reaction) => {
reaction.products.forEach(updateInUseForReaction);
reaction.reactants.forEach(updateInUseForReaction);
if(reaction.reactionType !== 'custom-propensity') {
updateInUseForRate(reaction.rate);
}
});
events.forEach((event) => {
event.eventAssignments.forEach((assignment) => {
Expand Down
8 changes: 7 additions & 1 deletion client/model-view/templates/editSpecie.pug
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ div.mx-1

div.pl-2(data-hook="input-name-container")

div.col-sm-5
div.col-sm-3

div(data-hook="input-value-container")

div.col-sm-2

div.pl-3

input(type="checkbox" data-hook="observable")

div.col-sm-2

div.tooltip-icon-large(data-hook="annotation-tooltip" data-html="true" data-toggle="tooltip" title=this.model.annotation || "Click 'Add' to add an annotation") <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="file-alt" class="svg-inline--fa fa-file-alt fa-w-12" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M224 136V0H24C10.7 0 0 10.7 0 24v464c0 13.3 10.7 24 24 24h336c13.3 0 24-10.7 24-24V160H248c-13.2 0-24-10.8-24-24zm64 236c0 6.6-5.4 12-12 12H108c-6.6 0-12-5.4-12-12v-8c0-6.6 5.4-12 12-12h168c6.6 0 12 5.4 12 12v8zm0-64c0 6.6-5.4 12-12 12H108c-6.6 0-12-5.4-12-12v-8c0-6.6 5.4-12 12-12h168c6.6 0 12 5.4 12 12v8zm0-72v8c0 6.6-5.4 12-12 12H108c-6.6 0-12-5.4-12-12v-8c0-6.6 5.4-12 12-12h168c6.6 0 12 5.4 12 12zm96-114.1v6.1H256V0h6.1c6.4 0 12.5 2.5 17 7l97.9 98c4.5 4.5 7 10.6 7 16.9z"></path></svg>
Expand Down
2 changes: 1 addition & 1 deletion client/model-view/templates/rulesView.pug
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ div#rules-editor.card

div.card-body
p.mb-0
| Equations that determine the value (assignment rule) or rates of change (rate rule) of <i>Variables</i> or <i>Parameter</i>.
| Equations that determine the value (assignment rule) or rates of change (rate rule) of <i>Variables</i>.
ul.mb-0
li A <b>'Rate Rule'</b> corresponds to a function in the form of <span data-hook="rr-doc-func"></span>
li An <b>'Assignment Rule'</b> correspond to a function in the form of <span data-hook="ar-doc-func"></span>
Expand Down
14 changes: 12 additions & 2 deletions client/model-view/templates/speciesView.pug
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ div#species-editor.card

div.tooltip-icon(data-html="true" data-toggle="tooltip" title=this.tooltips.name) <sup><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info" class="svg-inline--fa fa-info fa-w-6" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 512"><path fill="currentColor" d="M20 424.229h20V279.771H20c-11.046 0-20-8.954-20-20V212c0-11.046 8.954-20 20-20h112c11.046 0 20 8.954 20 20v212.229h20c11.046 0 20 8.954 20 20V492c0 11.046-8.954 20-20 20H20c-11.046 0-20-8.954-20-20v-47.771c0-11.046 8.954-20 20-20zM96 0C56.235 0 24 32.235 24 72s32.235 72 72 72 72-32.235 72-72S135.764 0 96 0z"></path></svg></sup>

div.col-sm-5
div.col-sm-3

h6.inline <b>Initial Condition</b>

div.tooltip-icon(data-html="true" data-toggle="tooltip" title=this.tooltips.initialValue) <sup><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info" class="svg-inline--fa fa-info fa-w-6" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 512"><path fill="currentColor" d="M20 424.229h20V279.771H20c-11.046 0-20-8.954-20-20V212c0-11.046 8.954-20 20-20h112c11.046 0 20 8.954 20 20v212.229h20c11.046 0 20 8.954 20 20V492c0 11.046-8.954 20-20 20H20c-11.046 0-20-8.954-20-20v-47.771c0-11.046 8.954-20 20-20zM96 0C56.235 0 24 32.235 24 72s32.235 72 72 72 72-32.235 72-72S135.764 0 96 0z"></path></svg></sup>

div.col-sm-2

h6.inline <b>Observable</b>

div.tooltip-icon(data-html="true" data-toggle="tooltip" title=this.tooltips.observable) <sup><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info" class="svg-inline--fa fa-info fa-w-6" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 512"><path fill="currentColor" d="M20 424.229h20V279.771H20c-11.046 0-20-8.954-20-20V212c0-11.046 8.954-20 20-20h112c11.046 0 20 8.954 20 20v212.229h20c11.046 0 20 8.954 20 20V492c0 11.046-8.954 20-20 20H20c-11.046 0-20-8.954-20-20v-47.771c0-11.046 8.954-20 20-20zM96 0C56.235 0 24 32.235 24 72s32.235 72 72 72 72-32.235 72-72S135.764 0 96 0z"></path></svg></sup>

div.col-sm-2

h6.inline <b>Annotation</b>
Expand Down Expand Up @@ -80,10 +86,14 @@ div#species-editor.card

h6.inline <b>Mode</b>

div.col-sm-4(data-hook="species-switching-header")
div.col-sm-2(data-hook="species-switching-header")

h6.inline <b>Switch Tolerance/Minimum Value for Switching</b>

div.col-sm-2

h6.inline <b>Observable</b>

div.col-sm-2(data-hook="species-annotation-header")

h6.inline <b>Annotation</b>
Expand Down
8 changes: 7 additions & 1 deletion client/model-view/templates/viewSpecie.pug
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ div.mx-1
div=this.model.mode

if this.model.mode === "dynamic"
div.col-sm-4
div.col-sm-2
div=this.switchingValWithLabel

div.col-sm-2

div.pl-3

input(type="checkbox" data-hook="observable" checked=this.model.observable)

div.col-sm-2

if this.model.annotation
Expand Down
28 changes: 4 additions & 24 deletions client/model-view/views/event-assignment-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,9 @@ module.exports = View.extend({
},
getOptions: function () {
var species = this.model.collection.parent.collection.parent.species;
var parameters = this.model.collection.parent.collection.parent.parameters;
var specs = species.map(function (specie) {
var options = species.map(function (specie) {
return [specie.compID, specie.name];
});
var params = parameters.map(function (parameter) {
return [parameter.compID, parameter.name];
});
let options = [{groupName: Boolean(specs) ? "Variables" : "Variables (empty)", options: specs},
{groupName: Boolean(params) ? "Parameters" : "Parameters (empty)", options: params}];
return options;
},
removeAssignment: function () {
Expand All @@ -60,22 +54,8 @@ module.exports = View.extend({
this.collection.parent.collection.trigger('change');
},
selectAssignmentVariable: function (e) {
var species = this.model.collection.parent.collection.parent.species;
var parameters = this.model.collection.parent.collection.parent.parameters;
var val = Number(e.target.value);
var eventVar = species.filter(function (specie) {
if(specie.compID === val) {
return specie;
}
});
if(!eventVar.length) {
eventVar = parameters.filter(function (parameter) {
if(parameter.compID === val) {
return parameter;
}
});
}
this.model.variable = eventVar[0];
let species = this.model.collection.parent.collection.parent.species;
this.model.variable = species.get(Number(e.target.value), 'compID');
this.updateViewer();
this.model.collection.parent.collection.trigger('change');
},
Expand Down Expand Up @@ -107,7 +87,7 @@ module.exports = View.extend({
name: 'variable',
required: true,
idAttributes: 'cid',
groupOptions: options,
options: options,
value: this.model.variable.compID
});
}
Expand Down
18 changes: 0 additions & 18 deletions client/model-view/views/parameters-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,6 @@ module.exports = View.extend({
}
}
});
this.collection.parent.eventsCollection.map((event) => {
event.eventAssignments.map((assignment) => {
if(assignment.variable.compID === compID) {
assignment.variable = parameter;
}
})
if(event.selected) {
event.trigger('change-event');
}
});
this.collection.parent.rules.map((rule) => {
if(rule.variable.compID === compID) {
rule.variable = parameter;
}
});
if(this.parent.rulesView) {
this.parent.rulesView.renderEditRules();
}
});
},
render: function () {
Expand Down
33 changes: 27 additions & 6 deletions client/model-view/views/reaction-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ module.exports = View.extend({
self.parent.renderEditReactionView();
});
},
getOptions: function () {
var species = this.model.collection.parent.species;
var parameters = this.model.collection.parent.parameters;
var specs = species.map(function (specie) {
return [specie.compID, specie.name];
});
var params = parameters.map(function (parameter) {
return [parameter.compID, parameter.name];
});
let options = [{groupName: Boolean(specs) ? "Variables" : "Variables (empty)", options: specs},
{groupName: Boolean(params) ? "Parameters" : "Parameters (empty)", options: params}];
return options;
},
getReactionTypes: function () {
let disableTypes = this.model.collection.parent.parameters.length == 0;
let options = _.map(ReactionTypes, function (val, key) {
Expand Down Expand Up @@ -289,14 +302,18 @@ module.exports = View.extend({
viewOptions['options'] = [];
viewOptions['unselectedText'] = "N/A";
}else{
// make sure the reaction has a rate and that rate exists in the parameters collection
// make sure the reaction has a rate and that rate exists in the species or parameters collection
let paramIDs = this.model.collection.parent.parameters.map(function (param) {
return param.compID;
});
if(!this.model.rate.compID || !paramIDs.includes(this.model.rate.compID)) {
let specIDs = this.model.collection.parent.species.map(function (spec) {
return spec.compID;
});
let rateExists = paramIDs.includes(this.model.rate.compID) || specIDs.includes(this.model.rate.compID);
if(!this.model.rate.compID || !rateExists) {
this.model.rate = this.model.collection.getDefaultRate();
}
viewOptions['options'] = this.model.collection.parent.parameters;
viewOptions['groupOptions'] = this.getOptions();
viewOptions['value'] = this.model.rate.compID;
}

Expand Down Expand Up @@ -368,9 +385,13 @@ module.exports = View.extend({
},
selectRateParam: function (e) {
let val = e.target.selectedOptions.item(0).value;
let param = this.model.collection.parent.parameters.get(val, 'compID');
if(param) {
this.model.rate = param;
console.log(val)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to drop the console log?

var rate = this.model.collection.parent.parameters.get(val, 'compID');
if(rate === undefined) {
rate = this.model.collection.parent.species.get(val, 'compID');
}
if(rate) {
this.model.rate = rate;
this.updateViewer();
this.model.trigger('change-reaction');
this.model.collection.trigger("change");
Expand Down
25 changes: 3 additions & 22 deletions client/model-view/views/rule-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,9 @@ module.exports = View.extend({
getOptions: function () {
let species = this.model.collection.parent.species;
let parameters = this.model.collection.parent.parameters;
let specs = species.map(function (specie) {
let options = species.map(function (specie) {
return [specie.compID, specie.name];
});
let params = parameters.map(function (parameter) {
return [parameter.compID, parameter.name];
});
let options = [{groupName: Boolean(specs) ? "Variables" : "Variables (empty)", options: specs},
{groupName: Boolean(params) ? "Parameters" : "Parameters (empty)", options: params}];
return options;
},
removeRule: function () {
Expand All @@ -95,21 +90,7 @@ module.exports = View.extend({
},
selectRuleVariable: function (e) {
let species = this.model.collection.parent.species;
let parameters = this.model.collection.parent.parameters;
let compID = Number(e.target.value);
let ruleVar = species.filter(function (specie) {
if(specie.compID === compID) {
return specie;
}
});
if(!ruleVar.length) {
ruleVar = parameters.filter(function (parameter) {
if(parameter.compID === compID) {
return parameter;
}
});
}
this.model.variable = ruleVar[0];
this.model.variable = species.get(Number(e.target.value), 'compID')
},
update: function (e) {},
updateValid: function () {},
Expand Down Expand Up @@ -152,7 +133,7 @@ module.exports = View.extend({
name: 'variable',
required: true,
idAttributes: 'cid',
groupOptions: options,
options: options,
value: this.model.variable.compID
});
}
Expand Down
10 changes: 10 additions & 0 deletions client/model-view/views/specie-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,19 @@ module.exports = View.extend({
type: 'booleanAttribute',
name: 'disabled',
},
'model.observable': {
type: function (el, value, previousValue) {
el.checked = value;
},
hook: 'observable'
}
},
events: {
'change [data-hook=input-name-container]' : 'setSpeciesName',
'change [data-hook=specie-mode]' : 'setSpeciesMode',
'change [data-hook=switching-tol]' : 'setSwitchingType',
'change [data-hook=switching-min]' : 'setSwitchingType',
'change [data-hook=observable]' : 'setObservable',
'click [data-hook=edit-annotation-btn]' : 'editAnnotation',
'click [data-hook=remove]' : 'removeSpecie',
'click [data-hook=collapse-advanced]' : 'changeCollapseButtonText'
Expand Down Expand Up @@ -152,6 +159,9 @@ module.exports = View.extend({
}}
);
},
setObservable: function (e) {
this.model.observable = !this.model.observable;
},
setSpeciesMode: function (e) {
this.model.mode = e.target.value;
this.model.collection.trigger('update-species', this.model.compID, this.model, false, false);
Expand Down
6 changes: 6 additions & 0 deletions client/model-view/views/species-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ module.exports = View.extend({
this.collection.on('update-species', (compID, specie, isNameUpdate, isDefaultMode) => {
this.collection.parent.reactions.forEach((reaction) => {
var changedReaction = false;
if(reaction.rate && reaction.rate.compID === compID){
reaction.rate = specie;
if(reaction.reactionType !== 'custom-propensity') {
changedReaction = true;
}
}
reaction.reactants.forEach((reactant) => {
if(reactant.specie.compID === compID) {
reactant.specie = specie;
Expand Down
7 changes: 7 additions & 0 deletions client/models/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ module.exports = State.extend({
// timeZone = timeZone.replace('(', '').replace(')', '') // remove the '()' from the timezone
return stamp + hours + ":" + minutes + " " + ampm + " " + timeZone;
}
},
sortTime: {
deps: ["startTime"],
fn: function () {
let date = new Date(this.startTime);
return Math.round(date.getTime() / 1000);
}
}
}
});
3 changes: 2 additions & 1 deletion client/models/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ let Collection = require('ampersand-collection');
let Job = require('./job');

module.exports = Collection.extend({
model: Job
model: Job,
comparator: 'sortTime'
});