NetchkWriter.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. log.debug("%s,%s", 'NetchkWriter', path)
  34. hfive = self.file
  35. if path not in hfive:
  36. dim = pos_map.dim()
  37. hfive[path] = np.zeros((dim, 86400))
  38. return path, time - today
  39. pass