MerchantCalcBase.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. from .CalcBase import CalcBase
  2. from .DataStream import EMchPosmap as pos_map, span_days
  3. from .MerchantReader import MerchantReader
  4. from .algorithm import calc_morder_lack
  5. import logging
  6. logger = logging.getLogger('MerchantCalcBase')
  7. def detail_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
  8. count = len(days)
  9. for mchid, tup in tuple_pathes.items():
  10. for _card_type, _spec in tup:
  11. detail_datas = reader.init_data(count)
  12. for i, day in enumerate(days):
  13. data = reader.read(day, mchid, _card_type, _spec)
  14. if data is not None:
  15. column_pos = i * 86400
  16. view = detail_datas[:, column_pos:column_pos + 86400]
  17. view += data
  18. yield mchid, _card_type, _spec, detail_datas
  19. def mch_detail_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
  20. count = len(days)
  21. for mchid, tup in tuple_pathes.items():
  22. mch_datas = reader.init_data(count)
  23. for _card_type, _spec in tup:
  24. detail_datas = reader.init_data(count)
  25. for i, day in enumerate(days):
  26. data = reader.read(day, mchid, _card_type, _spec)
  27. if data is not None:
  28. column_pos = i * 86400
  29. view = detail_datas[:, column_pos:column_pos + 86400]
  30. view += data
  31. view = mch_datas[:, column_pos:column_pos + 86400]
  32. view += data
  33. yield mchid, _card_type, _spec, detail_datas
  34. yield mchid, None, None, mch_datas
  35. def mch_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
  36. count = len(days)
  37. for mchid, tup in tuple_pathes.items():
  38. mch_datas = reader.init_data(count)
  39. for _card_type, _spec in tup:
  40. for i, day in enumerate(days):
  41. data = reader.read(day, mchid, _card_type, _spec)
  42. if data is not None:
  43. column_pos = i * 86400
  44. view = mch_datas[:, column_pos:column_pos + 86400]
  45. view += data
  46. yield mchid, None, None, mch_datas
  47. def allpathes(reader: MerchantReader, tuple_pathes: dict, days: list, spec=None):
  48. count = len(days)
  49. show_detail = True if len(list(tuple_pathes.keys())) == 1 else False
  50. if show_detail == False:
  51. all_datas = reader.init_data(count)
  52. else:
  53. all_datas = None
  54. for mchid, tup in tuple_pathes.items():
  55. add_mchid(mchid)
  56. mch_datas = reader.init_data(count)
  57. for _card_type, _spec in tup:
  58. if spec is not None and _spec != spec:
  59. continue
  60. if show_detail:
  61. detail_datas = reader.init_data(count)
  62. else:
  63. detail_datas = None
  64. for i, day in enumerate(days):
  65. data = reader.read(day, mchid, _card_type, _spec)
  66. if data is not None:
  67. column_pos = i * 86400
  68. view = mch_datas[:, column_pos:column_pos + 86400]
  69. view += data
  70. if show_detail:
  71. view = detail_datas[:, column_pos:column_pos + 86400]
  72. view += data
  73. if show_detail:
  74. yield mchid, _card_type, _spec, detail_datas
  75. if all_datas is not None:
  76. all_datas += mch_datas
  77. yield mchid, None, None, mch_datas
  78. if show_detail == False:
  79. yield 'all', None, None, all_datas
  80. class MerchantCalcBase(CalcBase):
  81. def _reader(self):
  82. return MerchantReader()
  83. pass