Write results to an Excel file
This commit is contained in:
parent
3e0dbb9168
commit
b8b812d011
@ -3,5 +3,10 @@
|
||||
with pkgs;
|
||||
|
||||
mkShell {
|
||||
buildInputs = [ python39 python39Packages.numpy python39Packages.pandas ];
|
||||
buildInputs = [
|
||||
python39
|
||||
python39Packages.numpy
|
||||
python39Packages.pandas
|
||||
python39Packages.XlsxWriter
|
||||
];
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
from glob import glob
|
||||
from subprocess import run
|
||||
from sys import executable
|
||||
|
||||
from numpy import mean, std
|
||||
from pandas import DataFrame
|
||||
from pandas import DataFrame, ExcelWriter
|
||||
|
||||
|
||||
def file_list(path):
|
||||
@ -32,12 +33,12 @@ def populate_dataframes(greedy, local, greedy_list, local_list, dataset):
|
||||
greedy_results = process_output(greedy_list)
|
||||
local_results = process_output(local_list)
|
||||
greedy_dict = {
|
||||
"dataset": dataset,
|
||||
"dataset": dataset.removeprefix("data/"),
|
||||
"distancia": mean(greedy_results),
|
||||
"desviacion": std(greedy_results),
|
||||
}
|
||||
local_dict = {
|
||||
"dataset": dataset,
|
||||
"dataset": dataset.removeprefix("data/"),
|
||||
"distancia": mean(local_results),
|
||||
"desviacion": std(local_results),
|
||||
}
|
||||
@ -68,11 +69,20 @@ def script_execution(filenames, greedy, local, iterations=3):
|
||||
|
||||
|
||||
def export_results(greedy, local):
|
||||
greedy.to_excel()
|
||||
local.to_excel()
|
||||
dataframes = {"Greedy": greedy, "Local search": local}
|
||||
writer = ExcelWriter(path="docs/algorithm-results.xlsx", engine="xlsxwriter")
|
||||
for name, df in dataframes.items():
|
||||
df.to_excel(writer, sheet_name=name, index=False)
|
||||
worksheet = writer.sheets[name]
|
||||
for index, column in enumerate(df):
|
||||
series = df[column]
|
||||
max_length = series.astype(str).str.len().max()
|
||||
worksheet.set_column(index, index, width=max_length + 5)
|
||||
writer.save()
|
||||
|
||||
|
||||
if __name__ == "__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)
|
||||
|
Loading…
Reference in New Issue
Block a user