bluemaesto: get rid of unnecessary file, move to top level

This commit is contained in:
Dima Gerasimov 2021-02-14 19:42:35 +00:00 committed by karlicoss
parent d562f00dca
commit d77ab92d86
3 changed files with 31 additions and 33 deletions

View file

@ -12,8 +12,8 @@ import sqlite3
from typing import Iterable, NamedTuple, Sequence, Set, Optional from typing import Iterable, NamedTuple, Sequence, Set, Optional
from ..core.common import mcachew, LazyLogger, get_files from .core.common import mcachew, LazyLogger, get_files
from ..core.cachew import cache_dir from .core.cachew import cache_dir
from my.config import bluemaestro as config from my.config import bluemaestro as config
@ -140,12 +140,12 @@ def measurements(dbs=inputs()) -> Iterable[Measurement]:
# for k, v in merged.items(): # for k, v in merged.items():
# yield Point(dt=k, temp=v) # meh? # yield Point(dt=k, temp=v) # meh?
from ..core import stat, Stats from .core import stat, Stats
def stats() -> Stats: def stats() -> Stats:
return stat(measurements) return stat(measurements)
from ..core.pandas import DataFrameT, check_dataframe as cdf from .core.pandas import DataFrameT, check_dataframe as cdf
@cdf @cdf
def dataframe() -> DataFrameT: def dataframe() -> DataFrameT:
""" """
@ -165,3 +165,28 @@ def dataframe() -> DataFrameT:
return df.set_index('dt') return df.set_index('dt')
# todo test against an older db? # 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

View file

@ -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()

View file

@ -2,6 +2,7 @@
from pathlib import Path from pathlib import Path
from more_itertools import one from more_itertools import one
# TODO hmm uses testdata so maybe ok to uncomment
from .common import skip_if_not_karlicoss from .common import skip_if_not_karlicoss
import pytest # type: ignore import pytest # type: ignore
@ -51,3 +52,4 @@ def prepare():
export_path = bmdata export_path = bmdata
config.bluemaestro = user_config # type: ignore config.bluemaestro = user_config # type: ignore
yield yield
# TODO restore the config!