Skip to content

Commit

Permalink
Finalize tests for JOS3
Browse files Browse the repository at this point in the history
JOS3 for `dict_result` are finally in!
  • Loading branch information
jordanocokoljic committed Feb 1, 2024
1 parent ac9a2e0 commit 1ec11e1
Show file tree
Hide file tree
Showing 4 changed files with 15,104 additions and 4 deletions.
63 changes: 61 additions & 2 deletions src/models/JOS3.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { local_q_work } from "../jos3_functions/thermoregulation/local_q_work.js
import { cr_ms_fat_blood_flow } from "../jos3_functions/thermoregulation/cr_ms_fat_blood_flow.js";
import { resp_heat_loss } from "../jos3_functions/thermoregulation/resp_heat_loss.js";
import { sum_bf } from "../jos3_functions/thermoregulation/sum_bf.js";
import Object from "lodash/object.js";

/**
* Create an array of shape (17,) with the given input.
Expand Down Expand Up @@ -522,7 +523,12 @@ export class JOS3 {
q_thermogenesis_muscle,
q_thermogenesis_fat,
q_thermogenesis_skin,
} = sum_m(q_bmr_local, q_work, q_shiv, q_nst);
} = sum_m(
q_bmr_local.map((c) => c.clone()),
q_work,
q_shiv,
q_nst,
);

let q_thermogenesis_total =
math.sum(q_thermogenesis_core) +
Expand Down Expand Up @@ -845,7 +851,60 @@ export class JOS3 {
* @returns {object}
*/
dict_results() {
throw new Error("Not implemented");
if (!this._history || this._history.length === 0) {
console.log("The model has no data.");
return null;
}

const checkWordContain = (word, ...args) => {
return args.some((arg) => word.includes(arg));
};

let key2keys = {}; // Column keys
for (let [key, value] of Object.entries(this._history[0])) {
let keys;
if (value.length !== undefined) {
if (typeof value === "string") {
keys = [key]; // string is iter. Convert to list without suffix
} else if (checkWordContain(key, "sve", "sfv", "superficialvein")) {
keys = VINDEX["sfvein"].map((i) => `${key}_${BODY_NAMES[i]}`);
} else if (checkWordContain(key, "ms", "muscle")) {
keys = VINDEX["muscle"].map((i) => `${key}_${BODY_NAMES[i]}`);
} else if (checkWordContain(key, "fat")) {
keys = VINDEX["fat"].map((i) => `${key}_${BODY_NAMES[i]}`);
} else if (value.length === 17) {
keys = BODY_NAMES.map((bn) => `${key}_${bn}`);
} else {
keys = Array.from(
{ length: value.length },
(_, i) => `${key}_${BODY_NAMES[i]}`,
);
}
} else {
keys = [key];
}

key2keys[key] = keys;
}

let data = this._history.map((dictout) => {
let row = {};
for (let [key, value] of Object.entries(dictout)) {
let keys = key2keys[key];
let values = keys.length === 1 ? [value] : value;
keys.forEach((k, i) => {
row[k] = values[i];
});
}
return row;
});

let outDict = {};
Object.keys(data[0]).forEach((key) => {
outDict[key] = data.map((row) => row[key]);
});

return outDict;
}

/**
Expand Down
Loading

0 comments on commit 1ec11e1

Please sign in to comment.