aboutsummaryrefslogtreecommitdiffstats
path: root/python/report_ops
diff options
context:
space:
mode:
Diffstat (limited to 'python/report_ops')
-rw-r--r--python/report_ops/status.py15
-rw-r--r--python/report_ops/utils.py40
2 files changed, 54 insertions, 1 deletions
diff --git a/python/report_ops/status.py b/python/report_ops/status.py
index befaeff3..297a1633 100644
--- a/python/report_ops/status.py
+++ b/python/report_ops/status.py
@@ -5,10 +5,13 @@ import re
import xml.etree.ElementTree as ET
from io import BytesIO
from functools import lru_cache
+from psycopg.errors import UniqueViolation
from serenitas.ops.trade_dataclasses import Deal
from serenitas.utils.remote import Client
+from .utils import QuantifiMonitor
+
class Remote:
_client: ClassVar
@@ -63,7 +66,17 @@ class QuantifiRemote(
"filename": fname.removesuffix(".xml"),
"total": data["items"],
}
- return cls.from_dict(**data)
+ item = cls.from_dict(**data)
+ item.stage()
+ try:
+ item.commit()
+ except UniqueViolation:
+ item._conn.rollback()
+ else:
+ QuantifiMonitor.stage(data)
+ QuantifiMonitor.email(fname.removesuffix(".xml"), data["errors"] > 0)
+ finally:
+ item._insert_queue.clear()
@staticmethod
def extract_ts(filename):
diff --git a/python/report_ops/utils.py b/python/report_ops/utils.py
index 54f25526..5b0c14a7 100644
--- a/python/report_ops/utils.py
+++ b/python/report_ops/utils.py
@@ -502,6 +502,46 @@ class FxHedge(
)
+class QuantifiMonitor(
+ Monitor,
+ headers=(
+ "uploadtime",
+ "filename",
+ "errors",
+ "warnings",
+ "successes",
+ "total",
+ ),
+ num_format=[],
+):
+ @classmethod
+ def email(cls, filename, errors):
+ if not cls._staging_queue:
+ return
+ cls._em.send_email(
+ f"Quantifi Report: {filename} {'**Errors**' if errors else ''}",
+ HTMLBody(
+ f"""
+<html>
+ <head>
+ <style>
+ table, th, td {{ border: 1px solid black; border-collapse: collapse;}}
+ th, td {{ padding: 5px; }}
+ </style>
+ </head>
+ <body>
+ {cls.to_tabulate()}
+ </body>
+</html>"""
+ ),
+ to_recipients=(
+ "fyu@lmcg.com",
+ "ghorel@lmcg.com",
+ "etsui@lmcg.com",
+ ),
+ )
+
+
@dataclass
class EmailOps:
_em = ExchangeMessage()