From 9cd80320cbb2673834c23fee3e817e11a920c9e0 Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Sun, 21 Aug 2022 19:46:49 +0500 Subject: [PATCH] Fix cdag expdecay Convert NS timestamp format fixed 'OverflowError: math range error'. --- core/cdag/node/expdecay.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/cdag/node/expdecay.py b/core/cdag/node/expdecay.py index 9efd6cf65f..2454033dc3 100644 --- a/core/cdag/node/expdecay.py +++ b/core/cdag/node/expdecay.py @@ -17,6 +17,8 @@ from .window import WindowNode, WindowConfig from .base import ValueType, Category +NS = 1_000_000_000 + class ExpDecayNodeState(BaseModel): times: List[int] = [] @@ -39,6 +41,6 @@ class ExpDecayNode(WindowNode): def get_window_value( self, values: List[ValueType], timestamps: List[int] ) -> Optional[ValueType]: - t0 = timestamps[-1] + t0 = timestamps[-1] // NS nk = self.config.k - return sum(v * exp(nk * (t0 - ts)) for ts, v in zip(timestamps, values)) + return sum(v * exp(nk * t0 - ts // NS) for ts, v in zip(timestamps, values)) -- GitLab