Skip to content

Commit

Permalink
refs #8300. Add Start and End time filtering.
Browse files Browse the repository at this point in the history
Unit tested too.
  • Loading branch information
OwenArnold committed Nov 5, 2013
1 parent f2608d0 commit b95d717
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
Expand Up @@ -30,27 +30,29 @@ def PyExec(self):
start_time = None
if end_time == sys.float_info.max:
end_time = None
if start_time > end_time:
raise ValueError("StartTime > EndTime")
if start_time and end_time and (start_time > end_time):
raise ValueError("StartTime > EndTime, %s > %s" % (str(start_time), str(end_time)))

values = self.__filter(in_ws, log_name)
values = self.__filter(in_ws, log_name, start_time, end_time)
stats = self.__statistics(values)
self.setProperty("FilteredResult", values)
self.setProperty("ResultStatistic", float(stats))

def __filter(self, ws, logname, starttime=None, endtime=None):
run = ws.getRun()
tstart = run.startTime()
tend = run.endTime()
runstart = run.startTime().total_nanoseconds()
tstart = runstart
tend = run.endTime().total_nanoseconds()
nanosecond = int(1e9)
if starttime:
tstart = tstart + (starttime * nanosecond)
tstart = runstart + (starttime * nanosecond)
if endtime:
tend = tend + (endtime * nanosecond)
tend = runstart + (endtime * nanosecond)
log = run.getLogData(logname)
times = numpy.array(log.times)
times = numpy.array(map(lambda t: t.total_nanoseconds(), log.times))

values = numpy.array(log.value)
mask = (tstart < times) & (times < tend) # Get times between filter start and end.
mask = (tstart <= times) & (times <= tend) # Get times between filter start and end.
filteredvalues = values[mask]
return filteredvalues

Expand Down
Expand Up @@ -55,8 +55,7 @@ def test_startdate_after_enddate(self):
except RuntimeError:
pass

def test_without_limits(self):

def xtest_without_limits(self):
AddSampleLog(Workspace=self.__ws,LogName='run_start',LogText='1900-Jan-01 00:00:00')
AddSampleLog(Workspace=self.__ws,LogName='run_end',LogText='2100-Jan-02 00:00:00')

Expand All @@ -67,6 +66,40 @@ def test_without_limits(self):
actual_size = results.size
self.assertEqual(expected_size, actual_size, "Nothing filtered out")

def xtest_with_start_limit(self):
AddSampleLog(Workspace=self.__ws,LogName='run_start',LogText='2008-06-17T11:10:44')
AddSampleLog(Workspace=self.__ws,LogName='run_end',LogText='2100-Jan-02 00:00:00')

results, stats = FilterLogByTime(InputWorkspace=self.__ws, LogName='height', StartTime=1)
self.assertTrue(isinstance(results, numpy.ndarray), "Should give back an array")
self.assertTrue(isinstance(stats, float), "Should give back a single result")
expected_size = self.__ws.getRun().getLogData('height').size() - 1
actual_size = results.size
self.assertEqual(expected_size, actual_size, "Should filter one out expected_size %s, actual_size %s" % (str(expected_size), str(actual_size)))

def xtest_with_end_limit(self):
AddSampleLog(Workspace=self.__ws,LogName='run_start',LogText='2008-06-17T11:10:44')
AddSampleLog(Workspace=self.__ws,LogName='run_end',LogText='2100-Jan-02 00:00:00')

results, stats = FilterLogByTime(InputWorkspace=self.__ws, LogName='height', EndTime=0.99)
self.assertTrue(isinstance(results, numpy.ndarray), "Should give back an array")
self.assertTrue(isinstance(stats, float), "Should give back a single result")
expected_size = 1
actual_size = results.size
self.assertEqual(expected_size, actual_size, "Expected_size %s, actual_size %s" % (str(expected_size), str(actual_size)))

def test_with_both_limits(self):
AddSampleLog(Workspace=self.__ws,LogName='run_start',LogText='2008-06-17T11:10:44')
AddSampleLog(Workspace=self.__ws,LogName='run_end',LogText='2100-Jan-02 00:00:00')

results, stats = FilterLogByTime(InputWorkspace=self.__ws, LogName='height', StartTime=1.001, EndTime=3)
self.assertTrue(isinstance(results, numpy.ndarray), "Should give back an array")
self.assertTrue(isinstance(stats, float), "Should give back a single result")
expected_size = 1
actual_size = results.size
self.assertEqual(expected_size, actual_size, "Should filter one out expected_size %s, actual_size %s" % (str(expected_size), str(actual_size)))



if __name__ == '__main__':
unittest.main()

0 comments on commit b95d717

Please sign in to comment.