Created
July 29, 2016 16:18
-
-
Save cdellin/9cdb1c1c36851b438654384d284099f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def yaml_fast_load(fp): | |
collision_dict = {} | |
planner = None | |
planner_dict = None | |
number = None | |
number_dict = None | |
dofvals = None | |
text_other = '' | |
in_collision = False | |
for iline,line in enumerate(fp): | |
if not in_collision: | |
if line.strip() == 'collision_log:': | |
in_collision = True | |
else: | |
text_other += line | |
continue | |
if ':' not in line: | |
v = line.strip() | |
dofvals.extend(map(float,v[:-1].split(', '))) | |
if v[-1] == ']': | |
number_dict['dofvals'] = dofvals | |
dofvals = None | |
continue | |
k,v = line.strip().split(':') | |
v = v.strip() | |
if k == 'collision_log': | |
pass | |
elif k in ['OMPL_RRTConnect','cbirrt']: | |
if planner_dict is not None: | |
collision_dict[planner] = planner_dict | |
planner = k | |
planner_dict = {} | |
elif k[0] == "'" and k[-1] == "'": | |
if number_dict is not None: | |
planner_dict[number] = number_dict | |
number = k[1:-1] | |
number_dict = {} | |
elif k in ['body','link','methodname','link1','link2']: | |
number_dict[k] = v | |
elif k == 'result': | |
if v == 'true': | |
number_dict[k] = True | |
elif v == 'false': | |
number_dict[k] = False | |
else: | |
raise ValueError('unknown bool') | |
elif k == 'bodies_excluded': | |
if v[0] == '[' and v[-1] == ']' and ',' not in v: | |
number_dict[k] = [v[1:-1]] | |
else: | |
print(v) | |
raise ValueError('unknown bodies_excluded') | |
elif k == 'links_excluded': | |
if v == '[]': | |
number_dict[k] = [] | |
else: | |
raise ValueError('unknown links_excluded') | |
elif k == 'dofvals': | |
dofvals = [] | |
if v != '[]': | |
dofvals.extend(map(float,v[1:-1].split(', '))) | |
if v[-1] == ']': | |
number_dict['dofvals'] = dofvals | |
dofvals = None | |
elif k == 'ok': | |
pass | |
elif k == 'environment': | |
if number_dict is not None: | |
planner_dict[number] = number_dict | |
number = None | |
number_dict = None | |
if planner_dict is not None: | |
collision_dict[planner] = planner_dict | |
planner = None | |
planner_dict = None | |
text_other += line | |
in_collision = False | |
else: | |
raise RuntimeError('unknown line: {}'.format(line.rstrip())) | |
yamldict = yaml.safe_load(text_other) | |
yamldict['collision_log'] = collision_dict | |
return yamldict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment