MerchantCalc.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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('MerchantCalc')
  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 mch_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
  48. count = len(days)
  49. for mchid, tup in tuple_pathes.items():
  50. mch_datas = reader.init_data(count)
  51. for _card_type, _spec in tup:
  52. for i, day in enumerate(days):
  53. data = reader.read(day, mchid, _card_type, _spec)
  54. if data is not None:
  55. column_pos = i * 86400
  56. view = mch_datas[:, column_pos:column_pos + 86400]
  57. view += data
  58. yield mchid, None, None, mch_datas
  59. def mch_cardtype_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
  60. def split_card(card_specs):
  61. result = dict()
  62. for card_type,spec in card_specs:
  63. if card_type not in result:
  64. result[card_type] = []
  65. result[card_type].append(spec)
  66. return result
  67. count = len(days)
  68. for mchid, tup in tuple_pathes.items():
  69. mch_datas = reader.init_data(count)
  70. card_specs = split_card(tup)
  71. for _card_type, specs in card_specs.items():
  72. card_type_data = reader.init_data(count)
  73. for _spec in specs:
  74. for i, day in enumerate(days):
  75. data = reader.read(day, mchid, _card_type, _spec)
  76. if data is not None:
  77. column_pos = i * 86400
  78. view = mch_datas[:, column_pos:column_pos + 86400]
  79. view += data
  80. view = card_type_data[:, column_pos:column_pos + 86400]
  81. view += data
  82. yield mchid, _card_type, None, card_type_data
  83. yield mchid, None, None, mch_datas
  84. def allpathes(reader: MerchantReader, tuple_pathes: dict, days: list, spec=None):
  85. count = len(days)
  86. show_detail = True if len(list(tuple_pathes.keys())) == 1 else False
  87. if show_detail == False:
  88. all_datas = reader.init_data(count)
  89. else:
  90. all_datas = None
  91. for mchid, tup in tuple_pathes.items():
  92. add_mchid(mchid)
  93. mch_datas = reader.init_data(count)
  94. for _card_type, _spec in tup:
  95. if spec is not None and _spec != spec:
  96. continue
  97. if show_detail:
  98. detail_datas = reader.init_data(count)
  99. else:
  100. detail_datas = None
  101. for i, day in enumerate(days):
  102. data = reader.read(day, mchid, _card_type, _spec)
  103. if data is not None:
  104. column_pos = i * 86400
  105. view = mch_datas[:, column_pos:column_pos + 86400]
  106. view += data
  107. if show_detail:
  108. view = detail_datas[:, column_pos:column_pos + 86400]
  109. view += data
  110. if show_detail:
  111. yield mchid, _card_type, _spec, detail_datas
  112. if all_datas is not None:
  113. all_datas += mch_datas
  114. yield mchid, None, None, mch_datas
  115. if show_detail == False:
  116. yield 'all', None, None, all_datas
  117. class MerchantCalc(CalcBase):
  118. def _reader(self):
  119. return MerchantReader()
  120. pass