Skip to content
Snippets Groups Projects
Commit 1638edc1 authored by Hal Simpson's avatar Hal Simpson
Browse files

Added update_realitime flag to init. run_as_update is completed up to finding...

Added update_realitime flag to init.  run_as_update is completed up to finding gaps, and backing up to find 'All' new data.  Still need to call the algorithm,  and write out the data that's 'new'
parent 5d212963
No related branches found
No related tags found
No related merge requests found
"""Controller class for geomag algorithms""" """Controller class for geomag algorithms"""
import TimeseriesUtilities import TimeseriesUtilities as TUtils
import numpy
import obspy
class Controller(object): class Controller(object):
...@@ -15,11 +17,14 @@ class Controller(object): ...@@ -15,11 +17,14 @@ class Controller(object):
algorithm: the algorithm(s) that will take procees the timeseries data algorithm: the algorithm(s) that will take procees the timeseries data
""" """
def __init__(self, inputFactory, outputFactory, algorithm, update=False): def __init__(self, inputFactory, outputFactory, algorithm, update=False,
interval='minute', update_realtime=False):
self._inputFactory = inputFactory self._inputFactory = inputFactory
self._algorithm = algorithm self._algorithm = algorithm
self._outputFactory = outputFactory self._outputFactory = outputFactory
self._update = update self._update = update
self._interval = interval
self._update_realtime = update_realtime
def run(self, starttime, endtime): def run(self, starttime, endtime):
"""run an algorithm as setup up by the main script. """run an algorithm as setup up by the main script.
...@@ -39,24 +44,60 @@ class Controller(object): ...@@ -39,24 +44,60 @@ class Controller(object):
def run_as_update(self, starttime, endtime): def run_as_update(self, starttime, endtime):
input_channels = self._algorithm.get_input_channels() input_channels = self._algorithm.get_input_channels()
output_channels = self._algorithm.get_output_channels() output_channels = self._algorithm.get_output_channels()
seconds_of_interval = TUtils.get_seconds_of_interval(self._interval)
backup_start = starttime
backup_end = endtime
backup = self._update_realtime
timeseries_in = self._inputFactory.get_timeseries(starttime, # get new input_channel data, and last output data.
timeseries_in = self._inputFactory.get_timeseries(backup_start,
endtime, channels=input_channels) endtime, channels=input_channels)
timeseries_out = self._inputFactory.get_timeseries(starttime, timeseries_update = self._outputFactory.get_timeseries(backup_start,
endtime, channels=output_channels) endtime, channels=output_channels)
# repeat until ouput is succesfully backfilled.
#TODO get input gaps while backup:
first_in_exists = self._first_value_exists(timeseries_in,
output_gaps = TimeseriesUtilities.get_timeseries_gaps( input_channels)
timeseries_out, output_channels, starttime, endtime) first_out_exists = self._first_value_exists(timeseries_update,
output_channels)
output_merged_gaps = TimeseriesUtilities.get_merged_gaps(output_gaps, if first_in_exists and not first_out_exists:
output_channels) new_backup_end = backup_start - seconds_of_interval
# TODO compare gaps. backup_start = backup_start - (backup_end - backup_start)
# if there is new data, run algorithm over entire time. backup_end = new_backup_end
# save any new data. timeseries_in += self._inputFactory.get_timeseries(
backup_start, backup_end, channels=input_channels)
#TODO iterate is starttime of gaps is starttime and new data found timeseries_update += self._outputFactory.get_timeseries(
backup_start, backup_end, channels=output_channels)
timeseries_in.merge()
timeseries_update.merge()
else:
backup = False
print backup_start, backup_end
starttime = backup_start
input_gaps = TUtils.get_timeseries_gaps(
timeseries_in, input_channels, starttime, endtime)
output_gaps = TUtils.get_timeseries_gaps(
timeseries_update, output_channels, starttime, endtime)
input_merged_gaps = TUtils.get_merged_gaps(
input_gaps, input_channels)
output_merged_gaps = TUtils.get_merged_gaps(
output_gaps, output_channels)
if TUtils.is_new_data(input_merged_gaps, output_merged_gaps):
pass
# TODO call algorithm
# TODO call output
def _first_value_exists(self, timeseries, channels):
for channel in channels:
stream = timeseries.select(channel=channel)
if len(stream[0].data) and not numpy.isnan(stream[0].data[0]):
return True
return False
def run_as_timeseries(self, starttime, endtime): def run_as_timeseries(self, starttime, endtime):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment