# -*- coding: utf-8 -*-
"""
Preprocessing
"""

import pickle
import numpy as np

import pickle


# Load
file_path = ".data.pkl"
with open(file_path, "rb") as f:
    data = pickle.load(f)

# List
methods = data[0]["results"].keys()
metrics = data[0]["results"][list(methods)[0]].keys()


# Store
avg_results = {}
std_results = {}

methods = data[0]["results"].keys()
metrics = data[0]["results"][list(methods)[0]].keys()

for method in methods:
    avg_results[method] = {}
    std_results[method] = {}

    for metric in metrics:
        sims = [np.array(sim["results"][method][metric], dtype=float) for sim in data]
        mat = np.vstack(sims)

        avg_results[method][metric] = mat.mean(axis=0).tolist()
        std_results[method][metric] = mat.std(axis=0).tolist()

# Save
data_avg = [avg_results, std_results]

with open("./data/data_avg.pkl", "wb") as f:
    pickle.dump(data_avg, f)

print("Saved")



