def __init_logger(): # Removes previous handler for handler in logging.root.handlers[:]: logging.root.removeHandler(handler) levels = { "info": logging.INFO, "debug": logging.DEBUG, "warning": logging.WARNING, "error": logging.ERROR, "critical": logging.CRITICAL } try: level = levels[cfg.params["logger"]["level"]] except KeyError: sys.exit(1) if cfg.params["logger"]["file"] or cfg.params["batch"] is not None: log_filename = get_output_dir_name() + "log" try: os.remove(log_filename) except OSError: pass logging.basicConfig(format=cfg.LOG_FORMAT, filename=log_filename, level=level) else: coloredlogs.install(level=level, fmt=cfg.LOG_FORMAT) return logging.getLogger(__name__)
def save_fig(fig_name, dataframe, kind): """Saves the given dataframe to a figure file.""" filename = "%s%s.png" % (get_output_dir_name(), fig_name) plt.clf() plt.figure(figsize=Config.OUTPUT_FIG_SIZE) dataframe.plot(kind=kind) plt.tight_layout() plt.savefig(filename, dpi=Config.OUTPUT_FIG_DPI)
def __save_metrics(self): """Saves the output metrics of the simulation to a JSON file.""" filename = "%smetrics.json" % get_output_dir_name() response = { "avg_active_aircrafts": self.aircraft_count_metric.avg_n_aircrafts, "conflicts": self.conflict_metric.conflicts, "makespan": self.makespan_metric.makespan, "avg_queue_size": self.gate_queue_metric.avg_queue_size, "avg_reschedule_exec_time": self.execution_time_metric.avg_reschedule_exec_time, "n_delay": self.delay_metric.n_delay, "n_scheduler_delay": self.delay_metric.n_scheduler_delay, "n_uncertainty_delay": self.delay_metric.n_uncertainty_delay } with open(filename, "w") as fout: fout.write(json.dumps(response, indent=4)) self.logger.info("Output metrics saved to %s", filename)
def save_csv(type_name, dataframe): """Saves the given dataframe to a csv file.""" filename = "%s%s.csv" % (get_output_dir_name(), type_name) dataframe.to_csv(filename)
def __save_airport_name(self): filename = "%sairport.txt" % get_output_dir_name() with open(filename, "w") as fout: fout.write(self.airport_name) self.logger.info("Airport name logged to %s", filename)
def output_filename(self): """Gets the output filename of json file storing all the states.""" return get_output_dir_name() + "states.json"