Skip to content

Commit

Permalink
edit logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nickxbs committed Apr 9, 2024
1 parent 370f668 commit 217de26
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
34 changes: 15 additions & 19 deletions src/CGMSIMsimulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import { transformNoteTreatmentsDrug } from './drug';
*/
const simulator = (params: MainParams): SimulationResult => {
const {
patient: env,
patient,
entries,
treatments,
profiles, //PUMP SIMULATION
pumpEnabled,
activities, //7-DAYS
user,
} = params;
logger.info('Run Init CGMSim NSUrl:%o', user.nsUrl);
logger.info(user.nsUrl + ' Run Init CGMSim NSUrl:%o', user.nsUrl);

if (!treatments) {
throw new Error('treatments is ' + treatments);
Expand All @@ -35,9 +35,9 @@ const simulator = (params: MainParams): SimulationResult => {
throw new Error('profiles is ' + profiles);
}

const isfConstant = env.ISF;
const age = env.AGE;
const gender = env.GENDER;
const isfConstant = patient.ISF;
const age = patient.AGE;
const gender = patient.GENDER;

let isfActivityDependent = isfConstant;
let activityFactor = 1;
Expand All @@ -49,11 +49,11 @@ const simulator = (params: MainParams): SimulationResult => {
activityFactor = physicalLiver(activities, age, gender);

Check warning on line 49 in src/CGMSIMsimulator.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 50 in src/CGMSIMsimulator.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

const weight = env.WEIGHT;
const dia = env.DIA;
const peak = env.TP;
const carbsAbs = env.CARBS_ABS_TIME;
const cr = env.CR;
const weight = patient.WEIGHT;
const dia = patient.DIA;
const peak = patient.TP;
const carbsAbs = patient.CARBS_ABS_TIME;
const cr = patient.CR;

//Find basal boluses
const drugs = transformNoteTreatmentsDrug(treatments);
Expand Down Expand Up @@ -95,15 +95,11 @@ const simulator = (params: MainParams): SimulationResult => {
isfActivityDependent,
);

logger.debug('this is the new sgv: %o', newSgvValue);
logger.info(
'this is the ISF multiplicator (or physicalISF): %o',
isfActivityDependent / isfConstant,
);
logger.info(
'this is the liver multiplicator (or physicalLiver): %o',
activityFactor,
);
logger.info(user.nsUrl + 'this is the simulator result: %o', {
...newSgvValue,
physicalISF: isfActivityDependent / isfConstant,
physicalLiver: activityFactor,
});

// const arrows = arrowsRun([newSgvValue, ...entries]);

Expand Down
24 changes: 12 additions & 12 deletions src/UVAsimulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { defaultPatient } from './defaultPatient';
*/
const UVAsimulator = (params: MainParamsUVA) => {
const {
patient: env,
patient,
treatments,
profiles,
lastState,
Expand All @@ -66,7 +66,7 @@ const UVAsimulator = (params: MainParamsUVA) => {
user,
} = params;

logger.info('Run Init UVA NSUrl:%o', user.nsUrl);
logger.debug('Run Init UVA NSUrl:%o', user.nsUrl);

if (!treatments) {
throw new Error('treatments is ' + treatments);
Expand All @@ -75,9 +75,9 @@ const UVAsimulator = (params: MainParamsUVA) => {
throw new Error('profiles is ' + profiles);
}

const weight = env.WEIGHT;
const age = env.AGE;
const gender = env.GENDER;
const weight = patient.WEIGHT;
const age = patient.AGE;
const gender = patient.GENDER;
const drugs = transformNoteTreatmentsDrug(treatments);

const activeDrugTreatments = drugs.filter(function (e) {
Expand Down Expand Up @@ -107,15 +107,15 @@ const UVAsimulator = (params: MainParamsUVA) => {

const basalProfileActivity = pumpEnabled ? basalProfile(profiles) : 0;

const patient = new PatientUva(defaultPatient);
const patientUva = new PatientUva(defaultPatient);
let partialMinutes = 0;
const fiveMinutes: UvaInterval = 5;
const oneMinute: UvaDelta = 1;

//get last state from mongo
let patientState: UvaPatientState = lastState
? lastState
: patient.getInitialState();
: patientUva.getInitialState();

logger.debug('basalProfileActivity:%o', basalProfileActivity * 60);
logger.debug('basalActivity:%o', basalActivity * 60);
Expand All @@ -129,14 +129,14 @@ const UVAsimulator = (params: MainParamsUVA) => {
intensity: 0,
};
//t0 result
let result: UvaOutput = patient.getOutputs(
let result: UvaOutput = patientUva.getOutputs(
partialMinutes,
patientState,
userParams,
);
const lastPatientState = { ...patientState };
// start simulation
logger.info('lastPatientState:%o', lastPatientState);
logger.debug(user.nsUrl + ' lastPatientState:%o', lastPatientState);

while (partialMinutes < fiveMinutes) {
// todo: sensor dynamics
Expand Down Expand Up @@ -165,13 +165,13 @@ const UVAsimulator = (params: MainParamsUVA) => {
// proceed one time step
patientState = RK4(
(time: number, state: UvaPatientState) =>
patient.getDerivatives(time, state, userParams),
patientUva.getDerivatives(time, state, userParams),
partialMinutes,
patientState,
oneMinute,
);
//t partialMinutes result
result = patient.getOutputs(partialMinutes, patientState, userParams);
result = patientUva.getOutputs(partialMinutes, patientState, userParams);
partialMinutes += oneMinute;
}
if (result.Gp > 400) {
Expand All @@ -181,7 +181,7 @@ const UVAsimulator = (params: MainParamsUVA) => {
return { state: lastPatientState, sgv: 40 };
}
const res = { state: patientState, sgv: result.Gp };
logger.info('uva output:%o', res);
logger.info(user.nsUrl + ' uva output:%o', res);
return res;
};

Expand Down
2 changes: 1 addition & 1 deletion src/liver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function (

const liver_sin = liver * sinus;
logger.debug('liver: %o', liver);
logger.info('liver_sin: %o', liver_sin);
logger.debug('liver_sin: %o', liver_sin);

return liver_sin; //(mmol/l)/min
}
1 change: 0 additions & 1 deletion src/sgv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ const sgv_start = (
' minutes: %o',
bolusActivity * deltaMinutes * 18 * isfMMol,
);
logger.info('this is the simulator result: %o', dict);

return dict;
};
Expand Down

1 comment on commit 217de26

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 94.67% 800/845
🟢 Branches 80.14% 222/277
🟢 Functions 92.94% 158/170
🟢 Lines 94.91% 783/825

Test suite run success

271 tests passing in 19 suites.

Report generated by 🧪jest coverage report action from 217de26

Please sign in to comment.