UNPKG

@metacell/geppetto-meta-core

Version:

The core functionality of geppetto-meta to build and simulate neuroscience data and models.

103 lines (102 loc) 2.76 kB
/** * Client class use to augment a model with state variable capabilities * * @module model/AStateVariableCapability * @author Matteo Cantarelli */ export default { capabilityId: 'StateVariableCapability', watched: false, timeSeries: null, unit: null, /** * Get value of quantity * * @command Variable.getTimeSeries() * @returns {String} Value of quantity */ getTimeSeries: function getTimeSeries() { if (!this.timeSeries) { var timeSeries = undefined; var initialValues = this.getVariable().getWrappedObj().initialValues; if (initialValues != undefined) { for (var i = 0; i < initialValues.length; i++) { if (initialValues[i].value.eClass === 'TimeSeries') { timeSeries = initialValues[i].value.value; } } } return timeSeries; } return this.timeSeries; }, /** * Set the time series for the state variable * * @command Variable.setTimeSeries() * @returns {Object} The state variable */ setTimeSeries: function setTimeSeries(timeSeries) { this.timeSeries = timeSeries; return this; }, /** * Get the initial value for the state variable * * @command Variable.getInitialValue() * @returns {Object} The initial value of the state variable */ getInitialValue: function getInitialValue() { return this.getVariable().getWrappedObj().initialValues; }, /** * Set unit value * * @param unit */ setUnit: function setUnit(unit) { this.unit = unit; }, /** * Get the type of tree this is * * @command Variable.getUnit() * @returns {String} Unit for quantity */ getUnit: function getUnit() { return this.unit == null ? this.extractUnit() : this.unit; }, extractUnit: function extractUnit() { var unit = undefined; var initialValues = this.getVariable().getWrappedObj().initialValues; for (var i = 0; i < initialValues.length; i++) { if (initialValues[i].value.eClass === 'PhysicalQuantity' || initialValues[i].value.eClass === 'TimeSeries') { unit = initialValues[i].value.unit.unit; } } return unit; }, /** * Get watched * * @command Variable.getWatched() * @returns {boolean} true if this variable is being watched */ isWatched: function isWatched() { // NOTE: this.watched is a flag added by this API / Capability return this.watched; }, /** * Set watched * * @command Variable.setWatched() * @param {Boolean} watched - Object with options attributes to initialize node */ setWatched: function setWatched(isWatched, updateServer) { if (updateServer == undefined) { updateServer = true; } this.watched = isWatched; return this; } };