Skip to content

Commit 0739c44

Browse files
committed
Added build script for building dlib and running pytests on push
1 parent 1978754 commit 0739c44

2 files changed

Lines changed: 203 additions & 21 deletions

File tree

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI Workflow
2+
3+
# Trigger the workflow on push and pull request events
4+
on:
5+
push:
6+
pull_request:
7+
8+
# Define the jobs to run in the workflow
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.9' # Specify your required Python version
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
26+
27+
- name: Run build script
28+
run: |
29+
chmod +x build.sh
30+
./build.sh
31+
32+
- name: Run tests
33+
run: |
34+
pytest

README.md

Lines changed: 169 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,8 @@ This is achieved by creating a foreign function interface (FFI) in Swift by usin
88

99
## Installation
1010

11-
### TODO: Remove this and add examples with pypi / local builds instead
11+
### TODO: Add examples with pypi
1212

13-
1. Clone the repository
14-
2. Build the dynamic library:
15-
16-
```
17-
swift package clean
18-
swift build --configuration release
19-
```
20-
Check if the dynamic library got properly generated and print the path:
21-
```
22-
find .build -name "libLoopAlgorithmToPython.dylib"
23-
```
24-
Output should be something like: /release/libLoopAlgorithmToPython.dylib
25-
26-
Copy that file into your repository.
2713

2814

2915
## Repository Overview
@@ -124,22 +110,182 @@ To do:
124110
- [X] write tests with example files
125111
- [ ] create pypi package
126112
- [ ] add a build script
127-
- automatically run tests on push
128-
- automatically build new dlib on push
113+
- [ ] automatically run tests on push
114+
- [ ] automatically build new dlib on push
129115
- [X] clean up code swift
130116
- [X] clean up code python
131117
- [ ] update readme with new changes
132-
- explanation, separating between python and swift code
133-
- example usage of the api (with signal handlers), and example inputs (refer to test files)
134-
- refer to example input files
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
135121
- build, venv, run commands
136122
- pypi
137-
- running tests
123+
- [X] running tests
138124
- [ ] merge to main
139125
- [ ] next project: take a df as input, convert to json (or do it in tidepool study?)
140126

141127

142128

