my.bluemaestro: minor cleanup
This commit is contained in:
parent
c25ab51664
commit
88a3aa8d67
1 changed files with 30 additions and 20 deletions
|
@ -4,13 +4,26 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# todo most of it belongs to DAL... but considering so few people use it I didn't bother for now
|
# todo most of it belongs to DAL... but considering so few people use it I didn't bother for now
|
||||||
|
from dataclasses import dataclass
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import re
|
import re
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from typing import Iterable, Sequence, Set, Optional
|
from typing import Iterable, Sequence, Set, Optional
|
||||||
|
|
||||||
from my.core import get_files, make_logger, dataclass, Res
|
import pytz
|
||||||
|
|
||||||
|
from my.core import (
|
||||||
|
get_files,
|
||||||
|
make_logger,
|
||||||
|
Res,
|
||||||
|
stat,
|
||||||
|
Stats,
|
||||||
|
influxdb,
|
||||||
|
)
|
||||||
|
from my.core.common import mcachew
|
||||||
|
from my.core.error import unwrap
|
||||||
|
from my.core.pandas import DataFrameT, as_dataframe
|
||||||
from my.core.sqlite import sqlite_connect_immutable
|
from my.core.sqlite import sqlite_connect_immutable
|
||||||
|
|
||||||
from my.config import bluemaestro as config
|
from my.config import bluemaestro as config
|
||||||
|
@ -27,6 +40,7 @@ Celsius = float
|
||||||
Percent = float
|
Percent = float
|
||||||
mBar = float
|
mBar = float
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Measurement:
|
class Measurement:
|
||||||
dt: datetime # todo aware/naive
|
dt: datetime # todo aware/naive
|
||||||
|
@ -38,7 +52,6 @@ class Measurement:
|
||||||
|
|
||||||
# fixme: later, rely on the timezone provider
|
# fixme: later, rely on the timezone provider
|
||||||
# NOTE: the timezone should be set with respect to the export date!!!
|
# NOTE: the timezone should be set with respect to the export date!!!
|
||||||
import pytz
|
|
||||||
tz = pytz.timezone('Europe/London')
|
tz = pytz.timezone('Europe/London')
|
||||||
# TODO when I change tz, check the diff
|
# TODO when I change tz, check the diff
|
||||||
|
|
||||||
|
@ -49,9 +62,7 @@ def is_bad_table(name: str) -> bool:
|
||||||
return False if delegate is None else delegate(name)
|
return False if delegate is None else delegate(name)
|
||||||
|
|
||||||
|
|
||||||
from my.core.cachew import cache_dir
|
@mcachew(depends_on=inputs)
|
||||||
from my.core.common import mcachew
|
|
||||||
@mcachew(depends_on=inputs, cache_path=cache_dir('bluemaestro'))
|
|
||||||
def measurements() -> Iterable[Res[Measurement]]:
|
def measurements() -> Iterable[Res[Measurement]]:
|
||||||
# todo ideally this would be via arguments... but needs to be lazy
|
# todo ideally this would be via arguments... but needs to be lazy
|
||||||
dbs = inputs()
|
dbs = inputs()
|
||||||
|
@ -68,7 +79,9 @@ def measurements() -> Iterable[Res[Measurement]]:
|
||||||
with sqlite_connect_immutable(f) as db:
|
with sqlite_connect_immutable(f) as db:
|
||||||
db_dt: Optional[datetime] = None
|
db_dt: Optional[datetime] = None
|
||||||
try:
|
try:
|
||||||
datas = db.execute(f'SELECT "{f.name}" as name, Time, Temperature, Humidity, Pressure, Dewpoint FROM data ORDER BY log_index')
|
datas = db.execute(
|
||||||
|
f'SELECT "{f.name}" as name, Time, Temperature, Humidity, Pressure, Dewpoint FROM data ORDER BY log_index'
|
||||||
|
)
|
||||||
oldfmt = True
|
oldfmt = True
|
||||||
db_dts = list(db.execute('SELECT last_download FROM info'))[0][0]
|
db_dts = list(db.execute('SELECT last_download FROM info'))[0][0]
|
||||||
if db_dts == 'N/A':
|
if db_dts == 'N/A':
|
||||||
|
@ -178,12 +191,11 @@ def measurements() -> Iterable[Res[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 my.core import stat, Stats
|
|
||||||
def stats() -> Stats:
|
def stats() -> Stats:
|
||||||
return stat(measurements)
|
return stat(measurements)
|
||||||
|
|
||||||
|
|
||||||
from my.core.pandas import DataFrameT, as_dataframe
|
|
||||||
def dataframe() -> DataFrameT:
|
def dataframe() -> DataFrameT:
|
||||||
"""
|
"""
|
||||||
%matplotlib gtk
|
%matplotlib gtk
|
||||||
|
@ -197,7 +209,6 @@ def dataframe() -> DataFrameT:
|
||||||
|
|
||||||
|
|
||||||
def fill_influxdb() -> None:
|
def fill_influxdb() -> None:
|
||||||
from my.core import influxdb
|
|
||||||
influxdb.fill(measurements(), measurement=__name__)
|
influxdb.fill(measurements(), measurement=__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -205,7 +216,6 @@ def check() -> None:
|
||||||
temps = list(measurements())
|
temps = list(measurements())
|
||||||
latest = temps[:-2]
|
latest = temps[:-2]
|
||||||
|
|
||||||
from my.core.error import unwrap
|
|
||||||
prev = unwrap(latest[-2]).dt
|
prev = unwrap(latest[-2]).dt
|
||||||
last = unwrap(latest[-1]).dt
|
last = unwrap(latest[-1]).dt
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue