From 3e886efd43ee7dfaa7467b7d55ad4f8026fcafe3 Mon Sep 17 00:00:00 2001 From: ximenes Date: Thu, 7 Mar 2024 00:10:53 -0300 Subject: [PATCH 1/6] Add getRecentlyModifiedPVs method to ClientArchiver --- siriuspy/siriuspy/clientarch/client.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/siriuspy/siriuspy/clientarch/client.py b/siriuspy/siriuspy/clientarch/client.py index 189ccd61f..4d88441f3 100644 --- a/siriuspy/siriuspy/clientarch/client.py +++ b/siriuspy/siriuspy/clientarch/client.py @@ -1,7 +1,10 @@ #!/usr/bin/env python-sirius """Fetcher module. -See https://slacmshankar.github.io/epicsarchiver_docs/userguide.html +See + https://slacmshankar.github.io/epicsarchiver_docs/userguide.html + http://slacmshankar.github.io/epicsarchiver_docs/details.html + http://slacmshankar.github.io/epicsarchiver_docs/api/mgmt_scriptables.html """ from threading import Thread as _Thread @@ -134,6 +137,18 @@ def getPausedPVsReport(self): resp = self._make_request(url, return_json=True) return None if not resp else resp + def getRecentlyModifiedPVs(self, limit=None): + """Get recently modified PVs. + + Currently version of the epics archiver appliance returns pvname + list from oldest to newest modified timestamps.""" + method = 'getRecentlyModifiedPVs' + if limit is not None: + method += f'?limit={str(limit)}' + url = self._create_url(method=method) + resp = self._make_request(url, return_json=True) + return None if not resp else resp + def pausePVs(self, pvnames): """Pause PVs.""" if not isinstance(pvnames, (list, tuple)): From 7076c566dca5df1a6a83ea4058b9e548e37bbde0 Mon Sep 17 00:00:00 2001 From: ximenes Date: Thu, 7 Mar 2024 00:12:32 -0300 Subject: [PATCH 2/6] Remove inappropriate she-bang in clientarch --- siriuspy/siriuspy/clientarch/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/siriuspy/siriuspy/clientarch/client.py b/siriuspy/siriuspy/clientarch/client.py index 4d88441f3..65f9a7e30 100644 --- a/siriuspy/siriuspy/clientarch/client.py +++ b/siriuspy/siriuspy/clientarch/client.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python-sirius """Fetcher module. See From c2035defb6b61dd019d9ede8465896e65f55f120 Mon Sep 17 00:00:00 2001 From: ximenes Date: Thu, 7 Mar 2024 13:59:50 -0300 Subject: [PATCH 3/6] Update clientarch Time and ClientArch --- siriuspy/siriuspy/clientarch/client.py | 16 ++++++++++++++-- siriuspy/siriuspy/clientarch/time.py | 8 ++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/siriuspy/siriuspy/clientarch/client.py b/siriuspy/siriuspy/clientarch/client.py index 65f9a7e30..67acaa8c0 100644 --- a/siriuspy/siriuspy/clientarch/client.py +++ b/siriuspy/siriuspy/clientarch/client.py @@ -13,11 +13,14 @@ import logging as _log import urllib3 as _urllib3 from aiohttp import ClientSession as _ClientSession +# from datetime import datetime as _datetime +# from calendar import timegm as _timegm import numpy as _np from .. import envars as _envars from . import exceptions as _exceptions +from .time import Time as _Time class ClientArchiver: @@ -136,16 +139,25 @@ def getPausedPVsReport(self): resp = self._make_request(url, return_json=True) return None if not resp else resp - def getRecentlyModifiedPVs(self, limit=None): - """Get recently modified PVs. + def getRecentlyModifiedPVs(self, limit=None, epoch_time=True): + """Get list of PVs with recently modified PVTypeInfo. Currently version of the epics archiver appliance returns pvname list from oldest to newest modified timestamps.""" method = 'getRecentlyModifiedPVs' + # get data if limit is not None: method += f'?limit={str(limit)}' url = self._create_url(method=method) resp = self._make_request(url, return_json=True) + + # convert to epoch, if the case + if resp and epoch_time: + for item in resp: + modtime = item['modificationTime'][:-7] # remove ISO8601 offset + epoch_time = _Time.conv_to_epoch(modtime, '%b/%d/%Y %H:%M:%S') + item['modificationTime'] = epoch_time + return None if not resp else resp def pausePVs(self, pvnames): diff --git a/siriuspy/siriuspy/clientarch/time.py b/siriuspy/siriuspy/clientarch/time.py index 899573812..9983cd1e5 100644 --- a/siriuspy/siriuspy/clientarch/time.py +++ b/siriuspy/siriuspy/clientarch/time.py @@ -2,6 +2,7 @@ from . import exceptions as _exceptions from datetime import datetime as _datetime, timedelta as _timedelta +from calendar import timegm as _timegm class Time(_datetime): @@ -94,6 +95,13 @@ def __sub__(self, other): sub = super().__sub__(other) return Time(timestamp=sub.timestamp()) + @staticmethod + def conv_to_epoch(time, datetime_format): + """get epoch from datetime.""" + utc_time = _datetime.strptime(time, datetime_format) + epoch_time = _timegm(utc_time.timetuple()) + return epoch_time + def get_time_intervals( time_start, time_stop, interval, return_isoformat=False): From 01a6405d251c042b5c3f3e1b426953e64081463a Mon Sep 17 00:00:00 2001 From: ximenes Date: Thu, 7 Mar 2024 14:08:32 -0300 Subject: [PATCH 4/6] Add timeout arg to update methods in pvarch classes --- siriuspy/siriuspy/clientarch/pvarch.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/siriuspy/siriuspy/clientarch/pvarch.py b/siriuspy/siriuspy/clientarch/pvarch.py index d481d552a..ab0dede75 100644 --- a/siriuspy/siriuspy/clientarch/pvarch.py +++ b/siriuspy/siriuspy/clientarch/pvarch.py @@ -112,9 +112,11 @@ def is_archived(self): return False return True - def update(self): + def update(self, timeout=None): """.""" self.connect() + if timeout is not None: + self.timeout = None data = self.connector.getPVDetails(self.pvname) if not data: return False @@ -280,9 +282,11 @@ def severity(self): """Severity data.""" return self._severity - def update(self, mean_sec=None, parallel=True): + def update(self, mean_sec=None, parallel=True, timeout=None): """Update.""" self.connect() + if timeout is not None: + self.timeout = None if None in (self.timestamp_start, self.timestamp_stop): print('Start and stop timestamps not defined! Aborting.') return @@ -493,9 +497,11 @@ def parallel_query_bin_interval(self, new_intvl): self._pvdata[pvname].parallel_query_bin_interval = \ self._parallel_query_bin_interval - def update(self, mean_sec=None, parallel=True): + def update(self, mean_sec=None, parallel=True, timeout=None): """Update.""" self.connect() + if timeout is not None: + self.timeout = None if None in (self.timestamp_start, self.timestamp_stop): print('Start and stop timestamps not defined! Aborting.') return From a5b9a76ace8cdf8183150fceceb93095124a588b Mon Sep 17 00:00:00 2001 From: ximenes Date: Mon, 11 Mar 2024 10:35:59 -0300 Subject: [PATCH 5/6] Fix wrong timeout impl. in pvarch --- siriuspy/siriuspy/clientarch/pvarch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/siriuspy/siriuspy/clientarch/pvarch.py b/siriuspy/siriuspy/clientarch/pvarch.py index ab0dede75..ad0d81a22 100644 --- a/siriuspy/siriuspy/clientarch/pvarch.py +++ b/siriuspy/siriuspy/clientarch/pvarch.py @@ -116,7 +116,7 @@ def update(self, timeout=None): """.""" self.connect() if timeout is not None: - self.timeout = None + self.timeout = timeout data = self.connector.getPVDetails(self.pvname) if not data: return False @@ -286,7 +286,7 @@ def update(self, mean_sec=None, parallel=True, timeout=None): """Update.""" self.connect() if timeout is not None: - self.timeout = None + self.timeout = timeout if None in (self.timestamp_start, self.timestamp_stop): print('Start and stop timestamps not defined! Aborting.') return From 89d25945249c3f501c28c5c3b80b55e6a95d5f63 Mon Sep 17 00:00:00 2001 From: ximenes Date: Mon, 11 Mar 2024 14:44:09 -0300 Subject: [PATCH 6/6] Remove commented out lines --- siriuspy/siriuspy/clientarch/client.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/siriuspy/siriuspy/clientarch/client.py b/siriuspy/siriuspy/clientarch/client.py index 67acaa8c0..fa6c4f0d2 100644 --- a/siriuspy/siriuspy/clientarch/client.py +++ b/siriuspy/siriuspy/clientarch/client.py @@ -13,8 +13,6 @@ import logging as _log import urllib3 as _urllib3 from aiohttp import ClientSession as _ClientSession -# from datetime import datetime as _datetime -# from calendar import timegm as _timegm import numpy as _np