Skip to content

Commit

Permalink
Update clientarch Time and ClientArch
Browse files Browse the repository at this point in the history
  • Loading branch information
xresende committed Mar 7, 2024
1 parent 7076c56 commit c2035de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
16 changes: 14 additions & 2 deletions siriuspy/siriuspy/clientarch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
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 c2035de

Please sign in to comment.