예제 #1
0
    def signal_handler(self, signal, frame):
        self.is_running = False

        if self._analyze is None:
            log.info('Interruption signal detected {}, exiting the '
                     'algorithm'.format(signal))

        else:
            log.info('Interruption signal detected {}, calling `analyze()` '
                     'before exiting the algorithm'.format(signal))

            algo_folder = get_algo_folder(self.algo_namespace)
            folder = join(algo_folder, 'daily_perf')
            files = [f for f in listdir(folder) if isfile(join(folder, f))]

            daily_perf_list = []
            for item in files:
                filename = join(folder, item)
                with open(filename, 'rb') as handle:
                    daily_perf_list.append(pickle.load(handle))

            stats = pd.DataFrame(daily_perf_list)

            self.analyze(stats)

        sys.exit(0)
예제 #2
0
def stats_to_algo_folder(stats, algo_namespace, recorded_cols=None):
    """
    Saves the performance stats to the algo local folder.

    Parameters
    ----------
    stats: list[Object]
    algo_namespace: str
    recorded_cols: list[str]

    Returns
    -------
    str

    """
    bytes_to_write = get_csv_stats(stats, recorded_cols=recorded_cols)

    timestr = time.strftime('%Y%m%d')
    folder = get_algo_folder(algo_namespace)

    filename = os.path.join(folder, '{}-{}.csv'.format(timestr, 'frames'))

    with open(filename, 'wb') as handle:
        handle.write(bytes_to_write)

    return bytes_to_write