Skip to content

Commit

Permalink
Merge pull request #111 from asmithie13/main
Browse files Browse the repository at this point in the history
Updating train model
  • Loading branch information
21AQN01 authored Mar 19, 2024
2 parents 1c73312 + 17ca663 commit ce80de1
Show file tree
Hide file tree
Showing 54 changed files with 4,801 additions and 1,305 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.autoClosingQuotes": "never",
"editor.autoClosingBrackets": "never",
"editor.autoClosingDelete": "never"
}
10 changes: 0 additions & 10 deletions CTC/CTC.py

This file was deleted.

44 changes: 39 additions & 5 deletions CTC/CTC_Maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@

#Class to manage maintenece mode for CTC
class CTC_Maintenance():
def __init__(self, Blocks = []):
def __init__(self, Blocks = [], switchPostions = []):
self.BlocksClosed = Blocks
self.SwitchPositons = switchPostions

def addBlockOccupancy(self, BlockNum):
newBlockClosure = [BlockNum]
def addBlockClosure(self, BlockID):
newBlockClosure = [BlockID]
self.BlockData.append(newBlockClosure)



#Table class to initialize a Pyqt5 table object that will display the Blocks that are shut down for maintenance
class MaintenanceTableModel(QtCore.QAbstractTableModel):
class OccupiedBlocksTableModel(QtCore.QAbstractTableModel):
def __init__(self, data):
super(MaintenanceTableModel, self).__init__()
super(OccupiedBlocksTableModel, self).__init__()
self._data = data

#Displays the data to the table
Expand All @@ -48,6 +49,39 @@ def columnCount(self, index):
def headerData(self, section, orientation, role):
headers = ['Closed Blocks']

if role == Qt.DisplayRole:
if orientation == Qt.Horizontal:
return str(headers[section])


#Table class to initialize a Pyqt5 table object that will display the switch positions set for maintenance
class SwitchPositionTableModel(QtCore.QAbstractTableModel):
def __init__(self, data):
super(SwitchPositionTableModel, self).__init__()
self._data = data

#Displays the data to the table
def data(self, index, role):
if role == Qt.DisplayRole:
return self._data[index.row()][index.column()]

#Returns the row count of the table
def rowCount(self, index):
return len(self._data)


#returns the column count of the table
def columnCount(self, index):
if(len(self._data) > 0):
return len(self._data[0])
else:
return 0


#Adds the column header with the correct data
def headerData(self, section, orientation, role):
headers = ['Switch', 'Position']

if role == Qt.DisplayRole:
if orientation == Qt.Horizontal:
return str(headers[section])
95 changes: 71 additions & 24 deletions CTC/CTC_UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import uic
#My class import
from Schedule import *
from OccupiedBlocks import *
from CTC_Maintenance import *
from Throughput import *
#My class imports
from CTC.Schedule import *
from CTC.OccupiedBlocks import *
from CTC.CTC_Maintenance import *
from CTC.Throughput import *
from CTC.TempData import *

#from UI_temp import MainWindow



class CTC_UI(QtWidgets.QMainWindow):
#Signals, for testbench
#Signals, for Wayside (and Testbench)
sendDispatchInfo = pyqtSignal(list)
sendBlockClosures = pyqtSignal(list)
sendSwitchPositions = pyqtSignal(list)

def __init__(self):
super(CTC_UI, self).__init__()
Expand All @@ -28,11 +32,15 @@ def __init__(self):


#Connect Buttons to signals defining behavior
self.UploadButton.clicked.connect(self.open_files)
self.ManualModeButton.clicked.connect(self.selectManualMode_button)
self.AddTrainButton.clicked.connect(self.addTrain_button)
self.AutoModeButton.clicked.connect(self.selectAutoMode_button)
self.GreenLineButton.clicked.connect(self.greenLine_button)
self.RedLineButton.clicked.connect(self.redLine_button)
self.UploadButton.clicked.connect(self.selectScheduleFile)
self.AddTrainButton.clicked.connect(self.addTrain_button)
self.MaintenanceModeButton.clicked.connect(self.enterMaintenanceMode)
self.CloseBlockButton.clicked.connect(self.closeBlock_button)
self.SetSwitchPositionButton.clicked.connect(self.setSwitch_button)

#Changing Button Colors
self.AddTrainButton.setStyleSheet("background-color : rgb(38, 207, 4)") #Green
Expand All @@ -47,24 +55,30 @@ def __init__(self):

#Manual Dispatch Formatting
self.ArrivalTimeEdit.setDisplayFormat("hh:mm")
self.DepartureTimeEdit.setDisplayFormat("hh:mm")

#Importing Track Data
self.TrackData = TempData()

#Setting Combo box values
stations = ['Yard', 'Station1', 'Station2']
self.DepartureSationSelect.addItems(stations)
self.DestinationSelect.addItems(stations)
#stations = ['Yard', 'Station1', 'Station2']
#self.DepartureSationSelect.addItems(stations)
#self.DestinationSelect.addItems(stations)

