# from . import DataHandler #此时是导入文件 from .DataStream import DataWriteStream, ChPosmap, day_stamp import numpy as np __all__ = ['ChannelWriter'] class ChannelWriter(DataWriteStream, ChPosmap): def write(self, method, params): if method == 'refill_commit': self._onCommit(params) elif method == 'notify_succ': self._onSucc(params) elif method == 'notify_fail': self._onFail(params) else: pass def _onCommit(self, params): def parse(input): return input['channel_name'], input['time'], input['spec'], input['card_type'], input['channel_amount'] chname, time, spec, card_type, channel_amount = parse(params) path, pos = self.path_pos(chname, time, spec, card_type) self.file[path][self._pos_map['commit_count'], pos] += 1 self.file[path][self._pos_map['commit_amounts'], pos] += channel_amount pass def _onSucc(self, params): def parse(input): return input['channel_name'], input['time'], input['spec'], input['card_type'], input['channel_amount'], input['period'] chname, time, spec, card_type, channel_amount, period = parse(params) path, pos = self.path_pos(chname, time, spec, card_type) self.file[path][self._pos_map['succ_count'], pos] += 1 self.file[path][self._pos_map['succ_amounts'], pos] += channel_amount self.file[path][self._pos_map['succ_periods'], pos] += period pass def _onFail(self, params): def parse(input): return input['channel_name'], input['time'], input['spec'], input['card_type'], input['channel_amount'], input['period'] chname, time, spec, card_type, channel_amount, period = parse(params) path, pos = self.path_pos(chname, time, spec, card_type) self.file[path][self._pos_map['fail_count'], pos] += 1 self.file[path][self._pos_map['fail_amounts'], pos] += channel_amount self.file[path][self._pos_map['fail_periods'], pos] += period pass def path_pos(self, chname, time, spec, card_type): today = day_stamp(time) path = f'/{self._version}/{today}/{chname}/{card_type}/{spec}' hfive = self.file if path not in hfive: dim = len(self._pos_map) hfive[path] = np.zeros((dim, 86400)) return path, time - today