diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/report_ops/admin.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/python/report_ops/admin.py b/python/report_ops/admin.py index b807c285..01a8929b 100644 --- a/python/report_ops/admin.py +++ b/python/report_ops/admin.py @@ -6,6 +6,7 @@ from serenitas.analytics.dates import next_business_day from .misc import dt_from_citco from functools import partial from typing import ClassVar +import datetime def load_citco_report(fh, kd, date_cols): @@ -40,18 +41,18 @@ class CitcoReport: return cls._registry[table] @classmethod - def get_newest_report(cls, date): + def get_newest_report(cls, report_file_date): p = max( [ f for f in cls._sftp.client.listdir() - if (cls.fname in f) and (cls.dtkey_fun(f).date() == date) + if (cls.fname in f) and (cls.dtkey_fun(f).date() == report_file_date) ], key=cls.dtkey_fun, default=None, ) if not p: - raise ValueError(f"No reports for {cls.table} on {date}") + raise ValueError(f"No reports for {cls.table} on {report_file_date}") return p @classmethod @@ -61,13 +62,18 @@ class CitcoReport: return load_citco_report(fh, kd, cls.date_cols) @classmethod - def to_db(cls, date): - p = cls.get_newest_report(date) + def to_db(cls, ped): + report_file_date = ped if cls is AllReport else next_business_day(ped) + p = cls.get_newest_report(report_file_date) df = cls.to_df(p) + df["knowledge_date"] = datetime.datetime.combine( + next_business_day(ped), cls.dtkey_fun(p).time() + ) + df["period_end_date"] = ped with cls._conn.cursor() as c: c.execute( f"DELETE FROM {cls.table} WHERE period_end_date= %s", - (date,), + (ped,), ) cls._conn.commit() if "strategy" in df.columns: |
