@@ -86,28 +86,96 @@ def get_active_carbs(json_file):
8686 return swift_lib .getActiveCarbs (json_bytes )
8787
8888
89+ def get_active_insulin (json_file ):
90+ json_bytes = get_bytes_from_json (json_file )
91+
92+ swift_lib .getActiveInsulin .argtypes = [ctypes .c_char_p ]
93+ swift_lib .getActiveInsulin .restype = ctypes .c_double
94+
95+ return swift_lib .getActiveInsulin (json_bytes )
96+
97+
98+ # Calculating the percentage of carbohydrate absorption at the percent time, with piecewise linear model
99+ # Input is percent as fraction
100+ def percent_absorption_at_percent_time (percent_time ):
101+ swift_lib .percentAbsorptionAtPercentTime .argtypes = [ctypes .c_double ]
102+ swift_lib .percentAbsorptionAtPercentTime .restype = ctypes .c_double
103+
104+ return swift_lib .percentAbsorptionAtPercentTime (percent_time )
105+
106+
107+ # Calculating the percentage rate of carbohydrate absorption at the percent time, with piecewise linear model
108+ # Input is percent as fraction
109+ def piecewise_linear_percent_rate_at_percent_time (percent_time ):
110+ swift_lib .percentRateAtPercentTime .argtypes = [ctypes .c_double ]
111+ swift_lib .percentRateAtPercentTime .restype = ctypes .c_double
112+
113+ return swift_lib .percentRateAtPercentTime (percent_time )
114+
115+
116+ # Input is percent as fraction
117+ def linear_percent_rate_at_percent_time (percent_time ):
118+ swift_lib .linearPercentRateAtPercentTime .argtypes = [ctypes .c_double ]
119+ swift_lib .linearPercentRateAtPercentTime .restype = ctypes .c_double
120+
121+ return swift_lib .linearPercentRateAtPercentTime (percent_time )
122+
123+
124+ def get_dynamic_carbs_on_board (json_file ):
125+ json_bytes = get_bytes_from_json (json_file )
126+
127+ swift_lib .getDynamicCarbsOnBoard .argtypes = [ctypes .c_char_p ]
128+ swift_lib .getDynamicCarbsOnBoard .restype = ctypes .c_double
129+
130+ return swift_lib .getDynamicCarbsOnBoard (json_bytes )
131+
132+
89133
90134
91135# THIS IS FOR TESTING, REMOVE WHEN DONE!
92136
93137with open ('python_tests/test_files/generate_prediction_input.json' , 'r' ) as f :
94- json_file = json .load (f )
138+ prediction_input = json .load (f )
139+
140+
141+ with open ('python_tests/test_files/loop_algorithm_input.json' , 'r' ) as f :
142+ loop_algorithm_input = json .load (f )
143+
144+
145+ with open ('python_tests/test_files/dynamic_carbs_input.json' , 'r' ) as f :
146+ dynamic_carbs_input = json .load (f )
95147
96148
97149initialize_exception_handlers ()
98- prediction_values = generate_prediction (json_file )
150+ prediction_values = generate_prediction (prediction_input )
99151print ("prediction values" , prediction_values )
100152print (" " )
101- prediction_dates = get_prediction_dates (json_file )
153+ prediction_dates = get_prediction_dates (prediction_input )
102154print ("prediction dates" , prediction_dates )
103155print (" " )
104- glucose_effect_velocity = get_glucose_effect_velocity (json_file )
156+ glucose_effect_velocity = get_glucose_effect_velocity (prediction_input )
105157print ("glucose_effect_velocity" , glucose_effect_velocity )
106158print (" " )
107- glucose_effect_velocity_dates = get_glucose_effect_velocity_dates (json_file )
159+ glucose_effect_velocity_dates = get_glucose_effect_velocity_dates (prediction_input )
108160print ("glucose_effect_velocity_dates" , glucose_effect_velocity_dates )
109161print (" " )
110- active_carbs = get_active_carbs (json_file )
162+ active_carbs = get_active_carbs (loop_algorithm_input )
111163print ("active_carbs" , active_carbs )
112164print (" " )
165+ active_insulin = get_active_insulin (loop_algorithm_input )
166+ print ("active_insulin" , active_insulin )
167+ print (" " )
168+ percent_absorption_at_percent_time = percent_absorption_at_percent_time (0.2 )
169+ print ("percent_absorption_at_percent_time" , percent_absorption_at_percent_time )
170+ print (" " )
171+ piecewise_linear_percent_rate_at_percent_time = piecewise_linear_percent_rate_at_percent_time (0.2 )
172+ print ("piecewise_linear_percent_rate_at_percent_time" , piecewise_linear_percent_rate_at_percent_time )
173+ print (" " )
174+ linear_percent_rate_at_percent_time = linear_percent_rate_at_percent_time (0.2 )
175+ print ("linear_percent_rate_at_percent_time" , linear_percent_rate_at_percent_time )
176+ print (" " )
177+ dynamic_carbs_on_board = get_dynamic_carbs_on_board (dynamic_carbs_input )
178+ print ("dynamic_carbs_on_board" , dynamic_carbs_on_board )
179+ print (" " )
180+
113181
0 commit comments