diff --git a/src/execution.py b/src/execution.py index 6b77e4d..a52cb36 100644 --- a/src/execution.py +++ b/src/execution.py @@ -14,33 +14,41 @@ def file_list(path): def create_dataframes(): - greedy = DataFrame(columns=["dataset", "distancia", "desviacion"]) - local = DataFrame(columns=["dataset", "distancia", "desviacion"]) + greedy = DataFrame() + local = DataFrame() return greedy, local def process_output(results): distances = [] + time = [] for element in results: for line in element: if line.startswith(bytes("Total distance:", encoding="utf-8")): line_elements = line.split(sep=bytes(":", encoding="utf-8")) distances.append(float(line_elements[1])) - return distances + if line.startswith(bytes("Execution time:", encoding="utf-8")): + line_elements = line.split(sep=bytes(":", encoding="utf-8")) + time.append(float(line_elements[1])) + return distances, time def populate_dataframes(greedy, local, greedy_list, local_list, dataset): - greedy_results = process_output(greedy_list) - local_results = process_output(local_list) + greedy_distances, greedy_time = process_output(greedy_list) + local_distances, local_time = process_output(local_list) greedy_dict = { "dataset": dataset.removeprefix("data/"), - "distancia": mean(greedy_results), - "desviacion": std(greedy_results), + "media distancia": mean(greedy_distances), + "desviacion distancia": std(greedy_distances), + "media tiempo": mean(greedy_time), + "desviacion tiempo": std(greedy_time), } local_dict = { "dataset": dataset.removeprefix("data/"), - "distancia": mean(local_results), - "desviacion": std(local_results), + "media distancia": mean(local_distances), + "desviacion distancia": std(local_distances), + "media tiempo": mean(local_time), + "desviacion tiempo": std(local_time), } greedy = greedy.append(greedy_dict, ignore_index=True) local = local.append(local_dict, ignore_index=True) @@ -76,13 +84,17 @@ def export_results(greedy, local): worksheet = writer.sheets[name] for index, column in enumerate(df): series = df[column] - max_length = series.astype(str).str.len().max() + max_length = max(series.astype(str).str.len().max(), len(str(series.name))) worksheet.set_column(index, index, width=max_length + 5) writer.save() -if __name__ == "__main__": +def main(): datasets = file_list(path="data/*.txt") greedy, local = create_dataframes() populated_greedy, populated_local = script_execution(datasets, greedy, local) export_results(populated_greedy, populated_local) + + +if __name__ == "__main__": + main()