Esempio n. 1
0
def test_passing_authority_red(upload_tracks, download_programs):
    """Testing passing authority. It should always be true because only 1 train is being dispatched"""
    # Disconnect signals going to and from track controller
    try:
        signals.train_model_dispatch_train.disconnect()
        signals.trackmodel_update_authority.disconnect()
        signals.update_occupancy.disconnect()
        signals.train_model_update_direction.disconnect()
    except Exception:
        pass

    # Connect to signal to verify
    signals.trackmodel_update_authority.connect(verify_authority)

    # Dispatch a train
    ctc.dispatch_train(60, Line.LINE_RED)

    signals.trackmodel_update_occupancy.emit(0, Line.LINE_RED,
                                             red_route_blocks[0], True, 0)
    for previous_block, current_block in zip(red_route_blocks,
                                             red_route_blocks[1:]):
        # Simulate the train changing blocks
        signals.trackmodel_update_occupancy.emit(0, Line.LINE_RED,
                                                 previous_block, False, 0)
        signals.trackmodel_update_occupancy.emit(0, Line.LINE_RED,
                                                 current_block, True, 0)
Esempio n. 2
0
def test_passing_authority_green(upload_tracks, download_programs):
    """Testing passing authority. It should always be true because only 1 train is being dispatched"""
    # Disconnect signals going to and from track controller
    signals.train_model_dispatch_train.disconnect()
    signals.train_model_update_command_speed.disconnect()
    signals.trackmodel_update_authority.disconnect()
    signals.update_occupancy.disconnect()
    signals.train_model_update_direction.disconnect()
    signals.train_model_receive_track_circuit.disconnect()

    # Connect to signal to verify
    signals.trackmodel_update_authority.connect(verify_authority)

    # Dispatch a train
    ctc.dispatch_train(38, Line.LINE_GREEN)

    signals.trackmodel_update_occupancy.emit(0, Line.LINE_GREEN,
                                             green_route_blocks[0], True, 0)
    for previous_block, current_block in zip(green_route_blocks,
                                             green_route_blocks[1:]):
        # Simulate the train changing blocks
        signals.trackmodel_update_occupancy.emit(0, Line.LINE_GREEN,
                                                 previous_block, False, 0)
        signals.trackmodel_update_occupancy.emit(0, Line.LINE_GREEN,
                                                 current_block, True, 0)
Esempio n. 3
0
def test_dispatch_train(upload_tracks, download_programs):
    """Tests dispatching a train and ensures all modules react accordingly"""
    # Upload track
    fileInfoGreen = ['resources/Green Line.xlsx', 'All Files (*)']
    SignalHandler.readInData(fileInfoGreen)

    fileInfoRed = ['resources/Red Line.xlsx', 'All Files (*)']
    SignalHandler.readInData(fileInfoRed)

    # Send dispatch signal
    ctc.dispatch_train(38, Line.LINE_GREEN)

    # Assert train is made in CTC
    assert ctc.trains_arr[0].train_id == 1

    # Assert train is made in swtrain, trainmodel
    assert len(train_catalogue.m_trainList) == 1
    assert len(control_system.p_controllers) == 1

    # Assert received authority and command speed
    assert train_catalogue.m_trainList[0].m_commandSpeed == 24.85484
    assert not train_catalogue.m_trainList[0].m_authority

    assert control_system.p_controllers[0].command_speed == 40.0
    assert control_system.p_controllers[0].authority
Esempio n. 4
0
    def test_dispatch(self):
        """ Test Setting Switches """

        # Test that the train array is empty
        self.assertEqual(len(ctc.trains_arr) == 0, True)
        self.assertEqual(len(ctc.train_numbers) == 0, True)

        # Dispatch a Train
        ctc.dispatch_train(10, Line.LINE_GREEN)

        # Test that train was dispatched
        self.assertEqual(len(ctc.trains_arr) == 1, True)
        self.assertEqual(len(ctc.train_numbers) == 1, True)

        # Check that the train number is 1
        self.assertEqual(ctc.trains_arr[0].train_id == 1, True)
        self.assertEqual(ctc.train_numbers[0] == 1, True)

        # Check that train is on green line and information is right

        self.assertEqual(ctc.trains_arr[0].line_on == Line.LINE_GREEN, True)
        self.assertEqual(ctc.trains_arr[0].destination_block == 10, True)
        self.assertEqual(ctc.trains_arr[0].command_speed == 70, True)
        self.assertEqual(ctc.trains_arr[0].authority == 3, True)
        self.assertEqual(ctc.trains_arr[0].index_on_route == 0, True)

        # Remove train from array
        ctc.trains_arr.pop()
        ctc.train_numbers.pop()

        # Test that train was removed
        self.assertEqual(len(ctc.trains_arr) == 0, True)
        self.assertEqual(len(ctc.train_numbers) == 0, True)

        # Dispatch another train
        ctc.dispatch_train(13, Line.LINE_RED)

        # Test that train was dispatched
        self.assertEqual(len(ctc.trains_arr) == 1, True)
        self.assertEqual(len(ctc.train_numbers) == 1, True)

        # Check that the train number is 2
        self.assertEqual(ctc.trains_arr[0].train_id == 2, True)
        self.assertEqual(ctc.train_numbers[0] == 2, True)

        # Check that train is on green line and information is right
        self.assertEqual(ctc.trains_arr[0].line_on == Line.LINE_RED, True)
        self.assertEqual(ctc.trains_arr[0].destination_block == 13, True)
        self.assertEqual(ctc.trains_arr[0].command_speed == 70, True)
        self.assertEqual(ctc.trains_arr[0].authority == 3, True)
        self.assertEqual(ctc.trains_arr[0].index_on_route == 0, True)
