Skip to content

Commit

Permalink
Merge pull request #1079 from lnls-sirius/add-method-clientarch
Browse files Browse the repository at this point in the history
Add getRecentlyModifiedPVs method to ClientArchiver
  • Loading branch information
xresende authored Mar 11, 2024
2 parents 20dc9a9 + 89d2594 commit a223e18
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
28 changes: 26 additions & 2 deletions siriuspy/siriuspy/clientarch/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/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
Expand All @@ -16,6 +18,7 @@

from .. import envars as _envars
from . import exceptions as _exceptions
from .time import Time as _Time


class ClientArchiver:
Expand Down Expand Up @@ -134,6 +137,27 @@ def getPausedPVsReport(self):
resp = self._make_request(url, return_json=True)
return None if not resp else resp

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):
"""Pause PVs."""
if not isinstance(pvnames, (list, tuple)):
Expand Down
12 changes: 9 additions & 3 deletions siriuspy/siriuspy/clientarch/pvarch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = timeout
data = self.connector.getPVDetails(self.pvname)
if not data:
return False
Expand Down Expand Up @@ -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 = timeout
if None in (self.timestamp_start, self.timestamp_stop):
print('Start and stop timestamps not defined! Aborting.')
return
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions siriuspy/siriuspy/clientarch/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a223e18

Please sign in to comment.