Newer
Older
Hal Simpson
committed
"""Controller class for geomag algorithms"""
Hal Simpson
committed
import TimeseriesUtilities
class Controller(object):
"""Controller for geomag algorithms.
Parameters
----------
the factory that will read in timeseries data
the factory that will output the timeseries data
algorithm: the algorithm(s) that will take procees the timeseries data
"""
Hal Simpson
committed
def __init__(self, inputFactory, outputFactory, algorithm, update=False):
self._inputFactory = inputFactory
self._algorithm = algorithm
self._outputFactory = outputFactory
Hal Simpson
committed
self._update = update
"""run an algorithm as setup up by the main script.
Parameters
----------
starttime : UTCDateTime
time of first sample to be worked on.
endtime : UTCDateTime
time of last sample to be worked on.
"""
Hal Simpson
committed
if (self._update):
self.run_as_update(starttime, endtime)
else:
self.run_as_timeseries(starttime, endtime)
def run_as_update(self, starttime, endtime):
input_channels = self._algorithm.get_input_channels()
output_channels = self._algorithm.get_output_channels()
timeseries_in = self._inputFactory.get_timeseries(starttime,
endtime, channels=input_channels)
timeseries_out = self._inputFactory.get_timeseries(starttime,
endtime, channels=output_channels)
Hal Simpson
committed
#TODO get input gaps
Hal Simpson
committed
Hal Simpson
committed
output_gaps = TimeseriesUtilities.get_timeseries_gaps(
timeseries_out, output_channels, starttime, endtime)
Hal Simpson
committed
Hal Simpson
committed
output_merged_gaps = TimeseriesUtilities.get_merged_gaps(output_gaps,
output_channels)
# TODO compare gaps.
# if there is new data, run algorithm over entire time.
# save any new data.
#TODO iterate is starttime of gaps is starttime and new data found
Hal Simpson
committed
def run_as_timeseries(self, starttime, endtime):
input_channels = self._algorithm.get_input_channels()
Hal Simpson
committed
timeseries = self._inputFactory.get_timeseries(starttime, endtime,
Hal Simpson
committed
channels=input_channels)
processed = self._algorithm.process(timeseries)
output_channels = self._algorithm.get_output_channels()
self._outputFactory.put_timeseries(timeseries=processed,
channels=output_channels)