|
1 | | -# edge-ml python |
2 | | -[](https://github.com/edge-ml/python/actions/workflows/tests.yml) |
3 | | -[](https://github.com/edge-ml/python/actions/workflows/PyPIPublish.yml) |
| 1 | +# Obtain data from edge-ml |
4 | 2 |
|
5 | | -Python package for [edge-ml.org](https://edge-ml.org). |
6 | 3 |
|
7 | | -## Usage |
8 | | -### Installation |
9 | | -Install edge-ml using the follwing command. |
10 | | -```bash |
11 | | -pip install edge-ml |
| 4 | +```python |
| 5 | +from edgeml import DatasetReceiver |
12 | 6 | ``` |
13 | 7 |
|
14 | | -### Retrieve Project |
15 | | -This functionality comes in handy if you would like to train a machine learning model from edge-ml data. |
| 8 | +### 1. Create a project |
| 9 | +This will also pull the metadata from the server. |
| 10 | +Here you need the *read*-key. |
| 11 | +Make sure there is not trailing */* in your URL. |
| 12 | + |
| 13 | + |
16 | 14 | ```python |
17 | | -from edgeml import edgeml |
| 15 | +project = DatasetReceiver("https://edge-ml-beta.dmz.teco.edu", "8c051972b56e6b4ad6bd0bf573da580f") |
| 16 | +print(project) |
| 17 | +``` |
| 18 | + |
| 19 | + Dataset - Name: W_001, ID: 645a255bdd19d537f2a50126, Metadata: {} |
| 20 | + Dataset - Name: W_004, ID: 645a255b7d9569d03843a12b, Metadata: {} |
| 21 | + Dataset - Name: Square_003, ID: 645a255b2ce253c26b52426c, Metadata: {} |
| 22 | + Dataset - Name: Square_004, ID: 645a255b1d6af5e7ed04575f, Metadata: {} |
| 23 | + Dataset - Name: Square_002, ID: 645a255bc21261d4cbdc990d, Metadata: {} |
| 24 | + Dataset - Name: W_002, ID: 645a255b3ebe0af02b211d5d, Metadata: {} |
| 25 | + Dataset - Name: W_003, ID: 645a255b074737af782167e2, Metadata: {} |
| 26 | + Dataset - Name: Square_001, ID: 645a255bbacf5ab8ff044304, Metadata: {} |
| 27 | + Dataset - Name: edgemlDemo, ID: 64635a79a7a7513e8ac92d32, Metadata: {'langauge': 'python'} |
| 28 | + Dataset - Name: edgemlDemo, ID: 64635a7b6fec1d2800b1cd06, Metadata: {'langauge': 'python'} |
| 29 | + |
| 30 | + |
| 31 | +### 2. Actually obtain data |
| 32 | +Until now, we only have metadata available. We need to pull the actual time-series data using one of the following methods: |
| 33 | + |
| 34 | +*We can load the data for a single timeSeries* |
| 35 | + |
| 36 | + |
| 37 | +```python |
| 38 | + |
| 39 | +project.datasets[0].timeSeries[0].loadData() |
| 40 | +project.datasets[0].timeSeries[0].data.head() |
18 | 41 |
|
19 | | -# get the API key from the settings of your project |
20 | | -project = edgeml.getProject("https://app.edge-ml.org", PROJECT_API_KEY) |
21 | 42 | ``` |
22 | 43 |
|
23 | | -### Push Data from Python |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +<div> |
| 48 | +<style scoped> |
| 49 | + .dataframe tbody tr th:only-of-type { |
| 50 | + vertical-align: middle; |
| 51 | + } |
| 52 | + |
| 53 | + .dataframe tbody tr th { |
| 54 | + vertical-align: top; |
| 55 | + } |
| 56 | + |
| 57 | + .dataframe thead th { |
| 58 | + text-align: right; |
| 59 | + } |
| 60 | +</style> |
| 61 | +<table class="dataframe"> |
| 62 | + <thead> |
| 63 | + <tr style="text-align: right;"> |
| 64 | + <th></th> |
| 65 | + <th>time</th> |
| 66 | + <th>x</th> |
| 67 | + </tr> |
| 68 | + </thead> |
| 69 | + <tbody> |
| 70 | + <tr> |
| 71 | + <th>0</th> |
| 72 | + <td>1970-01-01 00:10:23.339</td> |
| 73 | + <td>-823.0</td> |
| 74 | + </tr> |
| 75 | + <tr> |
| 76 | + <th>1</th> |
| 77 | + <td>1970-01-01 00:10:23.378</td> |
| 78 | + <td>-819.0</td> |
| 79 | + </tr> |
| 80 | + <tr> |
| 81 | + <th>2</th> |
| 82 | + <td>1970-01-01 00:10:23.418</td> |
| 83 | + <td>-770.0</td> |
| 84 | + </tr> |
| 85 | + <tr> |
| 86 | + <th>3</th> |
| 87 | + <td>1970-01-01 00:10:23.458</td> |
| 88 | + <td>-746.0</td> |
| 89 | + </tr> |
| 90 | + <tr> |
| 91 | + <th>4</th> |
| 92 | + <td>1970-01-01 00:10:23.497</td> |
| 93 | + <td>-783.0</td> |
| 94 | + </tr> |
| 95 | + </tbody> |
| 96 | +</table> |
| 97 | +</div> |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +*For a single dataset* |
| 102 | + |
| 103 | + |
| 104 | +```python |
| 105 | +project.datasets[0].loadData() |
| 106 | +project.datasets[0].data.head() |
| 107 | +``` |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +<div> |
| 113 | +<style scoped> |
| 114 | + .dataframe tbody tr th:only-of-type { |
| 115 | + vertical-align: middle; |
| 116 | + } |
| 117 | + |
| 118 | + .dataframe tbody tr th { |
| 119 | + vertical-align: top; |
| 120 | + } |
| 121 | + |
| 122 | + .dataframe thead th { |
| 123 | + text-align: right; |
| 124 | + } |
| 125 | +</style> |
| 126 | +<table class="dataframe"> |
| 127 | + <thead> |
| 128 | + <tr style="text-align: right;"> |
| 129 | + <th></th> |
| 130 | + <th>time</th> |
| 131 | + <th>x</th> |
| 132 | + <th>y</th> |
| 133 | + <th>z</th> |
| 134 | + <th>Gestures</th> |
| 135 | + </tr> |
| 136 | + </thead> |
| 137 | + <tbody> |
| 138 | + <tr> |
| 139 | + <th>0</th> |
| 140 | + <td>1970-01-01 00:10:23.339</td> |
| 141 | + <td>-823.0</td> |
| 142 | + <td>-45.0</td> |
| 143 | + <td>4025.0</td> |
| 144 | + <td></td> |
| 145 | + </tr> |
| 146 | + <tr> |
| 147 | + <th>1</th> |
| 148 | + <td>1970-01-01 00:10:23.378</td> |
| 149 | + <td>-819.0</td> |
| 150 | + <td>-158.0</td> |
| 151 | + <td>4075.0</td> |
| 152 | + <td></td> |
| 153 | + </tr> |
| 154 | + <tr> |
| 155 | + <th>2</th> |
| 156 | + <td>1970-01-01 00:10:23.418</td> |
| 157 | + <td>-770.0</td> |
| 158 | + <td>-255.0</td> |
| 159 | + <td>4116.0</td> |
| 160 | + <td></td> |
| 161 | + </tr> |
| 162 | + <tr> |
| 163 | + <th>3</th> |
| 164 | + <td>1970-01-01 00:10:23.458</td> |
| 165 | + <td>-746.0</td> |
| 166 | + <td>-155.0</td> |
| 167 | + <td>4059.0</td> |
| 168 | + <td></td> |
| 169 | + </tr> |
| 170 | + <tr> |
| 171 | + <th>4</th> |
| 172 | + <td>1970-01-01 00:10:23.497</td> |
| 173 | + <td>-783.0</td> |
| 174 | + <td>-104.0</td> |
| 175 | + <td>3963.0</td> |
| 176 | + <td></td> |
| 177 | + </tr> |
| 178 | + </tbody> |
| 179 | +</table> |
| 180 | +</div> |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | +*Or for all datasets in the project* |
| 185 | + |
| 186 | + |
| 187 | +```python |
| 188 | +project.loadData() |
| 189 | +project.data[0].head() |
| 190 | +``` |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | +<div> |
| 196 | +<style scoped> |
| 197 | + .dataframe tbody tr th:only-of-type { |
| 198 | + vertical-align: middle; |
| 199 | + } |
| 200 | + |
| 201 | + .dataframe tbody tr th { |
| 202 | + vertical-align: top; |
| 203 | + } |
| 204 | + |
| 205 | + .dataframe thead th { |
| 206 | + text-align: right; |
| 207 | + } |
| 208 | +</style> |
| 209 | +<table class="dataframe"> |
| 210 | + <thead> |
| 211 | + <tr style="text-align: right;"> |
| 212 | + <th></th> |
| 213 | + <th>time</th> |
| 214 | + <th>x</th> |
| 215 | + <th>y</th> |
| 216 | + <th>z</th> |
| 217 | + <th>Gestures</th> |
| 218 | + </tr> |
| 219 | + </thead> |
| 220 | + <tbody> |
| 221 | + <tr> |
| 222 | + <th>0</th> |
| 223 | + <td>1970-01-01 00:10:23.339</td> |
| 224 | + <td>-823.0</td> |
| 225 | + <td>-45.0</td> |
| 226 | + <td>4025.0</td> |
| 227 | + <td></td> |
| 228 | + </tr> |
| 229 | + <tr> |
| 230 | + <th>1</th> |
| 231 | + <td>1970-01-01 00:10:23.378</td> |
| 232 | + <td>-819.0</td> |
| 233 | + <td>-158.0</td> |
| 234 | + <td>4075.0</td> |
| 235 | + <td></td> |
| 236 | + </tr> |
| 237 | + <tr> |
| 238 | + <th>2</th> |
| 239 | + <td>1970-01-01 00:10:23.418</td> |
| 240 | + <td>-770.0</td> |
| 241 | + <td>-255.0</td> |
| 242 | + <td>4116.0</td> |
| 243 | + <td></td> |
| 244 | + </tr> |
| 245 | + <tr> |
| 246 | + <th>3</th> |
| 247 | + <td>1970-01-01 00:10:23.458</td> |
| 248 | + <td>-746.0</td> |
| 249 | + <td>-155.0</td> |
| 250 | + <td>4059.0</td> |
| 251 | + <td></td> |
| 252 | + </tr> |
| 253 | + <tr> |
| 254 | + <th>4</th> |
| 255 | + <td>1970-01-01 00:10:23.497</td> |
| 256 | + <td>-783.0</td> |
| 257 | + <td>-104.0</td> |
| 258 | + <td>3963.0</td> |
| 259 | + <td></td> |
| 260 | + </tr> |
| 261 | + </tbody> |
| 262 | +</table> |
| 263 | +</div> |
| 264 | + |
| 265 | + |
| 266 | + |
| 267 | +# Upload data to edge-ml |
| 268 | + |
| 269 | +### 1. Upload data using timestamps from the device |
| 270 | +Here you will need the *write*-key |
| 271 | + |
| 272 | + |
| 273 | +```python |
| 274 | +from edgeml.edgeml import DatasetCollector |
| 275 | +sender = DatasetCollector(url="https://edge-ml-beta.dmz.teco.edu", apiKey="4e6159c9c77124d71f298e93f1ed7254", name="edgemlDemo", useDeviceTime=True, timeSeries=["accX", "accY"], metaData={"langauge": "python"}) |
| 276 | + |
| 277 | +``` |
| 278 | + |
| 279 | + |
24 | 280 | ```python |
25 | | -from edgeml import edgeml |
26 | 281 | import time |
27 | 282 |
|
28 | | -key = "YOUR_API_KEY" |
29 | | -startTime = time.time() |
30 | | -collector = edgeml.datasetCollector("https://app.edge-ml.org", |
31 | | - key, |
32 | | - "Example Dataset", # name the dataset you would like to upload |
33 | | - False) # do not use server timestamps |
| 283 | +for i in range (100): |
| 284 | + await sender.addDataPoint(name="accX", value=i*0.1) |
| 285 | + await sender.addDataPoint(name="accY", value=i*0.5) |
| 286 | + time.sleep(0.01) |
| 287 | +sender.onComplete() |
| 288 | +``` |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + True |
| 294 | + |
34 | 295 |
|
35 | | -for i in range(500): |
36 | | - current_time = startTime + i * 10 # adding samples at 10 ms time steps |
37 | | - collector.addDataPoint("Accelerometer X", random.randint(1,50) / 10.0, current_time) |
38 | | - collector.addDataPoint("Accelerometer Y", random.randint(1,50) / 10.0, current_time) |
39 | | - collector.addDataPoint("Accelerometer Z", random.randint(1,50) / 10.0, current_time) |
40 | 296 |
|
41 | | -collector.onComplete() |
| 297 | +### 2. Provide your own timestamps |
| 298 | + |
| 299 | + |
| 300 | +```python |
| 301 | +from edgeml.edgeml import DatasetCollector |
| 302 | +sender = DatasetCollector(url="https://edge-ml-beta.dmz.teco.edu", apiKey="4e6159c9c77124d71f298e93f1ed7254", name="edgemlDemo", useDeviceTime=False, timeSeries=["accX", "accY"], metaData={"langauge": "python"}) |
| 303 | + |
42 | 304 | ``` |
43 | 305 |
|
44 | | -## Development |
45 | | -### Testing |
46 | | -To run the tests please enter: |
47 | 306 |
|
48 | | -```bash |
49 | | -python -m unittest -v tests/all.py |
| 307 | +```python |
| 308 | +import time |
| 309 | + |
| 310 | +for i in range (100): |
| 311 | + await sender.addDataPoint(timestamp=i*1000, name="accX", value=i*0.1) |
| 312 | + await sender.addDataPoint(timestamp=i*1000, name="accY", value=i*0.5) |
| 313 | + time.sleep(0.01) |
| 314 | +sender.onComplete() |
50 | 315 | ``` |
| 316 | + |
| 317 | + |
| 318 | + |
| 319 | + |
| 320 | + True |
| 321 | + |
| 322 | + |
0 commit comments