import argparse
import pickle
import numpy as np
import pandas as pd
from basedir import TEST

def main():
    breakpoint()
    data = pd.read_csv(TEST, low_memory=False) 
    with open('meta.pickle', 'rb') as file:
        meta = pickle.load(file)
    info = meta['info']
    name_info = sorted(list(info.items()), key=lambda pair: pair[1]['order'])
    prepared = []
    print('Converting test data into format suitable for predictions...')
    for name, info in name_info:
        print(f'Processing column: {name}')
        col = data[name].copy()
        if 'impute' in info:
             col[pd.isnull(col)] = info['impute']
        if 'encode' in info:
             col = col.map(info['encode'])
        col = col.values.astype(np.float32)
        prepared.append(col.reshape(-1, 1))
    X = np.hstack(prepared)
    np.savez('test.npz', data=X, id=data['MachineIdentifier'].values)
    print('Done!')

if __name__ == '__main__':
    main()
