# Analysis the data generated from on policy simulations of QL, QLP and GQL.

from BD.sim.sims import sims_analysis, merge_sim_files, extract_run_rew
from BD.util.paths import Paths


def sims_analysis_BD():
    input_folder = Paths.rest_path + 'archive/beh/qlp-ml-opt/qlp-ml/'
    sims_analysis(input_folder,
                  Paths.local_path + 'BD/to_graph_data/qlp_ml_onpolicy__stats.csv',
                  lambda conf: True
                  )

    input_folder = Paths.rest_path + 'archive/beh/ql-ml-opt/ql-ml/'
    sims_analysis(input_folder,
                  Paths.local_path + 'BD/to_graph_data/ql_ml_onpolicy_stats.csv',
                  lambda conf: True
                  )


def sims_analysis_GQL_BD():
    input_folder = Paths.rest_path + 'archive/beh/gql-ml-opt/gql-ml/'

    sims_analysis(input_folder,
                  Paths.local_path + 'BD/to_graph_data/gql_ml_onpolicy_stats.csv',
                  lambda conf: True
                  )

    input_folder = Paths.rest_path + 'archive/beh/gql10d-ml-opt/gql10d-ml/'

    sims_analysis(input_folder,
                  Paths.local_path + 'BD/to_graph_data/gql10d_ml_onpolicy_stats.csv',
                  lambda conf: True
                  )


if __name__ == '__main__':
    sims_analysis_BD()
    sims_analysis_GQL_BD()

    data = merge_sim_files(lambda x: True, Paths.rest_path + 'archive/beh/gql10d-ml-opt/gql10d-ml/')
    all_trials = extract_run_rew(data)

    output_file = Paths.local_path + 'BD/to_graph_data/gql10d_all_data_ml.csv'
    all_trials.to_csv(output_file, header=True)

    data = merge_sim_files(lambda x: True, Paths.rest_path + 'archive/beh/gql-ml-opt/gql-ml/')
    all_trials = extract_run_rew(data)

    output_file = Paths.local_path + 'BD/to_graph_data/gql_all_data_ml.csv'
    all_trials.to_csv(output_file, header=True)

[((282, 398), 'BD.sim.sims.sims_analysis', 'sims_analysis', (['input_folder', "(Paths.local_path + 'BD/to_graph_data/qlp_ml_onpolicy__stats.csv')", '(lambda conf: True)'], {}), "(input_folder, Paths.local_path +\n    'BD/to_graph_data/qlp_ml_onpolicy__stats.csv', lambda conf: True)\n", (295, 398), False, 'from BD.sim.sims import sims_analysis, merge_sim_files, extract_run_rew\n'), ((523, 637), 'BD.sim.sims.sims_analysis', 'sims_analysis', (['input_folder', "(Paths.local_path + 'BD/to_graph_data/ql_ml_onpolicy_stats.csv')", '(lambda conf: True)'], {}), "(input_folder, Paths.local_path +\n    'BD/to_graph_data/ql_ml_onpolicy_stats.csv', lambda conf: True)\n", (536, 637), False, 'from BD.sim.sims import sims_analysis, merge_sim_files, extract_run_rew\n'), ((794, 909), 'BD.sim.sims.sims_analysis', 'sims_analysis', (['input_folder', "(Paths.local_path + 'BD/to_graph_data/gql_ml_onpolicy_stats.csv')", '(lambda conf: True)'], {}), "(input_folder, Paths.local_path +\n    'BD/to_graph_data/gql_ml_onpolicy_stats.csv', lambda conf: True)\n", (807, 909), False, 'from BD.sim.sims import sims_analysis, merge_sim_files, extract_run_rew\n'), ((1043, 1161), 'BD.sim.sims.sims_analysis', 'sims_analysis', (['input_folder', "(Paths.local_path + 'BD/to_graph_data/gql10d_ml_onpolicy_stats.csv')", '(lambda conf: True)'], {}), "(input_folder, Paths.local_path +\n    'BD/to_graph_data/gql10d_ml_onpolicy_stats.csv', lambda conf: True)\n", (1056, 1161), False, 'from BD.sim.sims import sims_analysis, merge_sim_files, extract_run_rew\n'), ((1304, 1397), 'BD.sim.sims.merge_sim_files', 'merge_sim_files', (['(lambda x: True)', "(Paths.rest_path + 'archive/beh/gql10d-ml-opt/gql10d-ml/')"], {}), "(lambda x: True, Paths.rest_path +\n    'archive/beh/gql10d-ml-opt/gql10d-ml/')\n", (1319, 1397), False, 'from BD.sim.sims import sims_analysis, merge_sim_files, extract_run_rew\n'), ((1411, 1432), 'BD.sim.sims.extract_run_rew', 'extract_run_rew', (['data'], {}), '(data)\n', (1426, 1432), False, 'from BD.sim.sims import sims_analysis, merge_sim_files, extract_run_rew\n'), ((1573, 1660), 'BD.sim.sims.merge_sim_files', 'merge_sim_files', (['(lambda x: True)', "(Paths.rest_path + 'archive/beh/gql-ml-opt/gql-ml/')"], {}), "(lambda x: True, Paths.rest_path +\n    'archive/beh/gql-ml-opt/gql-ml/')\n", (1588, 1660), False, 'from BD.sim.sims import sims_analysis, merge_sim_files, extract_run_rew\n'), ((1674, 1695), 'BD.sim.sims.extract_run_rew', 'extract_run_rew', (['data'], {}), '(data)\n', (1689, 1695), False, 'from BD.sim.sims import sims_analysis, merge_sim_files, extract_run_rew\n')]