Skip to content

Commit 7fed4a7

Browse files
committed
Updated readme
1 parent 65ee7bb commit 7fed4a7

7 files changed

Lines changed: 43 additions & 10 deletions

File tree

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
This Swift module uses LoopAlgorithm to create C functions for generating predictions and prediction dates from JSON data.
44

5-
How?
6-
I create a foreign function interface (FFI) in Swift by using the unofficial @_cdecl Swift function. This interfaces the Swift code with C. Then we can create a dynamic library, import it into a Python (or other) repositories, and use for example ctypes to compile the C code.
5+
This is achieved by creating a foreign function interface (FFI) in Swift by using the unofficial @_cdecl Swift function. This interfaces the Swift code with C. Then we can create a dynamic library, import it into a Python (or other) repositories, and use for example ctypes to compile the C code.
6+
77

88

99
## Installation
1010

11+
### TODO: Remove this and add examples with pypi / local builds instead
12+
1113
1. Clone the repository
1214
2. Build the dynamic library:
1315

@@ -24,14 +26,26 @@ Output should be something like: /release/libLoopAlgorithmToPython.dylib
2426
Copy that file into your repository.
2527

2628

27-
## Exposed functions
29+
## Repository Overview
30+
31+
### Exposed functions
2832

2933
You can find the C-exposed functions in the file `LoopAlgorithmToPython.swift`.
3034

35+
### Python API
36+
37+
Python API functions are located in `loop_to_python_api/api.py`.
38+
39+
### Tests and test data
40+
41+
`python_tests/` contains examples of executing all the functions as well as example files providing templates on how to structure the input files.
3142

3243

3344
## Usage in Python
3445

46+
### TODO: Remove this and add examples for pypi usage instead
47+
48+
3549
Here's how you can use the dynamic library (`libLoopAlgorithmToPython.dylib`) in Python to call the exposed functions:
3650

3751
```
@@ -106,17 +120,17 @@ To do:
106120
- [X] add the dlib build script
107121
- build to python folder
108122
- add readme
109-
- [ ] write python functions api
123+
- [X] write python functions api
110124
- [ ] write tests with example files
111125
- [ ] create pypi package
112126
- [ ] add a build script
113127
- automatically run tests on push
114128
- automatically build new dlib on push
115-
- [ ] clean up code swift
129+
- [X] clean up code swift
116130
- [ ] clean up code python
117131
- [ ] update readme with new changes
118132
- explanation, separating between python and swift code
119-
- example usage of the api (with signal handlers)
133+
- example usage of the api (with signal handlers), and example inputs (refer to test files)
120134
- refer to example input files
121135
- build, venv, run commands
122136
- pypi
@@ -138,3 +152,6 @@ After making changes in the Swift code, rebuild the dynamic library by running `
138152

139153

140154

155+
156+
157+

python_tests/__init__.py

Whitespace-only changes.

python_tests/python_tests.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

python_tests/tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
import json
3+
from loop_to_python_api.api import generate_prediction
4+
5+
6+
@pytest.fixture
7+
def generate_prediction_input():
8+
with open('python_tests/test_files/generate_prediction_input.json', 'r') as f:
9+
return json.load(f)
10+
11+
12+
def test_generate_prediction():
13+
prediction_input = generate_prediction_input()
14+
prediction_values = generate_prediction(prediction_input)
15+
print(prediction_values)
16+
assert prediction_values == []
17+
18+
19+
20+

0 commit comments

Comments
 (0)