@@ -27,103 +27,6 @@ Python API functions are located in `loop_to_python_api/api.py`.
2727` python_tests/ ` contains examples of executing all the functions as well as example files providing templates on how to structure the input files.
2828
2929
30- ## Usage in Python
31-
32- ### TODO: Remove this and add examples for pypi usage instead
33-
34-
35- Here's how you can use the dynamic library (` libLoopAlgorithmToPython.dylib ` ) in Python to call the exposed functions:
36-
37- ```
38- import ctypes
39- import json
40-
41- json_file_path = 'some_file.json'
42-
43- # Load the shared library
44- swift_lib = ctypes.CDLL('./libLoopAlgorithmToPython.dylib')
45-
46- # Specify the argument types and return type of the Swift function
47- swift_lib.generatePrediction.argtypes = [ctypes.c_char_p]
48- swift_lib.generatePrediction.restype = ctypes.POINTER(ctypes.c_double)
49-
50- swift_lib.getPredictionDates.argtypes = [ctypes.c_char_p]
51- swift_lib.getPredictionDates.restype = ctypes.c_char_p
52-
53- swift_lib.getActiveCarbs.argtypes = [ctypes.c_char_p]
54- swift_lib.getActiveCarbs.restype = ctypes.c_double
55-
56- swift_lib.getActiveInsulin.argtypes = [ctypes.c_char_p]
57- swift_lib.getActiveInsulin.restype = ctypes.c_double
58-
59- # Read JSON file
60- def read_json_file(file_path):
61- with open(file_path, 'r') as f:
62- data = json.load(f)
63- return data
64-
65- json_data = read_json_file(json_file_path) # Read JSON file
66- json_str = json.dumps(json_data) # Convert JSON data to JSON string
67- json_bytes = json_str.encode('utf-8') # Convert JSON string to bytes
68-
69- # Prepare a variable to receive the length of the predicted values
70- length = 82
71-
72- # Call the Swift functions
73- result_prediction_values = swift_lib.generatePrediction(json_bytes)
74- result_prediction_dates = swift_lib.getPredictionDates(json_bytes).decode('utf-8')
75- result_active_carbs = swift_lib.getActiveCarbs(json_bytes)
76- result_active_insulin = swift_lib.getActiveInsulin(json_bytes)
77-
78- # Read the generated predictions
79- array = [result_prediction_values[i] for i in range(length)]
80- print(array[0])
81- print(f"The result from generatePrediction is: {array}")
82-
83- # Read the dates
84- date_list = result.split(',')[:-1]
85- print(f"The result from getPredictionDates is: {date_list}")
86-
87- # Read the active carbohydrates
88- print(f"The result from getActiveCarbs is: {result_active_carbs}")
89-
90- # Read the active insulin
91- print(f"The result from getActiveInsulin is: {result_active_insulin}")
92- ```
93-
94- Adjust the paths, function names, and details as per your specific project setup and requirements.
95-
96-
97-
98-
99-
100-
101-
102-
103- To do:
104- - [X] add a python folder
105- - [X] add a test folder
106- - [X] add the dlib build script
107- - build to python folder
108- - add readme
109- - [X] write python functions api
110- - [X] write tests with example files
111- - [ ] create pypi package
112- - [ ] add a build script
113- - [ ] automatically run tests on push
114- - [ ] automatically build new dlib on push
115- - [X] clean up code swift
116- - [X] clean up code python
117- - [ ] update readme with new changes
118- - [X] explanation, separating between python and swift code
119- - [X] example usage of the api (with signal handlers), and example inputs (refer to test files)
120- - [X] refer to example input files
121- - build, venv, run commands
122- - pypi
123- - [X] running tests
124- - [ ] merge to main
125- - [ ] next project: take a df as input, convert to json (or do it in tidepool study?)
126-
12730
12831
12932## Python API Functions
0 commit comments