This commit is contained in:
Victor Shyba 2019-11-24 02:38:42 -03:00 committed by Lex Berezhny
parent ece5082096
commit e77acde005
2 changed files with 8 additions and 1 deletions

View file

@ -39,7 +39,8 @@ class ZScore:
@property @property
def standard_deviation(self): def standard_deviation(self):
return sqrt((self.power / self.count) - self.mean ** 2) value = (self.power / self.count) - self.mean ** 2
return sqrt(value) if value > 0 else 0
def finalize(self): def finalize(self):
if self.count == 0: if self.count == 0:

View file

@ -477,3 +477,9 @@ class TestTrending(TestSQLDB):
self.assertEqual([53, 38, -32, 0, -6], [int(c['trending_global']) for c in results]) self.assertEqual([53, 38, -32, 0, -6], [int(c['trending_global']) for c in results])
self.assertEqual([4, 4, 2, 0, 1], [int(c['trending_group']) for c in results]) self.assertEqual([4, 4, 2, 0, 1], [int(c['trending_group']) for c in results])
self.assertEqual([53, 38, 2, 0, -6], [int(c['trending_mixed']) for c in results]) self.assertEqual([53, 38, 2, 0, -6], [int(c['trending_mixed']) for c in results])
def test_edge(self):
problematic = self.get_stream('Problem', COIN)
self.advance(1, [problematic])
self.advance(TRENDING_WINDOW, [self.get_support(problematic, 53000000000)])
self.advance(TRENDING_WINDOW * 2, [self.get_support(problematic, 500000000)])