-
Mattia Mancini authoredMattia Mancini authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
rtsm_test_raw_parser.py 2.38 KiB
from datetime import datetime
def split_raw_rtsm_test(content):
"""
Split the raw rtsm test in row and filters out comments and empty lines
:param content: content of rtsm output file
"""
results = filter(lambda x: not x.startswith('#'),
filter(lambda x: len(x) > 0,
map(lambda x: x.strip(),
content.split('\n')
)
))
return results
def preparse_rtsm_test_file(content):
results = []
result = dict()
observation = dict()
for line in content:
key, value = line.split('=')
if 'INFO' in key and 'OBS' not in key:
if 'rcu' in result:
results.append(result)
result = dict()
rcu, mode, observation_id, error_type, start_frequency, stop_frequency, time = value.split(',')
result.update(rcu=int(rcu),
mode=int(mode),
error_type=error_type,
start_frequency=float(start_frequency),
stop_frequency=float(stop_frequency),
time=datetime.utcfromtimestamp(float(time)))
elif 'INFO' in key:
observation_id, start_time, stop_time, samples = value.split(',')
observation.update(observation_id=observation_id,
start_time=datetime.utcfromtimestamp(float(start_time)),
end_time=datetime.utcfromtimestamp(float(stop_time)),
samples=int(samples))
elif 'BAD' in key:
values = [float(item) for item in value.lstrip('[').rstrip(']').strip().split(' ')]
result.update(bad_spectrum=values)
elif 'MEAN' in key:
values = [float(item) for item in value.lstrip('[').rstrip(']').strip().split(' ')]
result.update(average_spectrum=values)
results.append(result)
observation.update(errors=results)
return observation
def parse_rtsm_test(content):
"""
Expects a string content with the rtsm test output
and output a list of Django Models
:param content: string content with the station test output
:return: a list of Django models
"""
return [preparse_rtsm_test_file(split_raw_rtsm_test(content))]