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

tsio/insert: storing the manual input like that is not really useful


Dominant use case is to receive things from excel, which
means the manual edition is actually embedded within
mostly "automatic" data. Very different from a carefully
crafted insert ...

So we'll keep the habit of computing the manual insertions
by diffing automatic against the base (synthetic).
parent 8ca3c5235bd6
from pathlib import Path
from datetime import datetime
import pytest
......@@ -420,14 +421,6 @@ def test_more_manual(engine, tsh):
2015-01-05 True
""", marker)
tshm = TimeSerie('tsh-manual')
man = tshm.get(engine, 'ts_exp1', _keep_nans=True)
assert_df("""
2015-01-03 -3.0
2015-01-04 -3.0
2015-01-05 NaN
""", man)
def test_before_first_insertion(engine, tsh):
tsh.insert(engine, genserie(datetime(2010, 1, 1), 'D', 11), 'ts_shtroumpf', 'test')
......
......@@ -4,10 +4,8 @@ from tshistory.schema import init as tshinit, reset as tshreset
def init(engine, meta, namespace='tsh'):
tshinit(engine, meta, namespace)
tshinit(engine, meta, '{}-automatic'.format(namespace))
tshinit(engine, meta, '{}-manual'.format(namespace))
def reset(engine, namespace='tsh'):
tshreset(engine, namespace)
tshreset(engine, '{}-automatic'.format(namespace))
tshreset(engine, '{}-manual'.format(namespace))
......@@ -39,36 +39,27 @@ class TimeSerie(BaseTS):
value.
We can explain the workflow like with a traditional DVCS graph,
with three branches: "automatic", "manual" and "synthetic".
with two branches: "automatic" and "synthetic".
All automatic fetches go into the automatic branch (and thus are
diffed against each other).
The synthetic series receive all the non-empty differences
resulting from inserting to the automatic series, and also
all the manual entries.
resulting from inserting to the automatic series, and also all the
manual entries.
The manual editions are computed as a diffs between synthetic and
automatic series.
The manual editions can be computed as a diff between synthetic
and automatic series, but for convenience we also store them
explicitly.
"""
def __init__(self, *a, **kw):
super().__init__(*a, **kw)
self.manual_store = BaseTS(namespace='{}-manual'.format(self.namespace))
self.auto_store = BaseTS(namespace='{}-automatic'.format(self.namespace))
def insert(self, cn, ts, name, author, _insertion_date=None, manual=False):
if manual:
# insert & compute diff over synthetic
diff = self.manual_store.insert(
cn, ts, name, author, _insertion_date=_insertion_date
)
if diff is None:
return
diff = ts
else:
# insert & compute diff over automatic
diff = self.auto_store.insert(
......
Markdown is supported
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