# -*- coding: utf-8 -*-
"""
Created on Mon Dec  6 14:51:24 2021

@author: laukkara

This script is run first to fetch results data from university's network drive

"""
import os
import pickle


input_folder_for_Delphin_data = r'S:\91202_Rakfys_Mallinnus\RAMI\simulations'

output_folder = os.path.join(r'C:\Local\laukkara\Data\github\mry-cluster2\input')
    
output_pickle_file_name = 'S_RAMI.pickle'



## Preparations
if not os.path.exists(output_folder):
    os.makedirs(output_folder)

output_pickle_file_path = os.path.join(output_folder,
                                       output_pickle_file_name)

## Read in results data from pickle files
cases = {}
data = {}

cases = os.listdir(input_folder_for_Delphin_data)
cases.remove('olds')
cases.remove('RAMI_simulated_cases.xlsx')

data = {}
for case in cases:
    print('Reading:', case)
    fname = os.path.join(input_folder_for_Delphin_data, case, 'd.pickle')
    
    with open(fname, 'rb') as f:
        try:
            df = pickle.load(f)
            
            if df.shape[0] == 1200:
                data[case] = df
            else:
                print('ERROR AT:', case)
                
        except:
            print('Error when reading case:', case)

print(data[cases[0]].columns)



with open(output_pickle_file_path, 'wb') as f:
    pickle.dump(data, f)








[((16, 16, 16, 81), 'os.path.join', 'os.path.join', ({(16, 29, 16, 80): '"""C:\\\\Local\\\\laukkara\\\\Data\\\\github\\\\mry-cluster2\\\\input"""'}, {}), "('C:\\\\Local\\\\laukkara\\\\Data\\\\github\\\\mry-cluster2\\\\input')", False, 'import os\n'), ((26, 26, 27, 63), 'os.path.join', 'os.path.join', ({(26, 39, 26, 52): 'output_folder', (27, 39, 27, 62): 'output_pickle_file_name'}, {}), '(output_folder, output_pickle_file_name)', False, 'import os\n'), ((33, 8, 33, 49), 'os.listdir', 'os.listdir', ({(33, 19, 33, 48): 'input_folder_for_Delphin_data'}, {}), '(input_folder_for_Delphin_data)', False, 'import os\n'), ((23, 7, 23, 36), 'os.path.exists', 'os.path.exists', ({(23, 22, 23, 35): 'output_folder'}, {}), '(output_folder)', False, 'import os\n'), ((24, 4, 24, 30), 'os.makedirs', 'os.makedirs', ({(24, 16, 24, 29): 'output_folder'}, {}), '(output_folder)', False, 'import os\n'), ((40, 12, 40, 73), 'os.path.join', 'os.path.join', ({(40, 25, 40, 54): 'input_folder_for_Delphin_data', (40, 56, 40, 60): 'case', (40, 62, 40, 72): '"""d.pickle"""'}, {}), "(input_folder_for_Delphin_data, case, 'd.pickle')", False, 'import os\n'), ((59, 4, 59, 24), 'pickle.dump', 'pickle.dump', ({(59, 16, 59, 20): 'data', (59, 22, 59, 23): 'f'}, {}), '(data, f)', False, 'import pickle\n'), ((44, 17, 44, 31), 'pickle.load', 'pickle.load', ({(44, 29, 44, 30): 'f'}, {}), '(f)', False, 'import pickle\n')]