Esempio n. 5
0
def test_passing_occupancy(upload_tracks, download_programs):
    """Testing passing occupancy"""
    # Disconnect signals going to train model
    signals.train_model_dispatch_train.disconnect()
    signals.train_model_update_authority.disconnect()
    signals.train_model_update_command_speed.disconnect()
    signals.train_model_update_direction.disconnect()
    signals.train_model_receive_track_circuit.disconnect()

    # Dispatch a train
    ctc.dispatch_train(38, Line.LINE_GREEN)

    signals.trackmodel_update_occupancy.emit(0, Line.LINE_GREEN,
                                             green_route_blocks[0], True, 1)
    for previous_block, current_block in zip(green_route_blocks,
                                             green_route_blocks[1:]):
        # Simulate the train changing blocks
        signals.trackmodel_update_occupancy.emit(0, Line.LINE_GREEN,
                                                 previous_block, False, 1)
        signals.trackmodel_update_occupancy.emit(0, Line.LINE_GREEN,
                                                 current_block, True, 1)

        # Verify it got to the ctc
        assert current_block in track_system.green_occupied_blocks
        assert previous_block not in track_system.green_occupied_blocks

    # Dispatch a train
    ctc.dispatch_train(60, Line.LINE_RED)

    signals.trackmodel_update_occupancy.emit(1, Line.LINE_RED,
                                             red_route_blocks[0], True, 1)
    for previous_block, current_block in zip(red_route_blocks,
                                             red_route_blocks[1:]):
        # Simulate the train changing blocks
        signals.trackmodel_update_occupancy.emit(1, Line.LINE_RED,
                                                 previous_block, False, 1)
        signals.trackmodel_update_occupancy.emit(1, Line.LINE_RED,
                                                 current_block, True, 1)

        # Verify it got to the ctc
        assert current_block in track_system.red_occupied_blocks
        assert previous_block not in track_system.red_occupied_blocks
