• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hetalang / heta-compiler / 15021494632

14 May 2025 01:06PM UTC coverage: 67.864%. Remained the same
15021494632

push

github

metelkin
refactor: remove repeatCount references

1803 of 2784 branches covered (64.76%)

Branch coverage included in aggregate %.

3092 of 4429 relevant lines covered (69.81%)

83.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

3.37
/src/dbsolve-export/namespace.js
1
const { Namespace } = require('../namespace');
1✔
2
const _get = require('lodash/get');
1✔
3

4
/**
5
 * Creates single model image by nesessary components based on space.
6
 * @param {string} targetSpace - Model image to update.
7
 *
8
 * @return {undefined}
9
 */
10
Namespace.prototype.getDBSolveImage = function(powTransform, groupConstBy, version) {
1✔
11
  let { logger } = this.container;
×
12

13
  // push active processes
14
  let processes = this
×
15
    .selectByInstanceOf('Process')
16
    .filter((x) => {
17
      return x.actors.length > 0 // process with actors
×
18
        && x.actors.some((actor) => { // true if there is at least non boundary target
19
          return !actor.targetObj.boundary && !actor.targetObj.isRule;
×
20
        });
21
    });
22
  // push non boundary ode variables which are mentioned in processes
23
  let dynamicRecords = this
×
24
    .selectByInstanceOf('Record')
25
    .filter((x) => x.isDynamic);
×
26
  /*
27
  let staticRecords = this
28
    .selectByInstanceOf('Record')
29
    .filter((x) => !x.isDynamic && !x.isRule);
30
  */
31
  let initRecords = this
×
32
    .sortExpressionsByContext('start_', true)
33
    .filter((x) => {
34
      return x.instanceOf('Record') 
×
35
        && (x.assignments?.start_ !== undefined || x.isRule);
36
    }); 
37
  // create matrix
38
  let matrix = [];
×
39
  processes.forEach((process, processNum) => {
×
40
    process.actors.filter((actor) => {
×
41
      return !actor.targetObj.boundary
×
42
        && !actor.targetObj.isRule;
43
    }).forEach((actor) => {
44
      let variableNum = dynamicRecords.indexOf(actor.targetObj);
×
45
      matrix.push([processNum, variableNum, actor.stoichiometry]);
×
46
    });
47
  });
48

49
  // create and sort expressions for RHS (rules)
50
  let ruleRecords = this
×
51
    .sortExpressionsByContext('ode_', true)
52
    .filter((x) => x.isDynamic || x.isRule );
×
53

54
  // create TimeEvents
55
  let timeEvents = [];
×
56
  this
×
57
    .selectByInstanceOf('TimeSwitcher')
58
    .forEach((switcher) => { // scan for switch
59
      // if period===undefined or period===0 => single dose
60
      // if period > 0 => multiple dose
61
      let period = switcher.periodObj === undefined || switcher.repeatCountObj?.num === 0
×
62
        ? 0
63
        : switcher.getPeriod();
64
      this
×
65
        .selectRecordsByContext(switcher.id)
66
        .forEach((record) => { // scan for records in switch
67
          let expr = record.isDynamic && record.instanceOf('Species') && !record.isAmount
×
68
            ? record.getAssignment(switcher.id).multiply(record.compartment)
69
            : record.getAssignment(switcher.id);
70

71
          let evt = {
×
72
            start: switcher.getStart(),
73
            period: period,
74
            on: switcher.id + '_',
75
            target: record.id + (record.isDynamic ? '_' : ''),
×
76
            multiply: 0,
77
            add: record.id + '_' + switcher.id + '_',
78
            expr: expr.toSLVString(logger, powTransform)
79
          };
80
          timeEvents.push(evt);
×
81
        });
82

83
      // transform `stop` to `event`
84
      if (switcher.stopObj !== undefined) {
×
85
        let evt = {
×
86
          start: switcher.getStop(),
87
          period: 0,
88
          on: 1,
89
          target: switcher.id + '_',
90
          multiply: 0,
91
          add: 0,
92
          isStop: true // if false then do not put in RHS
93
        };
94
        timeEvents.push(evt);
×
95
      }
96
    });
97

98
  // Discrete Events
99
  let discreteEvents = this
×
100
    .selectByClassName('DSwitcher')
101
    .map((switcher) => {
102
      // check boolean expression in trigger
103
      if (!switcher.trigger.isComparison) {
×
104
        let msg = `DBSolve supports only simple comparison operators in DSwitcher trigger, got: "${switcher.trigger.toString()}"`;
×
105
        logger.error(msg, {type: 'ExportError'});
×
106
      }       
107
      
108
      let assignments = this
×
109
        .selectRecordsByContext(switcher.id)
110
        .map((record) => {
111
          let expr = record.isDynamic && record.instanceOf('Species') && !record.isAmount
×
112
            ? record.getAssignment(switcher.id).multiply(record.compartment)
113
            : record.getAssignment(switcher.id);
114

115
          return {
×
116
            targetObj: record,
117
            expr: expr
118
          };
119
        });
120
        
121
      return {
×
122
        switcher,
123
        assignments
124
      };
125
    });
126

127
  // Continuous Events
128
  let continuousEvents = this
×
129
    .selectByClassName('CSwitcher')
130
    .map((switcher) => {
131
      // CSWitcher is not supported in DBsolve
132
      let msg = `DBSolve does not support CSwitcher, got: "${switcher.id}. It will be transformed to DSwitcher"`;
×
133
      logger.warn(msg, {type: 'ExportWarning'});
×
134

135
      let assignments = this
×
136
        .selectRecordsByContext(switcher.id)
137
        .map((record) => {
138
          let expr = record.isDynamic && record.instanceOf('Species') && !record.isAmount
×
139
            ? record.getAssignment(switcher.id).multiply(record.compartment)
140
            : record.getAssignment(switcher.id);
141

142
          return {
×
143
            targetObj: record,
144
            expr: expr
145
          };
146
        });
147
        
148
      return {
×
149
        switcher,
150
        assignments
151
      };
152
    });
153
  // group Const, instead of groupBy
154
  let groupedConst = {}; // {group1: [const1, const2], group2: [const3, const4]}
×
155
  this.selectByClassName('Const').forEach((constant) => {
×
156
    let key = _get(constant, groupConstBy) + '';
×
157
    if (!groupedConst.hasOwnProperty(key)) {
×
158
      groupedConst[key] = [];
×
159
    }
160
    groupedConst[key].push(constant);
×
161
  });
162

163
  return {
×
164
    population: this,
165
    dynamicRecords,
166
    initRecords,
167
    ruleRecords,
168
    processes,
169
    matrix,
170
    powTransform: powTransform,
171
    version: version,
172
    timeEvents,
173
    discreteEvents,
174
    continuousEvents,
175
    groupedConst,
176
    logger
177
  };
178
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc