NetchkWriter.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # from . import DataHandler #此时是导入文件
  2. from .DataStream import DataWriteStream, day_stamp
  3. from .DataStream import ENetPosmap as pos_map
  4. import numpy as np
  5. __all__ = ['NetchkWriter']
  6. import logging
  7. log = logging.getLogger('writer')
  8. class NetchkWriter(DataWriteStream):
  9. def write(self, method, params):
  10. if method == 'net_succ':
  11. self._onSucc(params)
  12. elif method == 'net_fail':
  13. self._onFail(params)
  14. else:
  15. pass
  16. def _onSucc(self, params):
  17. def parse(input):
  18. return input['channel_name'], input['time']
  19. chname, time = parse(params)
  20. path, pos = self.path_pos(chname, time)
  21. self.file[path][pos_map.succ_count, pos] += 1
  22. pass
  23. def _onFail(self, params):
  24. def parse(input):
  25. return input['channel_name'], input['time']
  26. chname, time = parse(params)
  27. path, pos = self.path_pos(chname, time)
  28. self.file[path][pos_map.fail_count, pos] += 1
  29. pass
  30. def path_pos(self, chname, time):
  31. today = day_stamp(time)
  32. path = f'/{self._version}/{today}/{chname}'
  33. hfive = self.file
  34. if path not in hfive:
  35. dim = pos_map.dim()
  36. hfive[path] = np.zeros((dim, 86400))
  37. return path, time - today
  38. pass