-
Notifications
You must be signed in to change notification settings - Fork 8
/
detemir-old-model.js
42 lines (35 loc) · 1.37 KB
/
detemir-old-model.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
39
40
41
42
const dotenv = require('dotenv');
var result = require('dotenv').config();
require('json.date-extensions');
JSON.useDateParser();
var resultDetAct = 0;
const weight = parseInt(process.env.WEIGHT);
const detemirs = require('./files/last_detemir.json');
var jsondet = JSON.stringify(detemirs);
var detemir_data = JSON.parseWithDate(jsondet);
console.log(detemir_data);
// activities be expressed as U/min !!!
let timeSinceDetemirAct = detemir_data.map(entry => {
var time = entry.time;
var dose = entry.dose;
var duration = (16 + (20*dose/weight));
return { ...entry, time: time, duration: duration, detemirActivity: (dose * (Math.PI/(duration*2))*(Math.sin(time*Math.PI/duration)))/60};
});
console.log('these are the detemir activities:',timeSinceDetemirAct);
// compute the aggregated activity of last detemirs in 30 hours
let lastDetemirs = timeSinceDetemirAct.filter(function (e) {
return e.time <= 30;
});
console.log('these are the last detemirs and activities:',lastDetemirs);
var resultDetAct = lastDetemirs.reduce(function(tot, arr) {
return tot + arr.detemirActivity;
},0);
console.log(resultDetAct);
const fs = require('fs');
const DetAct = JSON.stringify(resultDetAct, null, 4);
fs.writeFile('./files/last_detemir_aggrACT.json', DetAct, (err) => {
if (err) {
throw err;
}
console.log("aggregated DET activity is now is saved as JSON.");
});