Permalink
Browse files

support filtering for "greater than" some datetime

  • Loading branch information...
stnbu committed Sep 8, 2018
1 parent 28bbb37 commit 60b40c1b075a23bc2bea6ca374616e13007b3f1a
Showing with 10 additions and 3 deletions.
  1. +9 −2 coincharts/data.py
  2. +1 −1 coincharts/views.py
@@ -7,16 +7,18 @@
from mutils.memoize import memoize
from coincharts.db import *
from coincharts.models import THE_DATETIME_FIELD, THE_PRICE_FIELD
from coincharts import config
config = config.get_config()
class SymbolInfo(object):
def __init__(self, symbol, length):
def __init__(self, symbol, length, since=None):
self.symbol = symbol
self.length = length # this is set below when we access the "history". Being as lazy as possible.
self.since = since
@property
@memoize
@@ -31,7 +33,12 @@ def max(self):
@property
@memoize
def history(self):
history = Prices.objects.filter(symbol=self.symbol)
kwargs = dict(symbol=self.symbol)
if self.since is not None:
dt__gte = '{}__gte'.format(THE_DATETIME_FIELD) # `@property` name mangling not supported
kwargs[dt__gte] = self.since
history = Prices.objects.filter(**kwargs)
self.length = len(history)
return history
@@ -18,7 +18,7 @@ def index(request):
symbols = config['history_symbols']
comparison = SymbolComparison()
for symbol in symbols:
comparison[symbol] = SymbolInfo(symbol, length=967)
comparison[symbol] = SymbolInfo(symbol, length=967, since='2018-08-16T06:59:59.0000000Z')
history_generator = comparison.normalized_history_averages()
graph = svg_graph.LineGraph(

0 comments on commit 60b40c1

Please sign in to comment.