129+
## Python API Functions
130+
131+
-------------------------
132+
133+
### Initialize Exception Handlers
134+
135+
`initialize_exception_handlers()`
136+
137+
Initializes the exception and signal handlers in the Swift library to provide more informative error messages.
138+
139+
-------------------------
140+
141+
### Generate Prediction
142+
143+
`generate_prediction(json_file, len=72)`
144+
145+
Generates a prediction based on the provided JSON input.
146+
147+
- **Parameters**:
148+
- `json_file`: The JSON data input. See python tests and test files for example inputs.
149+
- `len` (optional): The number of prediction values to generate. Defaults to 72.
150+
- **Returns**: A list of prediction values.
151+
152+
-------------------------
153+
154+
### Get Prediction Dates
155+
156+
`get_prediction_dates(json_file)`
157+
158+
Fetches prediction dates based on the provided JSON input.
159+
160+
- **Parameters**:
161+
- `json_file`: The JSON data input. See python tests and test files for example inputs.
162+
- **Returns**: A list of prediction dates as strings.
163+
164+
-------------------------
165+
166+
### Get Prediction Values and Dates
167+
168+
`get_prediction_values_and_dates(json_file)`
169+
170+
Combines the `generate_prediction` and `get_prediction_dates` functions to return both prediction values and dates.
171+
172+
- **Parameters**:
173+
- `json_file`: The JSON data input. See python tests and test files for example inputs.
174+
- **Returns**: A tuple containing a list of prediction values and a list of prediction dates.
175+
176+
-------------------------
177+
178+
### Get Glucose Effect Velocity
179+
180+
`get_glucose_effect_velocity(json_file, len=72)`
181+
182+
Fetches the glucose effect velocity, which is equivalent to Insulin Counteraction Effect (ICE).
183+
184+
- **Parameters**:
185+
- `json_file`: The JSON data input. See python tests and test files for example inputs.
186+
- `len` (optional): The number of values to fetch. Defaults to 72.
187+
- **Returns**: A list of glucose effect velocity values.
188+
189+
-------------------------
190+
191+
### Get Glucose Effect Velocity Dates
192+
193+
`get_glucose_effect_velocity_dates(json_file)`
194+
195+
Fetches the dates associated with the glucose effect velocity.
196+
197+
- **Parameters**:
198+
- `json_file`: The JSON data input. See python tests and test files for example inputs.
199+
- **Returns**: A list of dates as strings.
200+
201+
202+
-------------------------
203+
204+
### Get Glucose Velocity Values and Dates
205+
206+
`get_glucose_velocity_values_and_dates(json_file)`
207+
208+
Combines the `get_glucose_effect_velocity` and `get_glucose_effect_velocity_dates` functions to return both glucose effect velocity values and dates.
209+
210+
- **Parameters**:
211+
- `json_file`: The JSON data input. See python tests and test files for example inputs.
212+
- **Returns**: A tuple containing a list of glucose effect velocity values and a list of dates.
213+
214+
-------------------------
215+
216+
### Get Active Carbs
217+
218+
`get_active_carbs(json_file)`
219+
220+
Fetches the active carbohydrates based on the provided JSON input.
221+
222+
- **Parameters**:
223+
- `json_file`: The JSON data input. See python tests and test files for example inputs.
224+
- **Returns**: The active carbohydrates as a double.
225+
226+
227+
-------------------------
228+
229+
### Get Active Insulin
230+
231+
`get_active_insulin(json_file)`
232+
233+
Fetches the active insulin based on the provided JSON input.
234+
235+
- **Parameters**:
236+
- `json_file`: The JSON data input. See python tests and test files for example inputs.
237+
- **Returns**: The active insulin as a double.
238+
239+
-------------------------
240+
241+
### Percent Absorption at Percent Time
242+
243+
`percent_absorption_at_percent_time(percent_time)`
244+
245+
Calculates the percentage of carbohydrate absorption at a given percent time using a piecewise linear model.
246+
247+
- **Parameters**:
248+
- `percent_time`: The time as a fraction (e.g., 0.2 for 20%).
249+
- **Returns**: The percentage of absorption as a double.
250+
251+
-------------------------
252+
253+
### Piecewise Linear Percent Rate at Percent Time
254+
255+
`piecewise_linear_percent_rate_at_percent_time(percent_time)`
256+
257+
Calculates the percentage rate of carbohydrate absorption at a given percent time using a piecewise linear model.
258+
259+
- **Parameters**:
260+
- `percent_time`: The time as a fraction (e.g., 0.2 for 20%).
261+
- **Returns**: The percentage rate of absorption as a double.
262+
263+
-------------------------
264+
265+
### Linear Percent Rate at Percent Time
266+
267+
`linear_percent_rate_at_percent_time(percent_time)`
268+
269+
Calculates the percentage rate of carbohydrate absorption at a given percent time using a linear model.
270+
271+
- **Parameters**:
272+
- `percent_time`: The time as a fraction (e.g., 0.2 for 20%).
273+
- **Returns**: The percentage rate of absorption as a double.
274+
275+
-------------------------
276+
277+
### Get Dynamic Carbs on Board
278+
279+
`get_dynamic_carbs_on_board(json_file)`
280+
Fetches the dynamic carbohydrates on board based on the provided JSON input.
281+
282+
- **Parameters**:
283+
- `json_file`: The JSON data input. See python tests and test files for example inputs.
284+
- **Returns**: The dynamic carbohydrates on board as a double.
285+
286+
-------------------------
287+
288+
143289

144290

145291
## Build Dynamic Library
@@ -150,7 +296,9 @@ After making changes in the Swift code, rebuild the dynamic library by running `
150296

151297

152298

299+
## Run Tests
153300

301+
Run command `pytest`.
154302

155303

156304

0 commit comments

Comments
 (0)