Skip to content

Commit

Permalink
Merge pull request #807 from lnls-sirius/update-macreport
Browse files Browse the repository at this point in the history
Update machine reports
  • Loading branch information
anacso17 authored May 12, 2022
2 parents fe61764 + c9185e3 commit 40d7835
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 18 deletions.
6 changes: 3 additions & 3 deletions siriuspy/siriuspy/clientarch/pvarch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import numpy as _np

from mathphys.functions import save_pickle as _save_pickle, \
load_pickle as _load_pickle

from . import exceptions as _exceptions
from .client import ClientArchiver as _ClientArchiver
from .time import Time as _Time, get_time_intervals as _get_time_intervals

from mathphys.functions import save_pickle as _save_pickle, \
load_pickle as _load_pickle


class _Base:

Expand Down
1 change: 0 additions & 1 deletion siriuspy/siriuspy/clientconfigdb/pvsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def connected(self):
@property
def pvs(self):
"""Return dict with PVs and values."""
self.load()
pvslist = self._value['pvs']
pvsdict = {item[0]: item[1] for item in pvslist}
return pvsdict
Expand Down
26 changes: 22 additions & 4 deletions siriuspy/siriuspy/machshift/macreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,10 +1259,18 @@ def _compute_stats(self):
self._raw_data = dict()

# current data
self._curr_times, self._curr_values = \
_curr_times, _curr_values = \
self._get_pv_data('SI-Glob:AP-CurrInfo:Current-Mon')
self._curr_values[self._curr_values < 0] = 0
self._curr_values[self._curr_values > 500] = 0
_curr_values[_curr_values < 0] = 0
_curr_values[_curr_values > 500] = 0

# resample current data, from 1 pt in 60s, to 1pt in 5s
new_len = (len(_curr_times)-1)*12 + 1
new_times = _np.linspace(_curr_times[0], _curr_times[-1], new_len)
self._curr_times = new_times
self._curr_values = _np.interp(
new_times, _curr_times, _curr_values)

self._raw_data['Timestamp'] = self._curr_times
self._raw_data['Current'] = self._curr_values

Expand Down Expand Up @@ -1407,8 +1415,18 @@ def _compute_stats(self):
self._gamblk_fail_values.astype(int)
self._raw_data['Failures']['NoEBeam'] = \
_np.logical_not(self._is_stored_users)
self._raw_data['Failures']['WrongShift'] = \

# # # ignore wrong shift failures shorter than 60s
wrong_shift = \
1 * ((self._user_shift_progmd_values-self._user_shift_values) > 0)
ignore_wrong_shift = _np.zeros(wrong_shift.shape)
for i, val in enumerate(wrong_shift):
if i >= len(wrong_shift)-12:
break
if val == 1 and not _np.sum(wrong_shift[(i-12):(i+12)]) >= 12:
ignore_wrong_shift[i] = 1
consider_wrong_shift = wrong_shift - ignore_wrong_shift
self._raw_data['Failures']['WrongShift'] = consider_wrong_shift

self._failures_users = 1 * _np.logical_or.reduce(
[value for value in self._raw_data['Failures'].values()]) * \
Expand Down
54 changes: 44 additions & 10 deletions siriuspy/siriuspy/machshift/test_macreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
[Time(2021, 4, 1, 0, 0), Time(2021, 4, 30, 23, 59)],
[Time(2021, 5, 1, 0, 0), Time(2021, 5, 31, 23, 59)],
[Time(2021, 6, 1, 0, 0), Time(2021, 6, 30, 23, 59)],
[Time(2021, 7, 1, 0, 0), Time(2021, 7, 30, 23, 59)],
[Time(2021, 7, 1, 0, 0), Time(2021, 7, 31, 23, 59)],
[Time(2021, 8, 1, 0, 0), Time(2021, 8, 31, 23, 59)],
[Time(2021, 9, 1, 0, 0), Time(2021, 9, 30, 23, 59)],
[Time(2021, 10, 1, 0, 0), Time(2021, 10, 31, 23, 59)],
[Time(2021, 11, 1, 0, 0), Time(2021, 11, 30, 23, 59)],
[Time(2021, 12, 1, 0, 0), Time(2021, 12, 31, 23, 59)],
[Time(2022, 1, 1, 0, 0), Time(2022, 1, 31, 23, 59)],
[Time(2022, 2, 1, 0, 0), Time(2022, 2, 28, 23, 59)],
[Time(2022, 3, 1, 0, 0), Time(2022, 3, 31, 23, 59)],
]

macreports = dict()
Expand All @@ -28,19 +33,38 @@
macreports[intvl[0]].update()

mtbfs, mttrs, reliabs = dict(), dict(), dict()
progrmd, delivd, usertot = dict(), dict(), dict()
stable, unstable, relstable = dict(), dict(), dict()
for date, macr in macreports.items():
mtbfs[date] = macr.usershift_time_between_failures_average
mttrs[date] = macr.usershift_time_to_recover_average
reliabs[date] = macr.usershift_beam_reliability
progrmd[date] = macr.usershift_progmd_time
delivd[date] = macr.usershift_delivd_time
usertot[date] = macr.usershift_total_time
stable[date] = macr.usershift_total_stable_beam_time
unstable[date] = macr.usershift_total_unstable_beam_time
relstable[date] = macr.usershift_relative_stable_beam_time

str_ = '{:<12s} {:<12s} {:<12s} {:<12s}'
print(str_.format('Y-M', 'MTBF', 'MTTR', 'Reliability'))
str_ = '{:<12s} {:<9.3f} {:<9.3f} {:<9.3f}'
str_ = '{:<10s}' + '{:>16s}'*9
print(str_.format(
'Y-M', 'MTBF', 'MTTR',
'Reliability', 'Progrmd hours', 'Delivd hours', 'Total hours',
'% stable hours', 'Stable hours', 'Unstable hours'))
str_ = '{:<10s}' + ' {:>12.3f}'*9
for date in macreports:
print(str_.format(str(date.year)+'-'+str(date.month),
mtbfs[date],
mttrs[date],
reliabs[date]))
print(str_.format(
str(date.year)+'-'+str(date.month),
mtbfs[date],
mttrs[date],
reliabs[date],
progrmd[date],
delivd[date],
usertot[date],
relstable[date],
stable[date],
unstable[date],
))

fig, axs = plt.subplots(3, 1, sharex=True)
fig.set_size_inches(9, 6)
Expand All @@ -65,10 +89,20 @@
# programmed vs. delivered hours
macr = MacReport()
macr.connector.timeout = 120
macr.time_start = Time(2020, 7, 1, 0, 0)
macr.time_stop = Time(2021, 6, 30, 23, 59)
macr.time_start = Time(2021, 3, 1, 0, 0)
macr.time_stop = Time(2022, 3, 31, 23, 59)
macr.update()

print('MTBF', macr.usershift_time_between_failures_average)
print('MTTR', macr.usershift_time_to_recover_average)
print('Reliability', macr.usershift_beam_reliability)
print('Progrmd hours', macr.usershift_progmd_time)
print('Delivd hours', macr.usershift_delivd_time)
print('Total hours', macr.usershift_total_time)
print('% stable hours', macr.usershift_relative_stable_beam_time)
print('Stable hours', macr.usershift_total_stable_beam_time)
print('Unstable hours', macr.usershift_total_unstable_beam_time)

rd = macr.raw_data
dtimes = np.diff(rd['Timestamp'])
dtimes = np.r_[dtimes, dtimes[-1]]
Expand Down

0 comments on commit 40d7835

Please sign in to comment.