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

tsio: provide a .last_id method returning the latest changeset id of a serie

This is needed by the tshistory_editor package.
parent d770043514c6
......@@ -55,6 +55,8 @@ def test_differential(engine, tsh):
ts_begin = genserie(datetime(2010, 1, 1), 'D', 10)
tsh.insert(engine, ts_begin, 'ts_test', 'test')
id1 = tsh.last_id(engine, 'ts_test')
assert tsh.exists(engine, 'ts_test')
assert not tsh.exists(engine, 'this_does_not_exist')
......@@ -91,6 +93,7 @@ def test_differential(engine, tsh):
ts_slight_variation.iloc[3] = 0
ts_slight_variation.iloc[6] = 0
tsh.insert(engine, ts_slight_variation, 'ts_test', 'celeste')
id2 = tsh.last_id(engine, 'ts_test')
assert_df("""
2010-01-01 0.0
......@@ -111,6 +114,9 @@ def test_differential(engine, tsh):
ts_longer.iloc[5] = ts_begin.iloc[7]
tsh.insert(engine, ts_longer, 'ts_test', 'test')
id3 = tsh.last_id(engine, 'ts_test')
assert id1 < id2 < id3
assert_df("""
2010-01-01 0.00
......
......@@ -174,6 +174,10 @@ class Snapshot(SeriesServices):
return self.find(from_value_date=from_value_date,
to_value_date=to_value_date)[1]
def last_id(self, from_value_date=None, to_value_date=None):
return self.find(from_value_date=from_value_date,
to_value_date=to_value_date)[0]
def find(self, csetfilter=(), seriefilter=(),
from_value_date=None, to_value_date=None):
cset = self.tsh.schema.changeset
......
......@@ -232,6 +232,10 @@ class TimeSerie(SeriesServices):
).where(tstable.c.cset == cset.c.id)
return cn.execute(sql).scalar()
def last_id(self, cn, seriename):
snapshot = Snapshot(cn, self, seriename)
return snapshot.last_id()
def changeset_at(self, cn, seriename, revdate, mode='strict'):
assert mode in ('strict', 'before', 'after')
cset = self.schema.changeset
......
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