@lsandini/cgmsim-lib
- arrows
- downloads
- loadActivity
- simulator
- simulatorUVA
- uploadActivity
- uploadEntries
- uploadLogs
- uploadNotes
▸ arrows(sgvLast
, sgv1
, sgv2
, sgv3
): Object
Calculates the direction of blood glucose change based on recent data.
Name | Type | Description |
---|---|---|
sgvLast |
number |
The most recent blood glucose value. |
sgv1 |
number |
Blood glucose value 5 minutes ago. |
sgv2 |
number |
Blood glucose value 10 minutes ago. |
sgv3 |
number |
Blood glucose value 15 minutes ago. |
Object
An object containing the direction of blood glucose change and the variation.
Name | Type |
---|---|
direction |
Direction |
sgvdir |
number |
Example
// Calculate blood glucose direction based on recent data
const sgvLast = 120;
const sgv1 = 115;
const sgv2 = 110;
const sgv3 = 105;
const result = calculateGlucoseDirection(sgvLast, sgv1, sgv2, sgv3);
console.log("Blood glucose direction:", result.direction);
console.log("Blood glucose variation:", result.sgvdir);
▸ downloads(nsUrl
, apiSecret
): Promise
<{ entries
: Sgv
[] ; profiles
: NSProfile
[] ; treatments
: NSTreatment
[] }>
Downloads data from the Nightscout API, including treatments, profiles, and entries.
Name | Type | Description |
---|---|---|
nsUrl |
string |
Nightscout URL. |
apiSecret |
string |
Nightscout API secret. |
Promise
<{ entries
: Sgv
[] ; profiles
: NSProfile
[] ; treatments
: NSTreatment
[] }>
A promise that resolves with downloaded data.
Example
// Download data from Nightscout API
const apiUrl = "https://nightscout.example.com";
const apiSecret = "apiSecret123";
downloads(apiUrl, apiSecret)
.then((downloadedData) => {
console.log("Downloaded data:", downloadedData);
})
.catch((error) => {
console.error("Error downloading data:", error);
});
▸ loadActivity(nsUrl
, apiSecret
, fromUtcString?
): Promise
<(Note
| Activity
| Entry
)[]>
Loads activity data from the Nightscout API based on optional time filter.
Name | Type | Default value | Description |
---|---|---|---|
nsUrl |
string |
undefined |
Nightscout URL. |
apiSecret |
string |
undefined |
Nightscout API secret. |
fromUtcString |
string |
null |
Optional UTC timestamp to filter data from. |
Promise
<(Note
| Activity
| Entry
)[]>
A promise that resolves with the loaded activity data.
Example
// Load activity data from Nightscout
const apiUrl = "https://nightscout.example.com";
const apiSecret = "apiSecret123";
const fromDate = "2023-01-01T00:00:00.000Z"; // Optional UTC timestamp filter
loadActivityData(apiUrl, apiSecret, fromDate)
.then((activityData) => {
console.log("Loaded activity data:", activityData);
})
.catch((error) => {
console.error("Error loading activity data:", error);
});
▸ simulator(params
): SimulationResult
Simulation module for blood glucose data calculation.
Name | Type | Description |
---|---|---|
params |
MainParams |
Main parameters for running the simulation. |
Simulation result containing blood glucose data and other parameters.
▸ simulatorUVA(params
): Object
Simulates blood glucose levels in response to various parameters and inputs.
Name | Type | Description |
---|---|---|
params |
MainParamsUVA |
Main parameters for running the simulation. |
Object
Simulation result containing blood glucose data and patient state.
Name | Type |
---|---|
sgv |
number |
state |
{ Gp : number ; Gt : number ; I_ : number ; Il : number ; Ip : number ; Isc1 : number ; Isc2 : number ; Qgut : number ; Qsto1 : number ; Qsto2 : number ; W : number ; X : number ; XL : number ; Y : number ; Z : number } |
state.Gp |
number |
state.Gt |
number |
state.I_ |
number |
state.Il |
number |
state.Ip |
number |
state.Isc1 |
number |
state.Isc2 |
number |
state.Qgut |
number |
state.Qsto1 |
number |
state.Qsto2 |
number |
state.W |
number |
state.X |
number |
state.XL |
number |
state.Y |
number |
state.Z |
number |
Example
// Run a blood glucose simulation with specified parameters
const simulationParams = {
env: {
WEIGHT: "70",
AGE: "35",
GENDER: "Male",
// ... other environment parameters ...
},
treatments: [
// ... treatment data ...
],
profiles: [
// ... profile data ...
],
lastState: {
// ... patient state data ...
},
entries: [
// ... blood glucose entry data ...
],
pumpEnabled: true,
activities: [
// ... activity data ...
],
user: {
nsUrl: "https://nightscout.example.com",
// ... other user-related data ...
},
};
const simulationResult = simulator(simulationParams);
console.log("Blood glucose simulation result:", simulationResult);
▸ uploadActivity(activity
, nsUrl
, apiSecret
): Promise
<void
>
Uploads activity data to the Nightscout API.
Name | Type | Description |
---|---|---|
activity |
Activity |
Activity data to upload. |
nsUrl |
string |
Nightscout URL. |
apiSecret |
string |
Nightscout API secret. |
Promise
<void
>
A promise that resolves when the upload is complete.
Example
// Upload activity data to Nightscout
const activityData = {
// ... activity data ...
};
uploadActivity(activityData, "https://nightscout.example.com", "apiSecret123")
.then(() => {
console.log("Activity data uploaded successfully.");
})
.catch((error) => {
console.error("Error uploading activity data:", error);
});
▸ uploadEntries(cgmsim
, nsUrl
, apiSecret
): Promise
<void
>
Uploads entries (e.g., blood glucose readings) to the Nightscout API.
Name | Type | Description |
---|---|---|
cgmsim |
EntryValueType |
The entry data to upload. |
nsUrl |
string |
Nightscout URL. |
apiSecret |
string |
Nightscout API secret. |
Promise
<void
>
A promise that resolves when the upload is complete.
Example
// Upload a blood glucose entry to Nightscout
const glucoseEntry = {
// ... glucose entry data ...
};
uploadEntries(glucoseEntry, "https://nightscout.example.com", "apiSecret123")
.then(() => {
console.log("Blood glucose entry uploaded successfully.");
})
.catch((error) => {
console.error("Error uploading blood glucose entry:", error);
});
▸ uploadLogs(simResult
, nsUrl
, apiSecret
): Promise
<void
>
Uploads logs to the Nightscout API.
Name | Type | Description |
---|---|---|
simResult |
SimulationResult & { notes : string } |
Simulation result with attached notes. |
nsUrl |
string |
Nightscout URL. |
apiSecret |
string |
Nightscout API secret. |
Promise
<void
>
A promise that resolves when the upload is complete.
Example
// Upload simulation logs to Nightscout
const simulationResult = {
// ... simulation result data ...
notes: "Simulation complete",
};
uploadLogs(simulationResult, "https://nightscout.example.com", "apiSecret123")
.then(() => {
console.log("Logs uploaded successfully.");
})
.catch((error) => {
console.error("Error uploading logs:", error);
});
▸ uploadNotes(notes
, nsUrl
, apiSecret
): Promise
<void
>
Uploads notes to the Nightscout API.
Name | Type | Description |
---|---|---|
notes |
string |
The notes to upload. |
nsUrl |
string |
Nightscout URL. |
apiSecret |
string |
Nightscout API secret. |
Promise
<void
>
A promise that resolves when the upload is complete.
Example
// Upload a note to Nightscout
uploadNotes("Important note", "https://nightscout.example.com", "apiSecret123")
.then(() => {
console.log("Note uploaded successfully.");
})
.catch((error) => {
console.error("Error uploading note:", error);
});