def test_zscore(self): ts = [ (datetime.datetime(2013, 10, 31), 4.53), (datetime.datetime(2013, 11, 1), 3.87), (datetime.datetime(2013, 11, 4), -2.89), (datetime.datetime(2013, 11, 5), -0.18), (datetime.datetime(2013, 11, 6), 1.36), (datetime.datetime(2013, 11, 7), 6.32), (datetime.datetime(2013, 11, 8), 0.51), (datetime.datetime(2013, 11, 11), -5.98), (datetime.datetime(2013, 11, 12), -6.30), (datetime.datetime(2013, 11, 13), 0.51), ] zsc = timeseries.zscore(ts) ave = (4.53 + 3.87 - 2.89 - 0.18 + 1.36 + 6.32 + 0.51 - 5.98 - 6.30 + 0.51)/10.0 var = ((4.53 - ave)**2 + (3.87 - ave)**2 + (-2.89 - ave)**2 + (-0.18 - ave)**2 + (1.36 - ave)**2 + (6.32 - ave)**2 + (0.51 - ave)**2 + (-5.98 - ave)**2 + (-6.30 - ave)**2 + (0.51 - ave)**2)/10.0 expected_result = [(datetime.datetime(2013, 11, 13), (0.51 - ave)/(var**0.5))] self.assertEqual(zsc, expected_result)
def update(self, data, config): ts = sorted(zip(data['dates'], data['values'])) self.current.SetLabel('{0}'.format(ts[-1][1])) min = timeseries.min(ts)[0] self.min_val.SetLabel('{0} ({1})'. format(min[1], min[0].strftime('%Y-%m-%d'))) max = timeseries.max(ts)[0] self.max_val.SetLabel('{0} ({1})'. format(max[1], max[0].strftime('%Y-%m-%d'))) self.ave.SetLabel('{0:.2f}'.format(timeseries.mean(ts)[0][1])) self.sd.SetLabel('{0:.2f}'.format(timeseries.sd(ts)[0][1])) self.zscore.SetLabel('{0:.2f}'. format(timeseries.zscore(ts)[0][1]))