Skip to content

Commit

Permalink
ENH #166
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jun 6, 2019
1 parent abf42db commit f46f5af
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions apstools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
~cleanupText
~connect_pvlist
~device_read2table
~dictionary_table
~EmailNotifications
~ExcelDatabaseFileBase
Expand Down Expand Up @@ -34,6 +35,7 @@
#-----------------------------------------------------------------------------

from collections import OrderedDict
import datetime
from email.mime.text import MIMEText
from event_model import NumpyEncoder
import json
Expand Down Expand Up @@ -78,6 +80,28 @@ def mapper(c):
return "".join([mapper(c) for c in text])


def device_read2table(device, show_ancient=True, use_datetime=True):
"""
read an ophyd device and return a pyRestTable Table
Include an option to suppress ancient values identified
by timestamp from 1989. These are values only defined in
the original .db file.
"""
table = pyRestTable.Table()
table.labels = "name value timestamp".split()
ANCIENT_YEAR = 1989
for k, rec in device.read().items():
value = rec["value"]
ts = rec["timestamp"]
dt = datetime.datetime.fromtimestamp(ts)
if dt.year > ANCIENT_YEAR or show_ancient:
if use_datetime:
ts = dt
table.addRow((k, value, ts))
return table


def dictionary_table(dictionary, fmt="simple"):
"""
return a text table from ``dictionary``
Expand Down

0 comments on commit f46f5af

Please sign in to comment.