forked from drugis/gemtc-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodelService.js
38 lines (34 loc) · 1.04 KB
/
modelService.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
var modelRepository = require('./modelRepository');
var _ = require('lodash');
function update(oldModel, newModel, callback) {
if (newModel.burnInIterations < oldModel.burnInIterations ||
newModel.inferenceIterations < oldModel.inferenceIterations) {
var errorMessage = 'Error: may not update model with lower number of iterations';
callback(errorMessage);
} else {
modelRepository.update(newModel, callback);
}
}
function partitionModels(models) {
var partition = _.partition(models, function(model) {
return model.taskUrl !== null && model.taskUrl !== undefined;
});
return {
modelsWithTask: partition[0],
modelsWithoutTask: partition[1]
};
}
function decorateWithRunStatus(models, pataviResult) {
var tasks = _.keyBy(pataviResult, 'id');
return _.map(models, function(model) {
return _.extend(model, {
runStatus: tasks[model.taskUrl].runStatus
});
});
}
module.exports = {
update: update,
partitionModels: partitionModels,
decorateWithRunStatus: decorateWithRunStatus
};