Esempio n. 6
0
    def dispatch_train(self):
        """ Dispatches a train once user clicks button """

        # If simulation paused, dont let dispatch
        if timekeeper.paused:
            self.d_conf_label.setStyleSheet("color: red")
            self.d_conf_label.setText('Error: simulation paused')
            self.d_speed_label.setText('')
            self.d_auth_label.setText('')
            return

        # Red line
        if self.red_radio.isChecked() and len(self.d_time_label.text()) == 0:
            if ctc.blocks_red_arr[8].occupied:
                self.d_conf_label.setStyleSheet("color: red")
                self.d_conf_label.setText('Wait until train leaves block 9')
                self.d_speed_label.setText('')
                self.d_auth_label.setText('')
                return
            for i in range(len(ctc.trains_arr)):
                if ctc.trains_arr[i].line_on == Line.LINE_RED and\
                ctc.trains_arr[i].index_on_route == 0:
                    self.d_conf_label.setStyleSheet("color: red")
                    self.d_conf_label.setText('Wait until Previous train leaves Yard')
                    self.d_speed_label.setText('')
                    self.d_auth_label.setText('')
                    return

        # Green Line
        elif len(self.d_time_label.text()) == 0:
            if ctc.blocks_green_arr[61].occupied or ctc.blocks_green_arr[60].occupied:
                self.d_conf_label.setStyleSheet("color: red")
                self.d_conf_label.setText('Wait until train leaves block 62 or 61')
                self.d_speed_label.setText('')
                self.d_auth_label.setText('')
                return
            for i in range(len(ctc.trains_arr)):
                if ctc.trains_arr[i].line_on == Line.LINE_GREEN and\
                ctc.trains_arr[i].index_on_route == 0:
                    self.d_conf_label.setStyleSheet("color: red")
                    self.d_conf_label.setText('Wait until Previous train leaves Yard')
                    self.d_speed_label.setText('')
                    self.d_auth_label.setText('')
                    return

        # Error Check block value
        try:
            int(self.d_block_label.text())
        except:
            self.d_conf_label.setStyleSheet("color: red")
            self.d_conf_label.setText('Error: Invalid Block Entered')
            self.d_speed_label.setText('')
            self.d_auth_label.setText('')
            return

        # Make sure user specified a line
        if not self.green_radio.isChecked() and not self.red_radio.isChecked():
            self.d_conf_label.setStyleSheet("color: red")
            self.d_conf_label.setText('Error: Please Select a Line')
            self.d_speed_label.setText('')
            self.d_auth_label.setText('')
            return

        # Error Check for block value
        if int(self.d_block_label.text()) <= 0 or len(self.d_block_label.text()) == 0:
            self.d_conf_label.setStyleSheet("color: red")
            self.d_conf_label.setText('Error: Invalid Block Entered')
            self.d_speed_label.setText('')
            self.d_auth_label.setText('')
            return
        elif self.red_radio.isChecked() and int(self.d_block_label.text()) > 76:
            self.d_conf_label.setStyleSheet("color: red")
            self.d_conf_label.setText('Error: Invalid Block Entered For Red Line')
            self.d_speed_label.setText('')
            self.d_auth_label.setText('')
            return
        elif self.red_radio.isChecked() == False and int(self.d_block_label.text()) > 155:
            self.d_conf_label.setStyleSheet("color: red")
            self.d_conf_label.setText('Error: Invalid Block Entered For Green Line')
            self.d_speed_label.setText('')
            self.d_auth_label.setText('')
            return

        # Error Check for time value
        if len(self.d_time_label.text()) != 6 and len(self.d_time_label.text()) != 0:
            self.d_conf_label.setStyleSheet("color: red")
            self.d_conf_label.setText('Error: Invalid Time Entered 3')
            self.d_speed_label.setText('')
            self.d_auth_label.setText('')
            return
        elif len(self.d_time_label.text()) == 6:

            # Error Check time values
            try:
                int(self.d_time_label.text()[0] + self.d_time_label.text()[1])
            except:
                self.d_conf_label.setStyleSheet("color: red")
                self.d_conf_label.setText('Error: Invalid Time Entered 1')
                self.d_speed_label.setText('')
                self.d_auth_label.setText('')
                return
            try:
                int(self.d_time_label.text()[3] + self.d_time_label.text()[4])
            except:
                self.d_conf_label.setStyleSheet("color: red")
                self.d_conf_label.setText('Error: Invalid Time Entered 2')
                self.d_speed_label.setText('')
                self.d_auth_label.setText('')
                return

            if int(self.d_time_label.text()[0] + self.d_time_label.text()[1]) not in range(1, 13):
                self.d_conf_label.setStyleSheet("color: red")
                self.d_conf_label.setText('Error: Invalid Time Entered 4')
                self.d_speed_label.setText('')
                self.d_auth_label.setText('')
                return
            elif int(self.d_time_label.text()[3] + self.d_time_label.text()[4]) not in range(60):
                self.d_conf_label.setStyleSheet("color: red")
                self.d_conf_label.setText('Error: Invalid Time Entered 5')
                self.d_speed_label.setText('')
                self.d_auth_label.setText('')
                return
            elif self.d_time_label.text()[5] not in ['a', 'p']:
                self.d_conf_label.setStyleSheet("color: red")
                self.d_conf_label.setText('Error: Invalid Time of Day  Entered (a/p)')
                self.d_speed_label.setText('')
                self.d_auth_label.setText('')
                return

            # Print confirmation to screen and take actions if information valid
            else:
                self.d_conf_label.setStyleSheet("color: green")
                self.d_conf_label.setText('Train Dispatched to Block ' + self.d_block_label.text()\
                    + ' at ' + self.d_time_label.text())
                self.d_speed_label.setText('Command Speed [to Track Controller]: 43 MPH')
                self.d_auth_label.setText('Authority [to Track Controller]: 3 Blocks')

                ##### Send to Timekeeper class #####
                hr = int(self.d_time_label.text()[0:2])
                if hr == 12:
                    if self.d_time_label.text()[5] == 'a':
                        hr = 0
                elif self.d_time_label.text()[5] == 'p':
                    hr += 12
                else:
                    pass
                minute = int(self.d_time_label.text()[3:5])

                if self.red_radio.isChecked():
                    temp_time_train = InterruptTrain(int(self.d_block_label.text()),\
                        Line.LINE_RED, hr, minute)
                else:
                    temp_time_train = InterruptTrain(int(self.d_block_label.text()),\
                        Line.LINE_GREEN, hr, minute)

                # Add the train to the interrupt list
                timekeeper.ctc_trains_backlog.append(temp_time_train)
        else:
            self.d_conf_label.setStyleSheet("color: green")
            self.d_conf_label.setText('Train Dispatched to Block ' + self.d_block_label.text()\
                + ' Now')
            self.d_speed_label.setText('Command Speed [to Track Controller]: 43 MPH')
            self.d_auth_label.setText('Authority [to Track Controller]: 3 Blocks')
            if self.red_radio.isChecked():
                ctc.dispatch_train(int(self.d_block_label.text()), Line.LINE_RED)
            else:
                ctc.dispatch_train(int(self.d_block_label.text()), Line.LINE_GREEN)