AllBlocks = ['2']
self.CloseBlockSelect.addItems(AllBlocks)

#Initializing Schedule
self.trainSchedule = Schedule()
self.ScheduleTableView.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata))
self.ScheduleTable.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata))

#Initializing Occupied Blocks Table
self.occupiedBlocks = OccupiedBlocks()
self.OccupiedBlockTable.setModel(BlocksTableModel(self.occupiedBlocks.BlockData))

#Initializing Maintance Table
#Initializing Maintance Tables
self.Maintence = CTC_Maintenance()
self.MaintenanceTable.setModel(MaintenanceTableModel(self.Maintence.BlocksClosed))
self.BlockClosureTable.setModel(OccupiedBlocksTableModel(self.Maintence.BlocksClosed))
self.SwitchPositionTable.setModel(SwitchPositionTableModel(self.Maintence.BlocksClosed))

#Initializing Throughput
self.ThroughputGraph = Throughput()
Expand Down Expand Up @@ -93,7 +107,7 @@ def addTrain_button(self):
ArrivalTime = ArrivalTime.toString("hh:mm")

self.trainSchedule.addTrain(TrainID, Destination, ArrivalTime, Departure, DepartureTime)
self.ScheduleTableView.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata))
self.ScheduleTable.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata))


#Define mutually exclisive auto/manual mode when manual mode is selected
Expand Down Expand Up @@ -131,6 +145,21 @@ def selectAutoMode_button(self):
self.DepartureTimeLabel.setStyleSheet("color: rgb(120, 120, 120);")
self.ArrivalTimeLabel.setStyleSheet("color: rgb(120, 120, 120);")

#Sets drop down options if green line is selected
def greenLine_button(self):
self.GreenLineButton.setStyleSheet("background-color : rgb(38, 207, 4)") #Green
self.RedLineButton.setStyleSheet("background-color : white")

self.DestinationSelect.addItems(self.TrackData.GreenStations)
self.DepartureSationSelect.addItems(self.TrackData.GreenStations)


def redLine_button(self):
self.RedLineButton.setStyleSheet("background-color: rgb(195, 16, 40)") #Red
self.GreenLineButton.setStyleSheet("background-color : white")

self.DestinationSelect.addItems(self.TrackData.RedStations)
self.DepartureSationSelect.addItems(self.TrackData.RedStations)

#function to update the clock display on the layout
def displayClock(self, time):
Expand All @@ -142,15 +171,15 @@ def displayClock(self, time):


#Define functionality for Upload File Button
def open_files(self):
def selectScheduleFile(self):
# Open a file dialog to select a Excel File
file_dialog = QFileDialog()
file_path, _ = file_dialog.getOpenFileName(self, "Select Schedule File", "", "CSV FIle (*.csv);;All Files (*)")

#Parse File
self.trainSchedule.parseScheduleFile(file_path)
#Update Table
self.ScheduleTableView.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata))
self.ScheduleTable.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata))

#Disable Manual Mode and upload button
self.selectAutoMode_button()
Expand All @@ -159,7 +188,22 @@ def open_files(self):

#Disable Manual Mode button (because it's one use)
self.ManualModeButton.setEnabled(False)
self.ManualModeButton.setStyleSheet("background-color : blue; color: black;")
self.ManualModeButton.setStyleSheet("background-color : rgb(240, 240, 240); color: rgb(120, 120, 120);")


#Indication that the system is in maintenance mode
#Same behavior will occur if a block is closed or a switch is sets
def enterMaintenanceMode(self):
print("You still need to write this")

self.MaintenanceModeButton.setStyleSheet("background-color : blue; color: black;")


#Will indicate that the system is no longer in maintenance mode
#Should work on the double press of the button
#or if the block closures/switch position are empty
def exitMaintenanceMode(self):
print("You still need to write this")


#function to update block occupied table based on input from Wayside
Expand All @@ -178,16 +222,19 @@ def addTrain_button(self):
ArrivalTime = ArrivalTime.toString("hh:mm")
self.trainSchedule.addTrain(TrainID, Destination, ArrivalTime, Departure, DepartureTime)

self.ScheduleTable.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata))

self.ScheduleTableView.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata))


#Function to add a block closure
#Function to add a block closure when in maintence mode
def closeBlock_button(self):
BlockToClose = self.CloseBlockField.text()
BlockToClose = self.CloseBlockSelect.currentText()
self.Maintence.BlocksClosed.append([BlockToClose])
self.MaintenanceTable.setModel(MaintenanceTableModel(self.Maintence.BlocksClosed))
self.BlockClosureTable.setModel(OccupiedBlocksTableModel(self.Maintence.BlocksClosed))


#Function to set switch positons when in maintenance mode
def setSwitch_button(self):
print("You didn't implement this yet")


#Function to update the ticket sales based on information from Track Model
Expand Down
Loading

0 comments on commit ce80de1

Please sign in to comment.