123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- from .CalcBase import CalcBase
- from .DataStream import EMchPosmap as pos_map, span_days
- from .MerchantReader import MerchantReader
- from .algorithm import calc_morder_lack
- import logging
- logger = logging.getLogger('MerchantCalc')
- def detail_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
- count = len(days)
- for mchid, tup in tuple_pathes.items():
- for _card_type, _spec in tup:
- detail_datas = reader.init_data(count)
- for i, day in enumerate(days):
- data = reader.read(day, mchid, _card_type, _spec)
- if data is not None:
- column_pos = i * 86400
- view = detail_datas[:, column_pos:column_pos + 86400]
- view += data
- yield mchid, _card_type, _spec, detail_datas
- def mch_detail_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
- count = len(days)
- for mchid, tup in tuple_pathes.items():
- mch_datas = reader.init_data(count)
- for _card_type, _spec in tup:
- detail_datas = reader.init_data(count)
- for i, day in enumerate(days):
- data = reader.read(day, mchid, _card_type, _spec)
- if data is not None:
- column_pos = i * 86400
- view = detail_datas[:, column_pos:column_pos + 86400]
- view += data
- view = mch_datas[:, column_pos:column_pos + 86400]
- view += data
- yield mchid, _card_type, _spec, detail_datas
- yield mchid, None, None, mch_datas
- def mch_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
- count = len(days)
- for mchid, tup in tuple_pathes.items():
- mch_datas = reader.init_data(count)
- for _card_type, _spec in tup:
- for i, day in enumerate(days):
- data = reader.read(day, mchid, _card_type, _spec)
- if data is not None:
- column_pos = i * 86400
- view = mch_datas[:, column_pos:column_pos + 86400]
- view += data
- yield mchid, None, None, mch_datas
- def mch_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
- count = len(days)
- for mchid, tup in tuple_pathes.items():
- mch_datas = reader.init_data(count)
- for _card_type, _spec in tup:
- for i, day in enumerate(days):
- data = reader.read(day, mchid, _card_type, _spec)
- if data is not None:
- column_pos = i * 86400
- view = mch_datas[:, column_pos:column_pos + 86400]
- view += data
- yield mchid, None, None, mch_datas
- def mch_cardtype_paths(reader: MerchantReader, tuple_pathes: dict, days: list):
- def split_card(card_specs):
- result = dict()
- for card_type,spec in card_specs:
- if card_type not in result:
- result[card_type] = []
- result[card_type].append(spec)
- return result
- count = len(days)
- for mchid, tup in tuple_pathes.items():
- mch_datas = reader.init_data(count)
- card_specs = split_card(tup)
- for _card_type, specs in card_specs.items():
- card_type_data = reader.init_data(count)
- for _spec in specs:
- for i, day in enumerate(days):
- data = reader.read(day, mchid, _card_type, _spec)
- if data is not None:
- column_pos = i * 86400
- view = mch_datas[:, column_pos:column_pos + 86400]
- view += data
- view = card_type_data[:, column_pos:column_pos + 86400]
- view += data
- yield mchid, _card_type, None, card_type_data
- yield mchid, None, None, mch_datas
- def allpathes(reader: MerchantReader, tuple_pathes: dict, days: list, spec=None):
- count = len(days)
- show_detail = True if len(list(tuple_pathes.keys())) == 1 else False
- if show_detail == False:
- all_datas = reader.init_data(count)
- else:
- all_datas = None
- for mchid, tup in tuple_pathes.items():
- add_mchid(mchid)
- mch_datas = reader.init_data(count)
- for _card_type, _spec in tup:
- if spec is not None and _spec != spec:
- continue
- if show_detail:
- detail_datas = reader.init_data(count)
- else:
- detail_datas = None
- for i, day in enumerate(days):
- data = reader.read(day, mchid, _card_type, _spec)
- if data is not None:
- column_pos = i * 86400
- view = mch_datas[:, column_pos:column_pos + 86400]
- view += data
- if show_detail:
- view = detail_datas[:, column_pos:column_pos + 86400]
- view += data
- if show_detail:
- yield mchid, _card_type, _spec, detail_datas
- if all_datas is not None:
- all_datas += mch_datas
- yield mchid, None, None, mch_datas
- if show_detail == False:
- yield 'all', None, None, all_datas
- class MerchantCalc(CalcBase):
- def _reader(self):
- return MerchantReader()
- pass
|