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 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