def executor_derived(file_path_list: List[Path], output_path: Path, **kwargs) -> Dict: debug = kwargs.pop('debug', False), logger.remove() ts = file_path_list[0].name.rstrip('.a.csv') logger.add( sys.stdout, level='DEBUG', format=f"<yellow>{ts}</yellow> - {LOGURU_FORMAT}", backtrace=True ) logger.info(f"running squeeze for {ts}") dfa = pd.read_csv(file_path_list[0].resolve(), engine='python', dtype='str', delimiter=r"\s*,\s*") dfa['real'] = dfa['real'].astype(float) dfa['predict'] = dfa['predict'].astype(float) dfb = pd.read_csv(file_path_list[1].resolve(), engine='python', dtype='str', delimiter=r"\s*,\s*") dfb['real'] = dfb['real'].astype(float) dfb['predict'] = dfb['predict'].astype(float) zero_index = (dfa.real == 0) & (dfa.predict == 0) & (dfb.real == 0) & (dfb.predict == 0) dfa = dfa[~zero_index] dfb = dfb[~zero_index] try: timestamp = int(ts) except ValueError: timestamp = ts logger.warning(f"Unresolved timestamp: {timestamp}") tic = time.time() divide = lambda x, y: np.divide(x, y, out=np.zeros_like(x), where=y != 0) model = Squeeze( data_list=[dfa, dfb], op=divide, option=SqueezeOption( debug=debug, fig_save_path=f"{output_path.resolve()}/{timestamp}" + "{suffix}" + ".pdf", enable_filter=True, **kwargs, ) ) model.run() logger.info("\n" + model.report) try: root_cause = AC.batch_to_string( frozenset(reduce(lambda x, y: x.union(y), model.root_cause, set()))) # type: except IndexError: root_cause = "" toc = time.time() elapsed_time = toc - tic return { 'timestamp': timestamp, 'elapsed_time': elapsed_time, 'root_cause': root_cause, }
def executor(file_path: Path, output_path: Path, **kwargs) -> Dict: debug = kwargs.pop('debug', False), logger.remove() logger.add( sys.stdout, level='DEBUG', format=f"<yellow>{file_path.name}</yellow> - {LOGURU_FORMAT}", backtrace=True ) logger.info(f"running squeeze for {file_path}") df = pd.read_csv(file_path.resolve(), engine='python', dtype='str', delimiter=r"\s*,\s*") df['real'] = df['real'].astype(float) df['predict'] = df['predict'].astype(float) try: timestamp = int(file_path.name.rstrip('.csv')) except ValueError: timestamp = file_path.name.rstrip('.csv') logger.warning(f"Unresolved timestamp: {timestamp}") tic = time.time() model = Squeeze( data_list=[df], op=lambda x: x, option=SqueezeOption( debug=debug, fig_save_path=f"{output_path.resolve()}/{timestamp}" + "{suffix}" + ".pdf", **kwargs, ) ) model.run() logger.info("\n" + model.report) try: root_cause = AC.batch_to_string( frozenset(reduce(lambda x, y: x.union(y), model.root_cause, set()))) # type: except IndexError: root_cause = "" toc = time.time() elapsed_time = toc - tic return { 'timestamp': timestamp, 'elapsed_time': elapsed_time, 'root_cause': root_cause, }