12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- # from . import DataHandler #此时是导入文件
- from .DataStream import DataWriteStream, day_stamp
- from .DataStream import ENetPosmap as pos_map
- import numpy as np
- __all__ = ['NetchkWriter']
- import logging
- log = logging.getLogger('writer')
- class NetchkWriter(DataWriteStream):
- def write(self, method, params):
- if method == 'net_succ':
- self._onSucc(params)
- elif method == 'net_fail':
- self._onFail(params)
- else:
- pass
- def _onSucc(self, params):
- def parse(input):
- return input['channel_name'], input['time']
- chname, time = parse(params)
- path, pos = self.path_pos(chname, time)
- self.file[path][pos_map.succ_count, pos] += 1
- pass
- def _onFail(self, params):
- def parse(input):
- return input['channel_name'], input['time']
- chname, time = parse(params)
- path, pos = self.path_pos(chname, time)
- self.file[path][pos_map.fail_count, pos] += 1
- pass
- def path_pos(self, chname, time):
- today = day_stamp(time)
- path = f'/{self._version}/{today}/{chname}'
- log.debug("%s,%s", 'NetchkWriter', path)
- hfive = self.file
- if path not in hfive:
- dim = pos_map.dim()
- hfive[path] = np.zeros((dim, 86400))
- return path, time - today
- pass
|