import pandas
import numpy as np
from datetime import datetime
import sys

print("Read arguments from the terminal:")
for i in sys.argv[1:]:
    print(i)
    
project_data_path=sys.argv[1]
predictions_path=sys.argv[2]

print("\nLoading the real outcomes...")
real_outcomes = pandas.read_csv(project_data_path+"0_deployment_data_real_target.csv")
real_outcomes = real_outcomes[real_outcomes["person"]=="natural"]
print(real_outcomes.head())

print("\nLoading the predictions...")
predictions = pandas.read_csv(predictions_path+"predictions.csv",header=None,dtype={0: np.object, 1: np.object, 2: np.object, 3: np.int64})
print(predictions.head())
print("\nChanging column names ...")
predictions.columns = ["CustomerId","Name","person","Predictions"]
print(predictions.head())

print("\nJoining predicted and real...")
joined = predictions.merge(real_outcomes, how='inner', on=["CustomerId","Name","person"])

print("\nEvaluating the predictions...")
score = list()
for i in range(len(joined)):
    if joined["Exited"][i] == joined["Predictions"][i]:
        score.append(1)
    else:
        score.append(0)

accuracy = round( ( sum(score) / len(score) )*100, 1)

f = open(predictions_path+"validation_accuracy.txt", "a")
f.write("Date and time: {d}\nThe accuracy of the model on the new data is: {a}\n\n".format(d=datetime.now(),a=str(accuracy)+"%"))
f.close()

print("\nDone!")



