# -*- coding: utf-8 -*-
#This file generates the drive team input
import wx
import csv
import module_locator
import json
import os
from datetime import datetime
from pathlib2 import Path

#locate the Package
myPath = module_locator.module_path()

#import match schedule from json generated by PullMatchSchedule.py
matchSchedule = json.load(open(myPath + "/matchSchedule.json","r"))

class Panel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        #Identifiers
        self.nameTitle = wx.StaticText(self, label="Pit Scouting Input", pos=(20, 30))
        self.teamNumTitle = wx.StaticText(self, label="Team #", pos=(180, 30))
        self.teamNumInput = wx.TextCtrl(self, pos=(250, 30), size = (100, 20))

        self.weightTitle = wx.StaticText(self, label="Weight", pos=(20, 80))
        self.weightInput = wx.TextCtrl(self, pos=(150, 80), size=(100, 20))
        self.poundsTitle = wx.StaticText(self, label="lb.", pos=(255, 80))

        self.groundClearance = wx.StaticText(self, label="Ground Clearance", pos=(20,100))
        self.groundClearanceInput = wx.TextCtrl(self, pos=(150, 100), size=(100,20))
        self.inch = wx.StaticText(self,  label="in.", pos=(255, 100))

        self.scale = wx.StaticText(self, label="Scale capable?", pos=(20, 120))
        self.scaleCapable = wx.CheckBox(self, pos=(150, 120))
        self.description = wx.StaticText(self, label="Description", pos=(180, 120))
        self.scaleTextInput = wx.TextCtrl(self, pos=(280, 120), size=(300, 20))

        self.switch = wx.StaticText(self, label="Switch capable?", pos=(20, 140))
        self.switchCapable = wx.CheckBox(self, pos=(150, 140))
        self.description = wx.StaticText(self, label="Description", pos=(180, 140))
        self.switchTextInput = wx.TextCtrl(self, pos=(280, 140), size=(300, 20))

        # self.cheesecake = wx.StaticText(self, label="Cheesecake-able?", pos=(20,160))
        # self.cheesecakable = wx.CheckBox(self, pos =(150,160))
        self.driveTrain = wx.StaticText(self, label="Type of drivetrain?", pos=(20,165))
        self.driveTrainInput = wx.RadioBox(self, choices=["WestCoast / Tank","Swerve","Other"],pos=(175,160))
        self.driveTrainOtherInput = wx.TextCtrl(self, pos=(510,166), size=(80,20))
        self.driveTrainOtherInput.Enable(False)

        self.levitate = wx.StaticText(self, label="Can this robot help others Levitate?", pos=(20,210))
        self.levitateInput = wx.RadioBox(self, choices=["0","1","2"], pos=(280,205))
        self.how = wx.StaticText(self, label="How?", pos=(20, 235))
        self.levitateHow = wx.RadioBox(self, choices=["Buddy Bar","Platform but I don't climb","Platform and I climb","Others"], pos=(50,230), style = wx.RA_SPECIFY_COLS, majorDimension=2)
        self.otherInput = wx.TextCtrl(self, pos=(310,257.5), size=(80,20))
        self.otherInput.Enable(False)

        self.comments = wx.StaticText(self, label="General comments?", pos=(20,280))
        self.commentsInput = wx.TextCtrl(self, pos=(150,280), size=(300,20))

        self.submitButton = wx.Button(self, 10, "Submit Data!", pos=(450,300))

        self.submitButton.Bind(wx.EVT_BUTTON, self.CSV_OUTPUT)
        self.levitateHow.Bind(wx.EVT_RADIOBOX, self.Enable_Others)
        self.driveTrainInput.Bind(wx.EVT_RADIOBOX, self.DT_Enable_Others)


    def Enable_Others(self, event):
        if self.levitateHow.GetSelection() == 3:
            self.otherInput.Enable()
        else:
            self.otherInput.Enable(False)
        event.Skip()


    def DT_Enable_Others(self, event):
        if self.driveTrainInput.GetSelection() == 2:
            self.driveTrainOtherInput.Enable()
        else:
            self.driveTrainOtherInput.Enable(False)
        event.Skip()


    def CSV_OUTPUT(self, event):
        filename = "PITSCOUT"

        levitateHow = ""
        if self.levitateHow.GetSelection() == 3:
            levitateHow = self.otherInput.GetValue()
        elif self.levitateHow.GetSelection() != 3:
            levitateHow = self.levitateHow.GetItemLabel(self.levitateHow.GetSelection())


        if not Path(myPath + "/ScoutingData", filename + '.csv').exists():
            with open(os.path.join(myPath + "/ScoutingData", filename + '.csv'), 'w') as csvfile:
                fieldnames = ['teamNumber','weight','groundClearance','scale','scaleComments','switch','switchComments','levitateNum', 'levitateComments','comments','timeStamp']

                writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

                writer.writeheader()
                writer.writerow({'teamNumber':self.teamNumInput.GetValue(),'weight':self.weightInput.GetValue(),'groundClearance':self.groundClearanceInput.GetValue(),'scale':self.scaleCapable.GetValue(),'scaleComments':self.scaleTextInput.GetValue(),'switch':self.switchCapable.GetValue(),'switchComments':self.switchTextInput.GetValue(),'levitateNum':self.levitateInput.GetSelection(), 'levitateComments':levitateHow,'comments':self.commentsInput.GetValue(),'timeStamp':datetime.now().time()})
        else:
            with open(os.path.join(myPath + "/ScoutingData", filename + '.csv'), 'a') as csvfile:
                fieldnames = ['teamNumber','weight','groundClearance','scale','scaleComments','switch','switchComments','levitateNum', 'levitateComments','comments', 'timeStamp']

                writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

                # writer.writeheader()
                writer.writerow({'teamNumber':self.teamNumInput.GetValue(),'weight':self.weightInput.GetValue(),'groundClearance':self.groundClearanceInput.GetValue(),'scale':self.scaleCapable.GetValue(),'scaleComments':self.scaleTextInput.GetValue(),'switch':self.switchCapable.GetValue(),'switchComments':self.switchTextInput.GetValue(),'levitateNum':self.levitateInput.GetSelection(), 'levitateComments':levitateHow,'comments':self.commentsInput.GetValue(),'timeStamp':datetime.now().time()})


        self.teamNumInput.Clear()
        self.weightInput.Clear()
        self.groundClearanceInput.Clear()
        self.scaleCapable.SetValue(0)
        self.scaleTextInput.Clear()
        self.switchCapable.SetValue(0)
        self.switchTextInput.Clear()
        self.levitateInput.SetSelection(0)
        self.levitateHow.SetSelection(0)
        self.otherInput.Clear()
        self.otherInput.Enable(False)
        self.commentsInput.Clear()


        # os.system("open -a /Applications/Utilities/Bluetooth\ File\ Exchange.app " + myPath + "/ScoutingData/" + filename + ".csv")
        event.Skip()




