Other functions

CONGAn(Glu_interp)

Function to compute the CONGAn index

Parameters

Glu_interpTYPE

DESCRIPTION.

Returns

TYPE

DESCRIPTION.

DATA_DIR = './Data/'

Path where raw sensor data are kept

FILENAMES = '"Filename","Sensor"\n"Capteur_freestyle.txt","freeStyle"\n"Capteur_freestyle_pro.csv","freeStyle_pro_ancien"\n"Capteur_standard.csv","standard"\n"Capteur.csv","ipro2"\n"Capteur_valeur.csv","ipro2_valeur"\n"Capteur.txt","dexcom"\n"CLARITY_CANADA_EXPORT.csv","dexcom_canada"\n"MEDTRONIC_CANADA_EXPORT.csv","medtronic_canada"\n"DIASEND_CANADA_EXPORT.csv","diasend_canada"\n"TIDEPOOL_CANADA_EXPORT.csv","tidepool_canada"'

Default Correspondance between glycemic data filename and sensor model

LIBRARY = '"Sensor","encoding","delimiter","skiprows","col_date","col_time","col_datetime","dayfirst","col_value","units"\n"freeStyle","utf-8","\t","1","","","Heure","FALSE","Historique du taux de glucose (mg/dL)","mg/dL"\n"freeStyle_pro_ancien","utf-8",";|\t","2","","","Horodatage de l\'appareil","TRUE","Historique de la glycémie mg/dL","mg/dL"\n"standard","utf-8",";|s","0","Date (jj/mm/aaaa)","Heure(hh:mm:ss)","","TRUE","Capteur de glycemie (mg/dl)","mg/dL"\n"ipro2","utf-16le","\t","11","Date","Heure","Horodatage","TRUE","Capteur de glycémie (mg/dl)","mg/dL"\n"dexcom","utf-8","\t","0","","","GlucoseInternalTime","TRUE","GlucoseValue","mg/dL"\n"dexcom_canada","utf-8",",","0","","","Timestamp (YYYY-MM-DDThh:mm:ss)","FALSE","Glucose Value (mmol/L)","mmol/L"\n"medtronic_canada","utf-8",";","6","Date","Time","","TRUE","Sensor Glucose (mmol/L)","mmol/L"\n"diasend_canada","utf-8",";","4","","","Time","TRUE","mmol/L","mmol/L"\n"tidepool_canada","utf-8",";","0","","","Local Time","FALSE","Value","mmol/L"\n"ipro2_valeur","utf-16le","\t","11","Date","Heure","Horodatage","TRUE","Valeur de capteur (mg/dl)","mg/dL"'

Default Format of sensor files to open in python

RESULT_DIR = './Patients/'

Path where Glyapp results are kept

SENSORS_FILENAME = './filename_sensors.csv'

Correspondance filename betwwen sensors

SENSORS_LIBRARY = './sensor_library.csv'

Sensors library filename

calc_MAGE(Glu_interp, Time, nstd, Tav)

Function to compute the mAGE index on interpolated glycemic data

Parameters

Glu_interp(n) array of float

Glycemic time serie, equally sampled in time

Time(n) array of float

Corresponding time array

nstdTYPE

DESCRIPTION.

TavTYPE

Moving average duration

Returns

Amplitude_realTYPE

Array of amplitude of glycemic variabilities between peaks

Time_AmplitudeTYPE

Array of time stamp between peaks

idAll_filtTYPE

Index of peaks

calc_glu(patient='XX', GluCible=array([[70, 140], [70, 180], [54, 200], [60, 300]]), intervals=array([], shape=(0, 2), dtype=float64), WRITE='a', encoding='utf-8', verbose=False, interp=False)

Function to compute glycemic statistics of a patient glycemic time series, located in the folder DATA_DIR/patient/

Parameters

patientstr

Name of the folder containing all patient’s data in the DATA_DIR folder, which is ./Data/ by default.

GluCiblearray

(n,2) array containing the values of glycemic levels for hypo and hyper glycemia

WRITE‘a’, ‘w’

‘a’ append or ‘r’ replace result file

encodingstr

(old) Used to force glycemic file encoding

verboseTrue/False

To display more results

interpFalse/True

To compute statistics on interpolated data rather than raw sensor data

returns:

Bool

Returns

bool

if result is successfull

calc_hypo(Glu_interp, T_interp, time_hypo, glu_hypo)

Function to compute statistics of short or prolongated hypoglycemia events

Parameters

Glu_interpTYPE

DESCRIPTION.

T_interpTYPE

DESCRIPTION.

time_hypotuple

tuple of [time_ep_start,time_ep_stop] values.

glu_hypotuple

tuple of [hypo_start,hypo_stop] values.

Returns

None.

clean_data(GluTime, GluValue)
conversion_factor(units)
date_col_num(d)
datenum(d)
gly_hypo_prol = [54, 54]

Glycemia (mg/l) of prolongates hypoglycemia start and end

gly_hypo_short = [54, 70]

Glycemia (mg/l) of short hypoglycemia start and end

import_libraries_pyodide()
import_libraries_urllib()
init_environment(patient='XX')

Prepare the local folder structure for the first time where data has to be stored and results are written.

Create the sensor database if the file do not exist.

Create a test case with synthetic data for patient name XX.

Parameters

patientstr, optional

Codename of the patient to create. The default is ‘XX’.

Returns

None.

make_synthetic_gly_data(patient='XX', ndays=30, dt=15, gly_mean=150, gly_std=150, gly_corr=30, start_date='2025-01-01', seed=0)

Return a CSV file with synthetic glycemic data time series

Parameters

patientstr, optional

Codename of patient to create. The default is ‘XX’.

ndaysint, optional

Duration f the time serie in days. The default is 30.

dtint, optional

Measure intervals in minuts. The default is 15.

gly_meanfloat, optional

Mean glycemia. The default is 150.

gly_stdfloat, optional

Standard deviation of glycemia. The default is 150.

gly_corrfloat, optional

Time correlation of glycemia in min. The default is 30.

start_datestr, optional

Start date of the timeserie. The default is “2025-01-01”.

seedint, optional

Seed for random generator.

Returns

None.

numdate(n)
plot_patient(patient='XX', encoding='utf-8', start=None, end=None, start_Hour=7, hypo=70, hyper=180, superhypo=54, superhyper=250, plot_acc=False, filt_acc=1, seuils_acc=[0, 100, 250, 500, 1000, 2000], plot_temp=0, plot_bpm=False, filt_bpm=1, seuils_bpm=[20, 300], plot_alt=0, savefig=True, lw=2)

Plot the patient data on a dayly basis

Parameters

patientTYPE, optional

DESCRIPTION. The default is ‘XX’.

encodingTYPE, optional

DESCRIPTION. The default is ‘utf-8’.

startTYPE, optional

DESCRIPTION. The default is None.

endTYPE, optional

DESCRIPTION. The default is None.

start_HourTYPE, optional

DESCRIPTION. The default is 7.

hypoTYPE, optional

DESCRIPTION. The default is 70.

hyperTYPE, optional

DESCRIPTION. The default is 180.

superhypoTYPE, optional

DESCRIPTION. The default is 54.

superhyperTYPE, optional

DESCRIPTION. The default is 250.

plot_accTYPE, optional

DESCRIPTION. The default is False.

filt_accTYPE, optional

DESCRIPTION. The default is 1.

seuils_accTYPE, optional

DESCRIPTION. The default is [0,100,250,500,1000,2000].

plot_tempTYPE, optional

DESCRIPTION. The default is 0.

plot_bpmTYPE, optional

DESCRIPTION. The default is False.

filt_bpmTYPE, optional

DESCRIPTION. The default is 1.

seuils_bpmTYPE, optional

DESCRIPTION. The default is [20,300].

plot_altTYPE, optional

DESCRIPTION. The default is 0.

savefigTYPE, optional

DESCRIPTION. The default is True.

lwTYPE, optional

DESCRIPTION. The default is 2.

Returns

None.

read_Glu(patient, encoding='utf-8')
read_accelero(patient)
read_cardio(patient)
read_glu_octave(patient, encoding='utf-8')
read_glu_pandas(patient, verbose=True)
read_libraries(delimiter=',', encoding='utf-8')
short_plot_patient(patient='GZ2', encoding='utf-8', start=None, end=None, hypo=70, hyper=180, superhypo=54, superhyper=250, plot_acc=False, filt_acc=1, seuils_acc=[0, 100, 250, 500, 1000, 2000], plot_bpm=False, filt_bpm=1, seuils_bpm=[20, 60, 100, 120, 150, 200, 300], plot_alt=0, savefig=True, lw=2)
sort_times(GluTime, GluValue)
test_all()

Function to test all the glycemic sensor reading of all folders present in DATA Show errors of reading in red

time_hypo_prol = [120, 120]

Time (minutes) of prolongated hypoglycemia start and end

time_hypo_short = [15, 15]

Time (minutes) of short hypoglycemia start and end