from matplotlib import pyplot as plt

import videoParameters
import eyeDetection
import pupilDetectionTracking
# import dataFiltering
import videoSeparation
import convertPixelToCm
import analyzeSectionOne
import analyzeSectionTwo
import analyzeSectionThree

### PART ZERO
## Inputs entering + obtaining basic video parameters

videoPath = "Videos/VargovaLast.avi"
jsonPath = "videoTrimming.json"

nameID, fps = videoParameters.videoParameters(videoPath)


### PART ONE
## Eye Detection

leftEye, rightEye = eyeDetection.eyeDetection(videoPath)


### PART TWO
## Pupil Detection and Tracking

# Pupil detection
xLE, yLE, xRE, yRE, pupilSizeLE, pupilSizeRE = pupilDetectionTracking.pupilDetectionTracking(videoPath, leftEye, rightEye, fps)

plt.plot(yLE, xLE)
plt.xlabel('Y')
plt.ylabel('X')
plt.title('X and Y Coordinates of the Left Eye')
# plt.savefig("Outputs/" + nameID + "/SectionOne" + "/" + "accelerationLE_Time.pdf")
plt.show()

plt.plot(yRE, xRE)
plt.xlabel('Y')
plt.ylabel('X')
plt.title('X and Y Coordinates of the Right Eye')
# plt.savefig("Outputs/" + nameID + "/SectionOne" + "/" + "accelerationRE_Time.pdf")
plt.show()

### PART THREE
## Signal filtering - removing blink artefacts

# dataFiltering.dataFiltering(xLE, yLE, xRE, yRE)

### PART FOUR
## DIVIDING VIDEO INTO GROUPS AS TIME INVERVALS

calibration, dynamicPart, dynamicPartOneMove, staticPartCircle, staticPartImage, staticPartText = videoSeparation.videoSeparation(jsonPath, fps, xLE, yLE, xRE, yRE)

xLEcm, yLEcm, xREcm, yREcm, calibrationXLE = convertPixelToCm.convertPixelToCm(calibration, fps, xLE, yLE, xRE, yRE)

### PART FIVE
## Results and plots

# Section I - XY COORDINATES OVER TIME, ROUTE, VELOCITY, ACCELERATION
analyzeSectionOne.analyzeSectionOne(nameID, fps, xLE, yLE, xRE, yRE, pupilSizeLE, pupilSizeRE, calibration, calibrationXLE)


# Section II - Dynamic Part
analyzeSectionTwo.analyzeSectionTwo(nameID, dynamicPart, dynamicPartOneMove, fps, xLE, yLE, xRE, yRE, xLEcm, yLEcm, xREcm, yREcm)

# Section III - Static Part
analyzeSectionThree.analyzeSectionThree(nameID, fps, staticPartCircle, staticPartImage, staticPartText, xLE, yLE, xRE, yRE, xLEcm, yLEcm, xREcm, yREcm)


