UserFetcher.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from Fetcher import Fetcher
  2. import re
  3. import numpy as np
  4. class UserFetcher(Fetcher):
  5. #0纬放所有数据,1纬放成功,2纬放失败
  6. pos_map = {
  7. 'commit': 0, 'success': 1, 'fail': 2
  8. }
  9. name_prefix = {
  10. 'nc_user_monitor_commit': 'commit',
  11. 'nc_user_monitor_success': 'success',
  12. 'nc_user_monitor_fail': 'fail'
  13. }
  14. def __init__(self):
  15. filename = '/var/www/html/data/stdata/user.hdf5'
  16. super().__init__(filename)
  17. pass
  18. def redis_name_prefix(self) -> dict:
  19. return self.name_prefix
  20. def parase(self, hfive, key, val, prefix,latest_time):
  21. items = re.split(r'-', key)
  22. if len(items) != 5:
  23. return True
  24. (mchid, quality, card_type, amount, time) = items
  25. pos = self.pos_map[f'{prefix}']
  26. time = int(time)
  27. today = self.day_stamp(time)
  28. path = f'/{today}/{mchid}/{quality}/{card_type}/{amount}'
  29. if path not in hfive:
  30. dim = len(self.pos_map)
  31. hfive[path] = np.zeros((dim, 86400))
  32. diff = time - today
  33. if diff < 0:
  34. print(diff)
  35. hfive[path][pos, diff] = val
  36. print(path, pos, diff, val, hfive[path][pos, diff])
  37. if time > latest_time:
  38. return False
  39. else:
  40. return True
  41. pass
  42. pass