-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata_parse_util.py
More file actions
122 lines (91 loc) · 4.2 KB
/
data_parse_util.py
File metadata and controls
122 lines (91 loc) · 4.2 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import math
import json
from environment import *
from population import *
def DummyEnv():
return ''
def DummyPop(env_graph):
pass
def generate_EnvironmentGraph(env_input):
if env_input == 'dummy':
env = DummyEnv()
populate_EnvironmentGraph('dummy', env)
return env
else:
f = open(env_input,'r', encoding='utf8')
s = f.read()
descrip = json.loads(s)
env = EnvironmentGraph()
block_template = BlockTemplate()
pop_template = descrip['population_template']
# Default values for traceable properties
if 'traceable_properties' in pop_template:
tp = pop_template['traceable_properties']
for k in tp:
block_template.add_traceable_property(k, tp[k])
# Default values for sampled properties
if 'sampled_properties' in pop_template:
sp = pop_template['sampled_properties']
for k in sp:
block_template.add_bucket(k, sp[k])
blob_factory = BlobFactory(block_template)
env.original_block_template = block_template
# Process repeating global actions
if 'repeating_global_actions' in descrip:
repeating_global_actions = descrip['repeating_global_actions']
for rga in repeating_global_actions:
if 'cycle_length' in rga:
env.set_repeating_action(int(rga['cycle_length']), TimeAction(rga['type'], rga['values']))
elif 'frames' in rga:
env.set_repeating_action(rga['frames'], TimeAction(rga['type'], rga['values']))
for region_description in descrip['regions']:
region_template = EnvRegionTemplate()
for node_k, node_value in region_description['nodes'].items():
node_template = EnvNodeTemplate()
for key, characteristic in node_value.items():
# Add characteristics to the EnvNode
if key == 'characteristics':
for a, b in characteristic.items():
node_template.add_characteristic(a, b)
elif key == 'population_groups':
for group in characteristic:
node_template.add_blob_description(group['size'],group['traceable_properties'],group['description'], blob_factory)
# Add TimeActions to the EnvNode
elif key == 'time_actions':
# Each frame contains a list of TimeActions
for frame_key, actions_list in characteristic.items():
node_actions = []
# Each TimeAction description in the actions list
for _a in actions_list:
action = TimeAction(_a['type'], _a['values'])
node_actions.append(action)
node_template.add_routine_template(frame_key, node_actions)
region_template.add_template_node(node_k, node_template)
env.add_region(region_description['world_position'], region_template, region_description['name'])
env.region_list[-1].long_lat = region_description['long_lat_position']
env.set_spawning_nodes()
return env
def populate_EnvRegion(region, blob_factory: BlobFactory, population, profiles):
home_node: EnvNode = None
for node in region.node_list:
if node.name == 'home':
home_node = node
blob = blob_factory.GenerateProfile(region.id, population, profiles)
home_node.add_blob(blob)
def populate_EnvNode(region: EnvRegionTemplate, node_template: EnvNodeTemplate, blob_factory: BlobFactory, population, profiles):
blob = blob_factory.GenerateProfile(region.id, population, profiles)
node_template.blobs.append(blob)
def populate_EnvironmentGraph(pop_input, env_graph):
if pop_input == 'dummy':
DummyPop(env_graph)
else:
pass
#process input population
def json_2_routine(input_json):
pass
def json_2_blob(input_json):
pass
def json_2_node(input_json):
pass
def json_2_region(input_json):
pass