From 839ae9a81e3d649a9a2f18eaa8351aebc6f0e190 Mon Sep 17 00:00:00 2001 From: "Jose M. de la Rosa" Date: Thu, 31 Oct 2024 13:28:51 -0500 Subject: [PATCH 1/5] Added Timer.timeit decorator --- emtools/utils/time.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/emtools/utils/time.py b/emtools/utils/time.py index fdbe875..b7de988 100644 --- a/emtools/utils/time.py +++ b/emtools/utils/time.py @@ -15,6 +15,7 @@ # ************************************************************************** from datetime import datetime +from functools import wraps from .pretty import Pretty @@ -51,3 +52,13 @@ def __enter__(self): def __exit__(self, type, value, traceback): self.toc(self.message) + + @staticmethod + def timeit(func): + @wraps(func) + def wrap(*args, **kw): + t = Timer() + result = func(*args, **kw) + t.toc(f"Function {func.__name__} took: ") + return result + return wrap From 400335fccbcd7abca1cb31fa22d03d0516d8b742 Mon Sep 17 00:00:00 2001 From: "Jose M. de la Rosa" Date: Thu, 31 Oct 2024 16:05:24 -0500 Subject: [PATCH 2/5] Allow where for table iteration --- emtools/metadata/sqlite.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/emtools/metadata/sqlite.py b/emtools/metadata/sqlite.py index 7f3c264..e338259 100644 --- a/emtools/metadata/sqlite.py +++ b/emtools/metadata/sqlite.py @@ -80,7 +80,10 @@ def iterTable(self, tableName, **kwargs): limit: limit to this number of elements classes: read column names from a 'classes' table """ - query = f"SELECT * FROM {tableName}" + where = kwargs.get('where', '1') + printMap = kwargs.get('printMap', False) + + query = f"SELECT * FROM {tableName} WHERE {where}" if 'start' in kwargs and 'limit' not in kwargs: kwargs['limit'] = -1 @@ -99,6 +102,10 @@ def iterTable(self, tableName, **kwargs): columnsMap = {row['column_name']: row['label_property'] for row in self.iterTable(kwargs['classes'])} + if printMap: + from pprint import pprint + pprint(columnsMap) + def _row_factory(cursor, row): fields = [column[0] for column in cursor.description] return {columnsMap.get(k, k): v for k, v in zip(fields, row)} From b642413db301a30abb5aa3c92a6a140ae838bd38 Mon Sep 17 00:00:00 2001 From: "Jose M. de la Rosa" Date: Wed, 13 Nov 2024 19:00:22 -0600 Subject: [PATCH 3/5] Fixed error about monitor inputCount --- emtools/pwx/monitors.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/emtools/pwx/monitors.py b/emtools/pwx/monitors.py index 4c6f97b..85cceac 100644 --- a/emtools/pwx/monitors.py +++ b/emtools/pwx/monitors.py @@ -121,12 +121,11 @@ def __init__(self, SetClass, filename, *args, **kwargs): self._filename = filename self.lastUpdate = None self.streamClosed = None - self.inputCount = 0 # Count all input elements # Black list some items to not be monitored again # We are not interested in the items but just skip them from # the processing - blacklist = kwargs.get('blacklist', None) + blacklist = kwargs.get('blacklist', []) if blacklist: for item in blacklist: self[item.getObjId()] = True @@ -140,7 +139,6 @@ def update(self): setInstance = self._SetClass(filename=self._filename) setInstance.loadAllProperties() for item in setInstance.iterItems(): - self.inputCount += 1 iid = item.getObjId() if iid not in self: itemClone = item.clone() From bec8a98dbd50c2b6c0de56bd17a44db8b49707bd Mon Sep 17 00:00:00 2001 From: "Jose M. de la Rosa" Date: Thu, 14 Nov 2024 11:57:44 -0600 Subject: [PATCH 4/5] Bumped version to 0.1.3 --- emtools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emtools/__init__.py b/emtools/__init__.py index 011eba0..26dc68e 100644 --- a/emtools/__init__.py +++ b/emtools/__init__.py @@ -24,5 +24,5 @@ # * # ************************************************************************** -__version__ = '0.1.2' +__version__ = '0.1.3' From 077eb9b55e0fe58ca488acb95e5b11aa00574e28 Mon Sep 17 00:00:00 2001 From: "Jose M. de la Rosa" Date: Thu, 14 Nov 2024 12:02:48 -0600 Subject: [PATCH 5/5] Removed debug code --- emtools/metadata/sqlite.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/emtools/metadata/sqlite.py b/emtools/metadata/sqlite.py index e338259..119b87b 100644 --- a/emtools/metadata/sqlite.py +++ b/emtools/metadata/sqlite.py @@ -81,8 +81,6 @@ def iterTable(self, tableName, **kwargs): classes: read column names from a 'classes' table """ where = kwargs.get('where', '1') - printMap = kwargs.get('printMap', False) - query = f"SELECT * FROM {tableName} WHERE {where}" if 'start' in kwargs and 'limit' not in kwargs: @@ -102,10 +100,6 @@ def iterTable(self, tableName, **kwargs): columnsMap = {row['column_name']: row['label_property'] for row in self.iterTable(kwargs['classes'])} - if printMap: - from pprint import pprint - pprint(columnsMap) - def _row_factory(cursor, row): fields = [column[0] for column in cursor.description] return {columnsMap.get(k, k): v for k, v in zip(fields, row)}