-
Notifications
You must be signed in to change notification settings - Fork 3
/
segments.py
64 lines (49 loc) · 1.92 KB
/
segments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import json
import requests
import logging
import threading
API_KEY = "<Insert Edge Impulse API Key here from the Dashboard > Keys"
projectId = "<Your project ID, can be found at Edge Impulse dashboard"
headers = {
"Accept": "application/json",
"x-api-key": API_KEY
}
def segment(tid, ids):
for sampleId in ids:
url1 = "https://studio.edgeimpulse.com/v1/api/{}/raw-data/{}/find-segments".format(projectId, sampleId)
payload1 = {
"shiftSegments": True,
"segmentLengthMs": 1500
}
response1 = requests.request("POST", url1, json=payload1, headers=headers)
resp1 = json.loads(response1.text)
segments = resp1["segments"]
if len(segments) == 0:
continue
payload2 = {"segments": segments}
url2 = "https://studio.edgeimpulse.com/v1/api/{}/raw-data/{}/segment".format(projectId, sampleId)
response2 = requests.request("POST", url2, json=payload2, headers=headers)
logging.info('{} {} {}'.format(tid, sampleId, response2.text))
if __name__ == "__main__":
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO,
datefmt="%H:%M:%S")
querystring = {"category":"testing", "excludeSensors":"true"}
url = "https://studio.edgeimpulse.com/v1/api/{}/raw-data".format(projectId)
response = requests.request("GET", url, headers=headers, params=querystring)
resp = json.loads(response.text)
id_list = list(map(lambda s: s["id"], resp["samples"]))
div = 8
n = int(len(id_list) / div)
threads = list()
for i in range(div):
if i == (div - 1):
ids = id_list[n*i: ]
else:
ids = id_list[n*i: n*(i+1)]
x = threading.Thread(target=segment, args=(i, ids))
threads.append(x)
x.start()
for thread in threads:
thread.join()
logging.info("Finished")