Skip to content

Commit 7abf833

Browse files
committed
Added the ice functions
1 parent db938f9 commit 7abf833

1 file changed

Lines changed: 57 additions & 5 deletions

File tree

python_api/python_api.py

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
This file provides an API for calling the functions in the dynamic library. These functions are c-embeddings
33
for swift functions, found in Sources/LoopAlgorithmToPython/LoopAlgorithmToPython.swift.
44
"""
5+
import pandas as pd
6+
57
from helpers import get_bytes_from_json
68

79
import ctypes
@@ -25,17 +27,54 @@ def initialize_exception_handlers():
2527
initializeSignalHandlers()
2628

2729

28-
def generate_prediction(json_file, len=82):
30+
def generate_prediction(json_file, len=72):
2931
json_bytes = get_bytes_from_json(json_file)
3032

3133
swift_lib.generatePrediction.argtypes = [ctypes.c_char_p]
3234
swift_lib.generatePrediction.restype = ctypes.POINTER(ctypes.c_double)
3335

3436
result = swift_lib.generatePrediction(json_bytes)
35-
result_array = [result[i] for i in range(len)]
37+
return [result[i] for i in range(len)]
38+
39+
40+
def get_prediction_dates(json_file):
41+
json_bytes = get_bytes_from_json(json_file)
42+
43+
swift_lib.getPredictionDates.argtypes = [ctypes.c_char_p]
44+
swift_lib.getPredictionDates.restype = ctypes.c_char_p
45+
46+
result = swift_lib.getPredictionDates(json_bytes).decode('utf-8')
47+
date_list = result.split(',')[:-1]
48+
#date_list = [pd.to_datetime(date) for date in date_list]
49+
50+
return date_list
51+
52+
53+
# TODO: Add combined predictions and dates, with assertequals to check whether they are of same length
54+
3655

37-
return result_array
56+
# "Glucose effect velocity" is equivalent to insulin counteraction effect (ICE)
57+
def get_glucose_effect_velocity(json_file, len=72):
58+
json_bytes = get_bytes_from_json(json_file)
59+
60+
swift_lib.getGlucoseEffectVelocity.argtypes = [ctypes.c_char_p]
61+
swift_lib.getGlucoseEffectVelocity.restype = ctypes.POINTER(ctypes.c_double)
62+
63+
result = swift_lib.getGlucoseEffectVelocity(json_bytes)
64+
return [result[i] for i in range(len)]
65+
66+
67+
def get_glucose_effect_velocity_dates(json_file):
68+
json_bytes = get_bytes_from_json(json_file)
69+
70+
swift_lib.getGlucoseEffectVelocityDates.argtypes = [ctypes.c_char_p]
71+
swift_lib.getGlucoseEffectVelocityDates.restype = ctypes.c_char_p
72+
73+
result = swift_lib.getGlucoseEffectVelocityDates(json_bytes).decode('utf-8')
74+
date_list = result.split(',')[:-1]
75+
#date_list = [pd.to_datetime(date) for date in date_list]
3876

77+
return date_list
3978

4079

4180

@@ -45,11 +84,24 @@ def generate_prediction(json_file, len=82):
4584

4685

4786

87+
# THIS IS FOR TESTING, REMOVE WHEN DONE!
88+
4889
with open('python_tests/test_files/generate_prediction_input.json', 'r') as f:
4990
json_file = json.load(f)
5091

5192

5293
initialize_exception_handlers()
53-
res = generate_prediction(json_file)
94+
prediction_values = generate_prediction(json_file)
95+
print("prediction values", prediction_values)
96+
print(" ")
97+
prediction_dates = get_prediction_dates(json_file)
98+
print("prediction dates", prediction_dates)
99+
print(" ")
100+
glucose_effect_velocity = get_glucose_effect_velocity(json_file)
101+
print("glucose_effect_velocity", glucose_effect_velocity)
102+
print(" ")
103+
glucose_effect_velocity_dates = get_glucose_effect_velocity_dates(json_file)
104+
print("glucose_effect_velocity_dates", glucose_effect_velocity_dates)
105+
print(" ")
106+
54107

55-
print(res)

0 commit comments

Comments
 (0)