From ba0f909b68169c15b349e4def88b99a7ee200c10 Mon Sep 17 00:00:00 2001 From: Dimitris Papagiannis Date: Wed, 6 Sep 2023 10:49:47 +0000 Subject: [PATCH] asdfa --- db.py | 24 ++++++++++++++---------- tests/test_1.py | 3 +-- tests/test_2.py | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/db.py b/db.py index fe2a869..9f7788c 100644 --- a/db.py +++ b/db.py @@ -1,6 +1,7 @@ ### DQM^2 Mirror DB === > import os import sys +import logging import psycopg2 import sqlalchemy from sqlalchemy_utils import database_exists @@ -62,29 +63,29 @@ class DQM2MirrorDB: TB_DESCRIPTION_META_SHORT = "( name, data )" def __str__(self): - return f"{self.__class__.__name__}: {self.db_str}" + return f"{self.__class__.__name__}: {self.db_uri}" - def __init__(self, log, db=None, server=False): + def __init__(self, log: logging.Logger, db_uri: str = None, server: bool = False): """ The server flag will determine if table creation will take place or not, upon initialization. """ self.log = log self.log.info("\n\n DQM2MirrorDB ===== init ") - self.db_str = db + self.db_uri = db_uri - if not self.db_str: - self.db_str = ":memory:" + if not self.db_uri: + self.db_uri = ":memory:" self.engine = sqlalchemy.create_engine( - self.db_str, + url=self.db_uri, poolclass=sqlalchemy.pool.QueuePool, pool_size=20, max_overflow=0, ) if not database_exists(self.engine.url): raise DatabaseNotFoundError( - f"Database name was not found when connecting to '{self.db_str}'" + f"Database name was not found when connecting to '{self.db_uri}'" ) self.Session = sessionmaker(bind=self.engine) @@ -449,7 +450,8 @@ def format_run_data(self, data): ] return answer - def make_table_entry(self, data: dict): + def format_table_entry(self, data: dict): + """ """ answer = [] ( _, @@ -468,7 +470,7 @@ def make_table_entry(self, data: dict): timestamp, _, ) = data - + print("!! format_table_entry:\t\t", timestamp) client = self.get_short_client_name(client) # Hide part of the hostname for safety reasons var = hostname.split("-") @@ -497,6 +499,8 @@ def make_table_entry(self, data: dict): ), (cmssw_run, runkey, cmssw_v), ] + print("!! format_table_entry iso:\t", timestamp.isoformat()) + return answer def filter_clients(self, name): @@ -526,7 +530,7 @@ def get_timeline_data( with_ls_only: bool = False, ) -> dict: runs = self.get(run_start, run_end, bad_only, with_ls_only) - runs_out = [self.make_table_entry(run) for run in runs] + runs_out = [self.format_table_entry(run) for run in runs] dic = defaultdict(dict) for run in runs_out: diff --git a/tests/test_1.py b/tests/test_1.py index 00a7364..87e5803 100644 --- a/tests/test_1.py +++ b/tests/test_1.py @@ -43,7 +43,7 @@ def testing_database() -> DQM2MirrorDB: create_database(db_uri) db = DQM2MirrorDB( log=dummy_log(), - db=db_uri, + db_uri=db_uri, server=False, ) @@ -62,7 +62,6 @@ def testing_database() -> DQM2MirrorDB: with db.engine.connect() as cur: session = db.Session(bind=cur) for run in runs: - print("!!!", run[-4]) try: session.execute( f"""INSERT into runs ({str(db.TB_DESCRIPTION_RUNS_SHORT).replace("[", "").replace("]", "").replace("'", "")}) VALUES ({format_entry_to_db_entry(run, [13])})""" diff --git a/tests/test_2.py b/tests/test_2.py index da59776..5cf456d 100644 --- a/tests/test_2.py +++ b/tests/test_2.py @@ -20,7 +20,7 @@ def get_or_create_db(db_uri: str): create_database(db_uri) return DQM2MirrorDB( log=dummy_log(), - db=db_uri, + db_uri=db_uri, server=False, )