Commit 1ba81425 authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

snapshot/find: dissociate cset and serie filters

For usage clarity.
parent 830f6b6e5637
......@@ -168,25 +168,27 @@ class Snapshot(SeriesServices):
@property
def first(self):
return self.find(qfilter=[lambda _, table: table.c.id == 1])[1]
return self.find(seriefilter=[lambda serie: serie.c.id == 1])[1]
def last(self, from_value_date=None, to_value_date=None):
return self.find(from_value_date=from_value_date,
to_value_date=to_value_date)[1]
def find(self, qfilter=(),
def find(self, csetfilter=(), seriefilter=(),
from_value_date=None, to_value_date=None):
cset = self.tsh.schema.changeset
table = self.tsh._get_ts_table(self.cn, self.seriename)
sql = select([table.c.cset, table.c.snapshot]
).order_by(desc(table.c.id)
serie = self.tsh._get_ts_table(self.cn, self.seriename)
sql = select([serie.c.cset, serie.c.snapshot]
).order_by(desc(serie.c.id)
).limit(1
).select_from(table.join(cset))
if qfilter:
sql = sql.where(table.c.cset <= cset.c.id)
for filtercb in qfilter:
sql = sql.where(filtercb(cset, table))
).select_from(serie.join(cset))
if csetfilter:
sql = sql.where(serie.c.cset <= cset.c.id)
for filtercb in csetfilter:
sql = sql.where(filtercb(cset))
for tablecb in seriefilter:
sql = sql.where(tablefilter(serie))
try:
csid, cid = self.cn.execute(sql).fetchone()
......
......@@ -82,11 +82,11 @@ class TimeSerie(SeriesServices):
if table is None:
return
qfilter = []
csetfilter = []
if revision_date:
qfilter.append(lambda cset, _: cset.c.insertion_date <= revision_date)
csetfilter.append(lambda cset: cset.c.insertion_date <= revision_date)
snap = Snapshot(cn, self, name)
_, current = snap.find(qfilter,
_, current = snap.find(csetfilter=csetfilter,
from_value_date=from_value_date,
to_value_date=to_value_date)
......@@ -172,9 +172,9 @@ class TimeSerie(SeriesServices):
to_value_date = idate + deltaafter
series.append((
idate,
snapshot.find([lambda cset, _: cset.c.id == csid],
from_value_date=from_value_date,
to_value_date=to_value_date)[1]
snapshot.find(csetfilter=[lambda cset: cset.c.id == csid],
from_value_date=from_value_date,
to_value_date=to_value_date)[1]
))
for revdate, serie in series:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment