Skip to content

Commit 1978754

Browse files
committed
Added combined values and dates functions
1 parent c79fd6c commit 1978754

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ To do:
121121
- build to python folder
122122
- add readme
123123
- [X] write python functions api
124-
- [ ] write tests with example files
124+
- [X] write tests with example files
125125
- [ ] create pypi package
126126
- [ ] add a build script
127127
- automatically run tests on push
128128
- automatically build new dlib on push
129129
- [X] clean up code swift
130-
- [ ] clean up code python
130+
- [X] clean up code python
131131
- [ ] update readme with new changes
132132
- explanation, separating between python and swift code
133133
- example usage of the api (with signal handlers), and example inputs (refer to test files)

loop_to_python_api/api.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from loop_to_python_api.helpers import get_bytes_from_json
66

77
import ctypes
8-
import json
98
import os
109

1110

@@ -53,7 +52,10 @@ def get_prediction_dates(json_file):
5352
return date_list
5453

5554

56-
# TODO: Add combined predictions and dates, with assertequals to check whether they are of same length
55+
def get_prediction_values_and_dates(json_file):
56+
dates = get_prediction_dates(json_file)
57+
values = generate_prediction(json_file, len(dates))
58+
return values, dates
5759

5860

5961
# "Glucose effect velocity" is equivalent to insulin counteraction effect (ICE)
@@ -80,6 +82,14 @@ def get_glucose_effect_velocity_dates(json_file):
8082
return date_list
8183

8284

85+
def get_glucose_velocity_values_and_dates(json_file):
86+
# TODO: Add validation of json dates here to be more flexible?
87+
88+
dates = get_glucose_effect_velocity_dates(json_file)
89+
values = get_glucose_effect_velocity(json_file, len(dates))
90+
return values, dates
91+
92+
8393
def get_active_carbs(json_file):
8494
json_bytes = get_bytes_from_json(json_file)
8595

python_tests/tests.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
initialize_exception_handlers,
55
generate_prediction,
66
get_prediction_dates,
7+
get_prediction_values_and_dates,
78
get_glucose_effect_velocity,
89
get_glucose_effect_velocity_dates,
10+
get_glucose_velocity_values_and_dates,
911
get_active_carbs,
1012
get_active_insulin,
1113
percent_absorption_at_percent_time,
@@ -47,6 +49,17 @@ def test_get_prediction_dates():
4749
assert isinstance(prediction_dates, list) # Replace with the expected type or value
4850

4951

52+
def test_get_prediction_values_and_dates():
53+
prediction_input = get_generate_prediction_input()
54+
values, dates = get_prediction_values_and_dates(prediction_input)
55+
56+
# Assertions to check the types
57+
assert isinstance(values, list), "The prediction values should be a list."
58+
assert isinstance(dates, list), "The prediction dates should be a list."
59+
assert all(isinstance(value, (int, float)) for value in values), "All prediction values should be integers or floats."
60+
assert all(isinstance(date, str) for date in dates), "All prediction dates should be strings."
61+
62+
5063
def test_get_glucose_effect_velocity():
5164
prediction_input = get_generate_prediction_input()
5265
glucose_effect_velocity = get_glucose_effect_velocity(prediction_input)
@@ -59,6 +72,17 @@ def test_get_glucose_effect_velocity_dates():
5972
assert isinstance(glucose_effect_velocity_dates, list) # Replace with the expected type or value
6073

6174

75+
def test_get_glucose_effect_velocity_values_and_dates():
76+
prediction_input = get_generate_prediction_input()
77+
values, dates = get_glucose_velocity_values_and_dates(prediction_input)
78+
79+
# Assertions to check the types
80+
assert isinstance(values, list), "The prediction values should be a list."
81+
assert isinstance(dates, list), "The prediction dates should be a list."
82+
assert all(isinstance(value, (int, float)) for value in values), "All prediction values should be integers or floats."
83+
assert all(isinstance(date, str) for date in dates), "All prediction dates should be strings."
84+
85+
6286
def test_get_active_carbs():
6387
loop_algorithm_input = get_loop_aglgorithm_input()
6488
active_carbs = get_active_carbs(loop_algorithm_input)

0 commit comments

Comments
 (0)