Skip to content

Commit a044eb1

Browse files
author
Siddharta Govindaraj
committed
Extract Class - migrated update to TimeSeries
1 parent c3f4f79 commit a044eb1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

stock_alerter/stock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def update(self, timestamp, price):
3232
if price < 0:
3333
raise ValueError("price should not be negative")
3434
bisect.insort_left(self.price_history, PriceEvent(timestamp, price))
35+
self.history.update(timestamp, price)
3536

3637
def is_increasing_trend(self):
3738
return self.price_history[-3].price < \

stock_alerter/timeseries.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
import bisect
2+
import collections
3+
4+
Update = collections.namedtuple("Update", ["timestamp", "value"])
5+
6+
17
class TimeSeries:
2-
pass
8+
def __init__(self):
9+
self.series = []
10+
11+
def update(self, timestamp, value):
12+
bisect.insort_left(self.series, Update(timestamp, value))

0 commit comments

Comments
 (0)