diff --git a/lbry/lbry/wallet/server/db/trending.py b/lbry/lbry/wallet/server/db/trending.py index bf02aad90..3ec0562b5 100644 --- a/lbry/lbry/wallet/server/db/trending.py +++ b/lbry/lbry/wallet/server/db/trending.py @@ -39,7 +39,8 @@ class ZScore: @property 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): if self.count == 0: diff --git a/lbry/tests/unit/wallet/server/test_sqldb.py b/lbry/tests/unit/wallet/server/test_sqldb.py index 87dcc3bea..e313863bc 100644 --- a/lbry/tests/unit/wallet/server/test_sqldb.py +++ b/lbry/tests/unit/wallet/server/test_sqldb.py @@ -477,3 +477,9 @@ class TestTrending(TestSQLDB): 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([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)])