#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 23 21:27:33 2019

@author: kazuki.onodera
"""

import numpy as np
import pandas as pd
from multiprocessing import Pool
import utils

PREF = 'f001'

col = utils.COL_BINARY + utils.COL_CONTINUOS

def main(args):
    """
    
    input_path, output_path = '../data/train.f', f'../data/train_{PREF}.f'
    
    """
    
    input_path, output_path = args
    
    df = pd.read_feather(input_path)[col]
    
    df['Census_PrimaryDiskTotalCapacity-m-Census_SystemVolumeTotalCapacity'] = df['Census_PrimaryDiskTotalCapacity'] - df['Census_SystemVolumeTotalCapacity']
    df['Census_PrimaryDiskTotalCapacity-d-Census_SystemVolumeTotalCapacity'] = df['Census_PrimaryDiskTotalCapacity'] / df['Census_SystemVolumeTotalCapacity']
    
    df['Census_InternalPrimaryDisplayResolution'] = df['Census_InternalPrimaryDisplayResolutionHorizontal'] * df['Census_InternalPrimaryDisplayResolutionVertical']
    
    utils.reduce_mem_usage(df)
    df.add_prefix(PREF+'_').to_feather(output_path)
    
    return


# =============================================================================
# main
# =============================================================================
if __name__ == "__main__":
    utils.start(__file__)
    
    argss = []
    argss.append(['../data/train.f', f'../data/train_{PREF}.f'])
    argss.append(['../data/test.f',  f'../data/test_{PREF}.f'])
    
    pool = Pool( 2 )
    pool.map(main, argss)
    pool.close()
    
    utils.end(__file__)


