-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontextAware.py
More file actions
55 lines (43 loc) · 1.47 KB
/
contextAware.py
File metadata and controls
55 lines (43 loc) · 1.47 KB
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
import copy
def inject_location_context(td: dict, context:dict) -> dict:
td["nearby"] = context
return td
def convert_td(td:dict, context:list, contextIndex) -> list:
td = copy.deepcopy(td)
if "actions" in td:
for action in td["actions"]:
if "forms" in action:
del action["forms"]
if "events" in td:
for event in td["events"]:
if "forms" in event:
del event["forms"]
if "properties" in td:
for prop in td["properties"]:
if "forms" in prop:
del prop["forms"]
tds = []
j = 0
for i in context:
contextTD = copy.deepcopy(td)
contextTD["id"] = contextTD["id"] + "_" + str(j)
contextTD = inject_location_context(contextTD, i)
tds.append(contextTD)
j += 1
return tds
def convert_tds(tds:list, context:dict) -> list:
tds_2 = []
for td in tds:
if td["id"] not in context:
tds_2.append(td)
continue
c = context[td["id"]]["context"]
tds_2 += convert_td(td, c, context[td["id"]]["index"])
return tds_2
def convert_flow(flow: list[dict], context: dict):
flow = copy.deepcopy(flow)
for node in flow:
if node["type"] in ["system-property-node", "system-action-node", "system-event-node"]:
if node["thingID"] in context:
node["thingID"] = node["thingID"] + "_" + str(context[node["thingID"]]["index"])
return flow