app = wx.App(False)
frame = wx.Frame(None, title = "1218 Vulcan Scouting Pit Scouting Input", size = (600, 350))
panel = Panel(frame)
frame.Show()
app.MainLoop()

# -*- coding: utf-8 -*-
#This file generates the drive team input
import wx
import csv
import module_locator
import json
import os
from datetime import datetime
from pathlib2 import Path

#locate the Package
myPath = module_locator.module_path()

#import match schedule from json generated by PullMatchSchedule.py
matchSchedule = json.load(open(myPath + "/matchSchedule.json","r"))

class Panel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        #Identifiers
        self.nameTitle = wx.StaticText(self, label="Pit Scouting Input", pos=(20, 30))
        self.teamNumTitle = wx.StaticText(self, label="Team #", pos=(180, 30))
        self.teamNumInput = wx.TextCtrl(self, pos=(250, 30), size = (100, 20))

        self.weightTitle = wx.StaticText(self, label="Weight", pos=(20, 80))
        self.weightInput = wx.TextCtrl(self, pos=(150, 80), size=(100, 20))
        self.poundsTitle = wx.StaticText(self, label="lb.", pos=(255, 80))

        self.groundClearance = wx.StaticText(self, label="Ground Clearance", pos=(20,100))
        self.groundClearanceInput = wx.TextCtrl(self, pos=(150, 100), size=(100,20))
        self.inch = wx.StaticText(self,  label="in.", pos=(255, 100))

        self.scale = wx.StaticText(self, label="Scale capable?", pos=(20, 120))
        self.scaleCapable = wx.CheckBox(self, pos=(150, 120))
        self.description = wx.StaticText(self, label="Description", pos=(180, 120))
        self.scaleTextInput = wx.TextCtrl(self, pos=(280, 120), size=(300, 20))

        self.switch = wx.StaticText(self, label="Switch capable?", pos=(20, 140))
        self.switchCapable = wx.CheckBox(self, pos=(150, 140))
        self.description = wx.StaticText(self, label="Description", pos=(180, 140))
        self.switchTextInput = wx.TextCtrl(self, pos=(280, 140), size=(300, 20))

        # self.cheesecake = wx.StaticText(self, label="Cheesecake-able?", pos=(20,160))
        # self.cheesecakable = wx.CheckBox(self, pos =(150,160))
        self.driveTrain = wx.StaticText(self, label="Type of drivetrain?", pos=(20,165))
        self.driveTrainInput = wx.RadioBox(self, choices=["WestCoast / Tank","Swerve","Other"],pos=(175,160))
        self.driveTrainOtherInput = wx.TextCtrl(self, pos=(510,166), size=(80,20))
        self.driveTrainOtherInput.Enable(False)

        self.levitate = wx.StaticText(self, label="Can this robot help others Levitate?", pos=(20,210))
        self.levitateInput = wx.RadioBox(self, choices=["0","1","2"], pos=(280,205))
        self.how = wx.StaticText(self, label="How?", pos=(20, 235))
        self.levitateHow = wx.RadioBox(self, choices=["Buddy Bar","Platform but I don't climb","Platform and I climb","Others"], pos=(50,230), style = wx.RA_SPECIFY_COLS, majorDimension=2)
        self.otherInput = wx.TextCtrl(self, pos=(310,257.5), size=(80,20))
        self.otherInput.Enable(False)

        self.comments = wx.StaticText(self, label="General comments?", pos=(20,280))
        self.commentsInput = wx.TextCtrl(self, pos=(150,280), size=(300,20))

        self.submitButton = wx.Button(self, 10, "Submit Data!", pos=(450,300))

        self.submitButton.Bind(wx.EVT_BUTTON, self.CSV_OUTPUT)
        self.levitateHow.Bind(wx.EVT_RADIOBOX, self.Enable_Others)
        self.driveTrainInput.Bind(wx.EVT_RADIOBOX, self.DT_Enable_Others)


    def Enable_Others(self, event):
        if self.levitateHow.GetSelection() == 3:
            self.otherInput.Enable()
        else:
            self.otherInput.Enable(False)
        event.Skip()


    def DT_Enable_Others(self, event):
        if self.driveTrainInput.GetSelection() == 2:
            self.driveTrainOtherInput.Enable()
        else:
            self.driveTrainOtherInput.Enable(False)
        event.Skip()


    def CSV_OUTPUT(self, event):
        filename = "PITSCOUT"

        levitateHow = ""
        if self.levitateHow.GetSelection() == 3:
            levitateHow = self.otherInput.GetValue()
        elif self.levitateHow.GetSelection() != 3:
            levitateHow = self.levitateHow.GetItemLabel(self.levitateHow.GetSelection())


        if not Path(myPath + "/ScoutingData", filename + '.csv').exists():
            with open(os.path.join(myPath + "/ScoutingData", filename + '.csv'), 'w') as csvfile:
                fieldnames = ['teamNumber','weight','groundClearance','scale','scaleComments','switch','switchComments','levitateNum', 'levitateComments','comments','timeStamp']

                writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

                writer.writeheader()
                writer.writerow({'teamNumber':self.teamNumInput.GetValue(),'weight':self.weightInput.GetValue(),'groundClearance':self.groundClearanceInput.GetValue(),'scale':self.scaleCapable.GetValue(),'scaleComments':self.scaleTextInput.GetValue(),'switch':self.switchCapable.GetValue(),'switchComments':self.switchTextInput.GetValue(),'levitateNum':self.levitateInput.GetSelection(), 'levitateComments':levitateHow,'comments':self.commentsInput.GetValue(),'timeStamp':datetime.now().time()})
        else:
            with open(os.path.join(myPath + "/ScoutingData", filename + '.csv'), 'a') as csvfile:
                fieldnames = ['teamNumber','weight','groundClearance','scale','scaleComments','switch','switchComments','levitateNum', 'levitateComments','comments', 'timeStamp']

                writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

                # writer.writeheader()
                writer.writerow({'teamNumber':self.teamNumInput.GetValue(),'weight':self.weightInput.GetValue(),'groundClearance':self.groundClearanceInput.GetValue(),'scale':self.scaleCapable.GetValue(),'scaleComments':self.scaleTextInput.GetValue(),'switch':self.switchCapable.GetValue(),'switchComments':self.switchTextInput.GetValue(),'levitateNum':self.levitateInput.GetSelection(), 'levitateComments':levitateHow,'comments':self.commentsInput.GetValue(),'timeStamp':datetime.now().time()})


        self.teamNumInput.Clear()
        self.weightInput.Clear()
        self.groundClearanceInput.Clear()
        self.scaleCapable.SetValue(0)
        self.scaleTextInput.Clear()
        self.switchCapable.SetValue(0)
        self.switchTextInput.Clear()
        self.levitateInput.SetSelection(0)
        self.levitateHow.SetSelection(0)
        self.otherInput.Clear()
        self.otherInput.Enable(False)
        self.commentsInput.Clear()


        # os.system("open -a /Applications/Utilities/Bluetooth\ File\ Exchange.app " + myPath + "/ScoutingData/" + filename + ".csv")
        event.Skip()




app = wx.App(False)
frame = wx.Frame(None, title = "1218 Vulcan Scouting Pit Scouting Input", size = (600, 350))
panel = Panel(frame)
frame.Show()
app.MainLoop()

# -*- coding: utf-8 -*- #This file generates the drive team input #locate the Package #import match schedule from json generated by PullMatchSchedule.py #Identifiers #", pos=(180, 30)) # self.cheesecake = wx.StaticText(self, label="Cheesecake-able?", pos=(20,160)) # self.cheesecakable = wx.CheckBox(self, pos =(150,160)) # writer.writeheader() # os.system("open -a /Applications/Utilities/Bluetooth\ File\ Exchange.app " + myPath + "/ScoutingData/" + filename + ".csv")