From d77ab92d8634d0863d2b966cb448bbfcc8a8d565 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sun, 14 Feb 2021 19:42:35 +0000 Subject: [PATCH] bluemaesto: get rid of unnecessary file, move to top level --- .../__init__.py => bluemaestro.py} | 33 ++++++++++++++++--- my/bluemaestro/check.py | 29 ---------------- tests/bluemaestro.py | 2 ++ 3 files changed, 31 insertions(+), 33 deletions(-) rename my/{bluemaestro/__init__.py => bluemaestro.py} (87%) delete mode 100755 my/bluemaestro/check.py diff --git a/my/bluemaestro/__init__.py b/my/bluemaestro.py similarity index 87% rename from my/bluemaestro/__init__.py rename to my/bluemaestro.py index 172164a..b1a578f 100755 --- a/my/bluemaestro/__init__.py +++ b/my/bluemaestro.py @@ -12,8 +12,8 @@ import sqlite3 from typing import Iterable, NamedTuple, Sequence, Set, Optional -from ..core.common import mcachew, LazyLogger, get_files -from ..core.cachew import cache_dir +from .core.common import mcachew, LazyLogger, get_files +from .core.cachew import cache_dir from my.config import bluemaestro as config @@ -140,12 +140,12 @@ def measurements(dbs=inputs()) -> Iterable[Measurement]: # for k, v in merged.items(): # yield Point(dt=k, temp=v) # meh? -from ..core import stat, Stats +from .core import stat, Stats def stats() -> Stats: return stat(measurements) -from ..core.pandas import DataFrameT, check_dataframe as cdf +from .core.pandas import DataFrameT, check_dataframe as cdf @cdf def dataframe() -> DataFrameT: """ @@ -165,3 +165,28 @@ def dataframe() -> DataFrameT: return df.set_index('dt') # todo test against an older db? + + +def check() -> None: + temps = list(measurements()) + latest = temps[:-2] + + prev = latest[-2].dt + last = latest[-1].dt + + # todo stat should expose a dataclass? + # TODO ugh. might need to warn about points past 'now'?? + # the default shouldn't allow points in the future... + # + # TODO also needs to be filtered out on processing, should be rejected on the basis of export date? + + POINTS_STORED = 6000 # on device? + FREQ_SEC = 60 + SECS_STORED = POINTS_STORED * FREQ_SEC + HOURS_STORED = POINTS_STORED / (60 * 60 / FREQ_SEC) # around 4 days + NOW = datetime.now() + assert NOW - last < timedelta(hours=HOURS_STORED / 2), f'old backup! {last}' + + + assert last - prev < timedelta(minutes=3), f'bad interval! {last - prev}' + single = (last - prev).seconds diff --git a/my/bluemaestro/check.py b/my/bluemaestro/check.py deleted file mode 100755 index a2e25bc..0000000 --- a/my/bluemaestro/check.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/python3 -import logging -from datetime import timedelta, datetime - -from my.bluemaestro import measurements, logger - -# TODO move this to backup checker? -def main() -> None: - temps = list(measurements()) - latest = temps[:-2] - - prev = latest[-2].dt - last = latest[-1].dt - - POINTS_STORED = 6000 - FREQ_SEC = 60 - SECS_STORED = POINTS_STORED * FREQ_SEC - HOURS_STORED = POINTS_STORED / (60 * 60 / FREQ_SEC) # around 4 days - NOW = datetime.now() - assert NOW - last < timedelta(hours=HOURS_STORED / 2), f'old backup! {last}' - - - assert last - prev < timedelta(minutes=3), f'bad interval! {last - prev}' - single = (last - prev).seconds - - - -if __name__ == '__main__': - main() diff --git a/tests/bluemaestro.py b/tests/bluemaestro.py index 420dab8..1ec309d 100644 --- a/tests/bluemaestro.py +++ b/tests/bluemaestro.py @@ -2,6 +2,7 @@ from pathlib import Path from more_itertools import one +# TODO hmm uses testdata so maybe ok to uncomment from .common import skip_if_not_karlicoss import pytest # type: ignore @@ -51,3 +52,4 @@ def prepare(): export_path = bmdata config.bluemaestro = user_config # type: ignore yield + # TODO restore the config!