Commit 554f09e1 authored by Mattia Mancini's avatar Mattia Mancini
Browse files

Add callback function and handling of events

parent b1079248
......@@ -131,9 +131,45 @@ def is_line_average_spectra(line: str):
return line.startswith('MEAN-SPECTRA=')
def parse_spectra(line: str):
spectra = line.split('=')
spectra = [float(value) for value in line.split('=')[1].strip().lstrip('[').rstrip(']').split(',')]
return spectra
def parse_metadata(line: str):
"""
parses this
rcu,rcumode,obs-id,check,startfreq,stopfreq,rec-timestamp
SPECTRA-INFO=5,5,641999,SN,100,200,1520211605.115792
:param line:
:return:
"""
rcu, \
rcumode,\
obs_id, \
error, \
start_freq, \
end_freq, \
timestamp = line.split('=')[1].strip().split(',')
rcu = int(rcu)
rcumode = int(rcumode)
obs_id = int(obs_id)
start_freq = float(start_freq)
end_freq = float(end_freq)
timestamp = float(timestamp)
return dict(rcu=rcu, rcumode=rcumode, obs_id=obs_id, start_freq=start_freq, end_freq=end_freq, timestamp=timestamp)
def datapoint_change_callback(current_event: dict):
"""
TODO do your OPC magic here
:param current_event:
:return:
"""
raise NotImplementedError()
# TODO This is the function you have to modify
def handle_event(f_stream: TextIOBase):
"""
Handle the file created event sending the file to the MaintenanceDB REST API.
......@@ -147,6 +183,13 @@ def handle_event(f_stream: TextIOBase):
for line in data:
line = line.strip()
if _is_line_interesting(line):
if is_line_metadata(line):
current_event = parse_metadata(line)
if is_line_average_spectra(line):
current_event['AVERAGE'] = parse_spectra(line)
if is_line_bad_spectra(line):
# THIS is the finish of the event
current_event['SPECTRUM'] = parse_spectra(line)
datapoint_change_callback(current_event)
current_event = {}
return None
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment