import numpy as np
%run 'preprocessor.ipynb' #our own preprocessor functions

"""
Explanation: Simple 2D Plots using Matplotlib
Week 4 onwards (Term 2)
Import dependencies
End of explanation
"""


with open('/Users/timothy/Desktop/Files/data_new/merged.csv', 'r') as f:
      reader = csv.reader(f)
      data = list(reader)

"""
Explanation: Load the dataset from the csv file
End of explanation
"""


matrix = obtain_data_matrix(data)
samples = len(matrix)
print("Number of samples: " + str(samples))

"""
Explanation: Process the data
We will output the data in the form of a numpy matrix using our preprocessing functions.
The first row in the matrix (first data entry) and total number of samples will be displayed.
End of explanation
"""


filament = matrix[:,[8]]
time = matrix[:,[9]]
satisfaction = matrix[:,[10]]
result = matrix[:,[11]]

"""
Explanation: Prepare the individual data axis
End of explanation
"""


%config InlineBackend.figure_format = 'retina'
import matplotlib.pyplot as plt

plt.figure(1,figsize=(12,8))
plt.xlabel('Print Time (mins)')
plt.ylabel('Filament (m)')
plt.title('Prints (Combined)')

plt.figure(2,figsize=(12,8))
plt.xlabel('Print Time (mins)')
plt.ylabel('Filament (m)')
plt.title('Prints (Failed Focus)')

plt.figure(3,figsize=(10,8))
plt.xlabel('Print Time (mins)')
plt.ylabel('Filament (m)')
plt.title('Prints (Success Only)')

for data in matrix:
    filament = [data[0][:,8]]
    time = [data[0][:,9]]
    satisfaction = [data[:,[10]]]
    result = [data[:,[11]]]
    result_success = [[1]]
    if result[0] == result_success:
        plt.figure(1)
        plt.scatter(time, filament, c="green", alpha=0.5,)
        plt.figure(2)
        plt.scatter(time, filament, c="green", alpha=0.1,)
        plt.figure(3)
        plt.scatter(time, filament, c="green", alpha=1,)
    else:
        plt.figure(1)
        plt.scatter(time, filament, c="red", alpha=0.5,)
        plt.figure(2)
        plt.scatter(time, filament, c="red", alpha=1,)
        
plt.tight_layout()
plt.show()

"""
Explanation: Plot the data in 2D
End of explanation
"""


