|
@@ -6,8 +6,10 @@ import numpy as np
|
|
|
__all__ = ['ChannelWriter']
|
|
|
|
|
|
import logging
|
|
|
+
|
|
|
log = logging.getLogger('writer')
|
|
|
|
|
|
+
|
|
|
class ChannelWriter(DataWriteStream):
|
|
|
def __init__(self, hfive):
|
|
|
DataWriteStream.__init__(self, hfive)
|
|
@@ -37,10 +39,13 @@ class ChannelWriter(DataWriteStream):
|
|
|
def _write_batch(self, path, messages):
|
|
|
def _commit(input):
|
|
|
return input['time'], input['channel_amount']
|
|
|
+
|
|
|
def _succ(input):
|
|
|
return input['time'], input['channel_amount'], input['period']
|
|
|
+
|
|
|
def _fail(input):
|
|
|
return input['time'], input['channel_amount'], input['period']
|
|
|
+
|
|
|
def _pos(time):
|
|
|
today = day_stamp(time)
|
|
|
return time - today
|
|
@@ -83,13 +88,17 @@ class ChannelWriter(DataWriteStream):
|
|
|
|
|
|
def _onSucc(self, params):
|
|
|
def parse(input):
|
|
|
- return input['channel_name'], input['time'], input['spec'], input['card_type'], input['channel_amount'], input['period']
|
|
|
+ mch_amount = 0 if 'mch_amount' not in input else input['mch_amount']
|
|
|
+ return input['channel_name'], input['time'], input['spec'], input['card_type'], input['channel_amount'], input['period'], mch_amount
|
|
|
|
|
|
- chname, time, spec, card_type, channel_amount, period = parse(params)
|
|
|
+ chname, time, spec, card_type, channel_amount, period, mch_amount = parse(params)
|
|
|
dset, pos = self.path_pos(chname, time, spec, card_type)
|
|
|
-
|
|
|
- rows = [pos_map.succ_count, pos_map.succ_amounts, pos_map.succ_periods]
|
|
|
- vals = [1, channel_amount, period]
|
|
|
+ if dset.shape[0] == pos_map.dim():
|
|
|
+ rows = [pos_map.succ_count, pos_map.succ_amounts, pos_map.succ_periods, pos_map.succ_mch_amounts]
|
|
|
+ vals = [1, channel_amount, period, mch_amount]
|
|
|
+ else:
|
|
|
+ rows = [pos_map.succ_count, pos_map.succ_amounts, pos_map.succ_periods]
|
|
|
+ vals = [1, channel_amount, period]
|
|
|
dset[rows, pos] += vals
|
|
|
pass
|
|
|
|
|
@@ -108,13 +117,14 @@ class ChannelWriter(DataWriteStream):
|
|
|
def get_path(self, method, params):
|
|
|
def _parse(input):
|
|
|
return input['channel_name'], input['time'], input['spec'], input['card_type']
|
|
|
+
|
|
|
def _path(input):
|
|
|
chname, time, spec, card_type = _parse(input)
|
|
|
today = day_stamp(time)
|
|
|
path = f'/{self._version}/{today}/{chname}/{card_type}/{spec}'
|
|
|
return path
|
|
|
|
|
|
- if method in ['ch_commit','ch_succ','ch_fail']:
|
|
|
+ if method in ['ch_commit', 'ch_succ', 'ch_fail']:
|
|
|
path = _path(params)
|
|
|
return path
|
|
|
else:
|