#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 19 13:38:19 2019

@author: nozhan
"""

import os
import pickle
import pandas
from sklearn.preprocessing import StandardScaler

def map_ml(dataFrame):
    """ This method takes in the dataFrame generated by convert.py and applies a pre-trained ML model to this dataFrame. """
    
    #   We read in the data
    df = dataFrame
    x  = df.iloc[:, [0, 1, 2, 3]].values
    
    #   We standardize our data
    sc = StandardScaler()
    standX = sc.fit_transform(x)
    
    #   de-serialize the trained model.
    #   Note: here path to the model.pkl is relatively HARDCODED but this is a test app. We will change this later!!!
    with open(os.path.join(os.getcwd(), 'model.pkl'), 'rb') as model:
        classifier = pickle.load(model)
    
    #   We do the prediction
    
    y_pred = classifier.predict(standX)
    
    return y_pred
    
    
    
    