Exemple #1
0
    def timed_job(self):

        conn = sqlite3.connect('serm.db')

        with conn:
            
            df = pd.read_sql_query("SELECT * from data", conn);
            df.humidity = np.array(df.humidity.astype(float))
            df.temperature = np.array(df.temperature.astype(float))
            df.smoke = np.array(df.smoke.astype(float))
            df.co = np.array(df.co.astype(float))
            df.lpg = np.array(df.lpg.astype(float))
            df.windspeed = np.array(df.windspeed.astype(float)) 
            df.ffwi = np.array(df.ffwi.astype(float))                    
            datetm = calendar.timegm(time.strptime(str(time.strftime('%Y-%m-%d %H:%M:%S')), '%Y-%m-%d %H:%M:%S'))
            datedt = time.strftime('%Y-%m-%d %H:%M:%S')
            winddir = df.winddir.tail(1).iget(0)

            predict_risk.input['FFWI'] = df.ffwi.mean()
            predict_risk.input['SMOKE'] = df.smoke.mean()
            predict_risk.compute()
            
            risk = predict_risk.output['RISK']
            
            conn.execute("INSERT INTO data_means(timestamp,datetime,smoke,lpg,co,temperature,humidity,windspeed,winddir,ffwi,risk) VALUES (?,?,?,?,?,?,?,?,?,?,?)", (datetm,datedt,round(df.smoke.mean(),3),round(df.lpg.mean(),3),round(df.co.mean(),3),round(df.temperature.mean(),3),round(df.humidity.mean(),3),round(df.windspeed.mean(),3),winddir,round(df.ffwi.mean(),3),round(risk,3)))
            conn.commit()
            
            sql = "DELETE FROM data WHERE recid <= ( SELECT recid FROM (SELECT recid FROM data ORDER BY recid DESC LIMIT 1 OFFSET 20)foo)"
            conn.execute(sql)
            conn.commit()

#        self.lcdNumber_ffwi.display(str(round(df.ffwi.mean(),-1)))           
        self.lcdNumber_ffwi.display(str(df.ffwi.mean()))
        self.lcdNumber_risk.display((risk))
        
        palette = QtGui.QPalette()

        if risk < 10:
            palette.setColor(QtGui.QPalette.Foreground,QtCore.Qt.green)
            self.lbl_RiskStateValue.setPalette(palette)
            self.lbl_RiskStateValue.setText("LOW")
        elif risk >= 10 and risk < 30:
            palette.setColor(QtGui.QPalette.Foreground,QtCore.Qt.yellow)
            self.lbl_RiskStateValue.setPalette(palette)
            self.lbl_RiskStateValue.setText("AVERAGE")
        else:
            palette.setColor(QtGui.QPalette.Foreground,QtCore.Qt.red)
            self.lbl_RiskStateValue.setPalette(palette)
            self.lbl_RiskStateValue.setText("HIGH")
            sound = QSound("smoke-detector-1.wav")
            sound.play() 
Exemple #2
0
 def _drawAttentionWindows(self, audioFile, openTray):
     if openTray:
         try:
             ctypes.windll.WINMM.mciSendStringW(u"set cdaudio door open", None, 0, None)
         except:
             self.logger.exception("notify error: eject error (open)")
     
     try:
         from PyQt4.QtGui import QSound
         q = QSound(audioFile)
         q.play()
     except:        
         self.logger.exception("notify error: sound")
     
     if openTray:    
         try:
             ctypes.windll.WINMM.mciSendStringW(u"set cdaudio door open", None, 0, None)
         except:
             self.logger.exception("notify error: eject error (close)")
    def Play(self):

        QSound.play("fly-high.mp3")
 def measurementStopped(self):
     finishedSound = QSound('sounds/finished.wav')
     finishedSound.play()
     
     self.prepareInterfaceToStart()
Exemple #5
0
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)

    def keyPressEvent(self, event):
        if type(event) == QKeyEvent:
            if self.isBuzzer(event.text()):
                if not self.teamIsHighlighted():
                    if not self.timeUp:
                        for team in self.teamObjectList:
                            if event.text() in team.buzzerList:
                                buzzerIndex = team.buzzerList.index(
                                    event.text())
                                playerIndex = int(
                                    team.activePlayerList[buzzerIndex])
                                playerPicture = team.playerPictureList[
                                    playerIndex]
                                playerName = team.playerNameList[playerIndex]
                                self.currentBuzzedPlayerId = team.playerIdList[
                                    buzzerIndex]
                                teamWidget = team.teamWidget
                                self.buzzed(playerPicture, playerName,
                                            teamWidget)
            else:
                self.functionHandler(event.text())

    def bonusModeChooser(self, points):
        if config.bonusMode:
            self.changeScore(points)
        else:
            self.changeScoreFinal(points)

    def buzzed(self, playerPicture, playerName, teamWidget):
        self.beep.play()
        self.changePlayerWidget(playerPicture, playerName)
        self.highlightTeam(teamWidget)

    def blankPlayerWidget(self):
        self.playerWidget.updateWidget(config.blankPlayerPicture, '')

    def changePlayerWidget(self, picture, name):
        self.playerWidget.updateWidget(picture, name)

    def changeScoreBonus(self, scoreChange):
        for team in self.teamObjectList:
            if team.teamWidget.isHighlighted() and team.teamWidget.isBonus():
                team.teamWidget.setScore(team.teamWidget.getScore() +
                                         scoreChange)
                self.deHighlightTeam(team.teamWidget)
                team.teamWidget.bonusOff()
                self.blankPlayerWidget()

    def changeScoreTossup(self, scoreChange):
        for team in self.teamObjectList:
            if team.teamWidget.isHighlighted(
            ) and not team.teamWidget.isBonus():
                teamNumber = self.teamObjectList.index(team) + 1
                score = team.teamWidget.getScore() + scoreChange
                team.teamWidget.setScore(score)
                from modules import databaseaccess
                databaseaccess.submit_Score(self.gameId, self.questionNumber,
                                            self.currentBuzzedPlayerId,
                                            scoreChange, teamNumber)
                if config.bonusMode:
                    team.teamWidget.bonusOn()
                else:
                    self.clearBuzzers()

    def changeScoreTossupNeg(self, scoreChange):
        for team in self.teamObjectList:
            if team.teamWidget.isHighlighted(
            ) and not team.teamWidget.isBonus():
                teamNumber = self.teamObjectList.index(team) + 1
                score = team.teamWidget.getScore() + scoreChange
                team.teamWidget.setScore(score)
                from modules import databaseaccess
                databaseaccess.submit_Score(self.gameId, self.questionNumber,
                                            self.currentBuzzedPlayerId,
                                            scoreChange, teamNumber)
                self.clearBuzzers()

    def clearBuzzers(self):
        self.stopTimer()
        self.setTimerDisplay(5)
        self.timeUp = False
        self.currentBuzzedPlayerId = ""
        for team in self.teamObjectList:
            if team.teamWidget.isHighlighted():
                self.deHighlightTeam(team.teamWidget)
                team.teamWidget.bonusOff()
        self.blankPlayerWidget()

    def constructTeams(self, team1, team2):
        self.teamObjectList = []
        """
        for team in config.teamList:
            teamFile = open(team, 'r')
            teamName = teamFile.readline().rstrip()
            playerPictureList = []
            playerNameList = []
            for line in teamFile:
                lineList = line.rstrip().split()
                playerNameList.append(lineList[0])
                playerPictureList.append(team.rsplit('/', 1)[0] + '/' + lineList[1])
            teamFile.close()
        """
        """
        
            ##buzzerList = config.buzzerList[config.teamList.index(team)]
        activePlayerList = config.activePlayerList[config.teamList.index(team)]
        teamWidget = TeamWidget(team1)
        self.teamsLayout.addWidget(teamWidget)
        teamWidget = TeamWidget(team2)
        self.teamsLayout.addWidget(teamWidget)
        """
        from modules import databaseaccess
        team_Pic1 = databaseaccess.get_Team_Pic(team1)
        playerPictureList1 = [team_Pic1, team_Pic1, team_Pic1, team_Pic1]
        playerNameList1 = databaseaccess.get_Player_Name_By_Team_Id(self.team1)
        playerIdList1 = databaseaccess.get_Player_Id_By_Team_Id(self.team1id)
        ##playerNameList1 = ['qq',  'ww',  'ee',  'rr']
        buzzerList1 = ['q', 'w', 'e', 'r']
        activePlayerList1 = [0, 1, 2, 3]
        teamWidget1 = TeamWidget(team1)
        teamObject1 = TeamObject(team1, playerPictureList1, playerNameList1,
                                 playerIdList1, buzzerList1, activePlayerList1,
                                 teamWidget1)
        self.team1Layout.addWidget(teamWidget1)
        self.teamObjectList.append(teamObject1)
        team_Pic2 = databaseaccess.get_Team_Pic(team2)
        playerPictureList2 = [team_Pic2, team_Pic2, team_Pic2, team_Pic2]
        playerNameList2 = databaseaccess.get_Player_Name_By_Team_Id(self.team2)
        playerIdList2 = databaseaccess.get_Player_Id_By_Team_Id(self.team2id)
        buzzerList2 = ['t', 'y', 'u', 'i']
        activePlayerList2 = [0, 1, 2, 3]
        teamWidget2 = TeamWidget(team2)
        teamObject2 = TeamObject(team2, playerPictureList2, playerNameList2,
                                 playerIdList2, buzzerList2, activePlayerList2,
                                 teamWidget2)
        self.team2Layout.addWidget(teamWidget2)
        self.teamObjectList.append(teamObject2)

    def deHighlightTeam(self, teamWidget):
        teamWidget.deHighlight()

    def functionHandler(self, keyPress):
        if keyPress == config.clearButton:
            self.clearBuzzers()
        elif keyPress == config.negButton:
            self.changeScoreTossupNeg(config.negPoints)
        elif keyPress == config.correctButton:
            self.changeScoreTossup(config.correctPoints)
        elif keyPress == config.powerButton:
            self.changeScoreTossup(config.powerPoints)
        if keyPress == config.oneBonus:
            self.changeScoreBonus(config.bonusPoints)
        elif keyPress == config.twoBonus:
            self.changeScoreBonus(2 * config.bonusPoints)
        elif keyPress == config.threeBonus:
            self.changeScoreBonus(3 * config.bonusPoints)
        elif keyPress == config.startTimer:
            self.startTimer(5)
        elif keyPress == config.previousQuestion:
            self.emit(SIGNAL('previousQuestion'))
        elif keyPress == config.nextQuestion:
            self.emit(SIGNAL('nextQuestion'))

    def highlightTeam(self, teamWidget):
        teamWidget.highlight()

    def isBuzzer(self, text):
        status = False
        self.stopTimer()
        for team in self.teamObjectList:
            if text in team.buzzerList:
                status = True
        return status

    def setTimerDisplay(self, time):
        time = round(time, 1)
        time = float(time)
        self.lcdTimer.display(time)

    def setupGame(self, team1, team2):
        self.questionNumber = 0
        self.roundNumber = str(1)
        self.tournamentId = str(2)
        from modules import databaseaccess
        self.gameId = databaseaccess.create_Game(self.tournamentId,
                                                 self.roundNumber,
                                                 self.team1id, self.team2id)
        self.tournamentName = "Capstone Tournament of Champions"
        self.setWindowTitle('Quizbowl Scorekeeper')
        self.tournamentLabel.setText(self.tournamentName)
        self.roundLabel.setText('Round: ' + self.roundNumber)
        self.playerWidget = PlayerWidget()
        self.playerWidgetLayout.addWidget(self.playerWidget)
        self.blankPlayerWidget()
        self.constructTeams(team1, team2)
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.tick)
        self.setupSounds()
        self.timeUp = False
        self.emit(SIGNAL('nextQuestion'))

    def setupSounds(self):
        self.beep = QSound("sounds/beep.wav")
        self.buzzer = QSound("sounds/buzzer.wav")

    def startTimer(self, time=0):
        if time == 0:
            ##Just restarting the timer
            pass
        else:
            self.activeTime = time
            self.setTimerDisplay(time)
        self.timer.start(100)

    def stopTimer(self):
        self.timer.stop()

    def tick(self):
        self.activeTime -= .1
        if self.activeTime <= 0.001:
            self.timeUp = True
            self.stopTimer()
            self.buzzer.play()
        self.setTimerDisplay(self.activeTime)

    def teamIsHighlighted(self):
        status = False
        for team in self.teamObjectList:
            if team.teamWidget.isHighlighted():
                status = True
        return status
Exemple #6
0
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)


    def keyPressEvent(self, event):
        if type(event) == QKeyEvent:
            if self.isBuzzer(event.text()):
                if not self.teamIsHighlighted():
                    if not self.timeUp:
                        for team in self.teamObjectList:
                            if event.text() in team.buzzerList:
                                buzzerIndex = team.buzzerList.index(event.text())
                                playerIndex = int(team.activePlayerList[buzzerIndex])
                                playerPicture = team.playerPictureList[playerIndex]
                                playerName = team.playerNameList[playerIndex]
                                self.currentBuzzedPlayerId = team.playerIdList[buzzerIndex]
                                teamWidget = team.teamWidget
                                self.buzzed(playerPicture, playerName, teamWidget)
            else:
                self.functionHandler(event.text())

    def bonusModeChooser(self, points):
        if config.bonusMode:
            self.changeScore(points)
        else:
            self.changeScoreFinal(points)

    def buzzed(self, playerPicture, playerName, teamWidget):
        self.beep.play()
        self.changePlayerWidget(playerPicture, playerName)
        self.highlightTeam(teamWidget)

    def blankPlayerWidget(self):
        self.playerWidget.updateWidget(config.blankPlayerPicture, '')

    def changePlayerWidget(self, picture, name):
        self.playerWidget.updateWidget(picture, name)

    def changeScoreBonus(self, scoreChange):
        for team in self.teamObjectList:
            if team.teamWidget.isHighlighted() and team.teamWidget.isBonus():
                team.teamWidget.setScore(team.teamWidget.getScore() + scoreChange)
                self.deHighlightTeam(team.teamWidget)
                team.teamWidget.bonusOff()
                self.blankPlayerWidget()

    def changeScoreTossup(self, scoreChange):
        for team in self.teamObjectList:
            if team.teamWidget.isHighlighted() and not team.teamWidget.isBonus():
                teamNumber = self.teamObjectList.index(team) + 1
                score = team.teamWidget.getScore() + scoreChange
                team.teamWidget.setScore(score)
                from modules import databaseaccess
                databaseaccess.submit_Score(self.gameId, self.questionNumber, self.currentBuzzedPlayerId, scoreChange, teamNumber)
                if config.bonusMode:
                    team.teamWidget.bonusOn()
                else:
                    self.clearBuzzers()

    def changeScoreTossupNeg(self, scoreChange):
        for team in self.teamObjectList:
            if team.teamWidget.isHighlighted() and not team.teamWidget.isBonus():
                teamNumber = self.teamObjectList.index(team) + 1
                score = team.teamWidget.getScore() + scoreChange
                team.teamWidget.setScore(score)
                from modules import databaseaccess
                databaseaccess.submit_Score(self.gameId, self.questionNumber, self.currentBuzzedPlayerId, scoreChange, teamNumber)
                self.clearBuzzers()

    def clearBuzzers(self):
        self.stopTimer()
        self.setTimerDisplay(5)
        self.timeUp = False
        self.currentBuzzedPlayerId = ""
        for team in self.teamObjectList:
            if team.teamWidget.isHighlighted():
                self.deHighlightTeam(team.teamWidget)
                team.teamWidget.bonusOff()
        self.blankPlayerWidget()
    
    def constructTeams(self, team1, team2):
        self.teamObjectList = []
        """
        for team in config.teamList:
            teamFile = open(team, 'r')
            teamName = teamFile.readline().rstrip()
            playerPictureList = []
            playerNameList = []
            for line in teamFile:
                lineList = line.rstrip().split()
                playerNameList.append(lineList[0])
                playerPictureList.append(team.rsplit('/', 1)[0] + '/' + lineList[1])
            teamFile.close()
        """
        """
        
            ##buzzerList = config.buzzerList[config.teamList.index(team)]
        activePlayerList = config.activePlayerList[config.teamList.index(team)]
        teamWidget = TeamWidget(team1)
        self.teamsLayout.addWidget(teamWidget)
        teamWidget = TeamWidget(team2)
        self.teamsLayout.addWidget(teamWidget)
        """
        from modules import databaseaccess
        team_Pic1 = databaseaccess.get_Team_Pic(team1)
        playerPictureList1 = [team_Pic1,  team_Pic1,  team_Pic1,  team_Pic1]
        playerNameList1 = databaseaccess.get_Player_Name_By_Team_Id(self.team1)
        playerIdList1 = databaseaccess.get_Player_Id_By_Team_Id(self.team1id)
        ##playerNameList1 = ['qq',  'ww',  'ee',  'rr']
        buzzerList1 = ['q', 'w', 'e', 'r']
        activePlayerList1 = [0,  1,  2,  3]
        teamWidget1 = TeamWidget(team1)
        teamObject1 = TeamObject(team1, playerPictureList1, playerNameList1, playerIdList1, buzzerList1, activePlayerList1, teamWidget1)
        self.team1Layout.addWidget(teamWidget1)
        self.teamObjectList.append(teamObject1)
        team_Pic2 = databaseaccess.get_Team_Pic(team2)
        playerPictureList2 = [team_Pic2,  team_Pic2,  team_Pic2,  team_Pic2]
        playerNameList2 = databaseaccess.get_Player_Name_By_Team_Id(self.team2)
        playerIdList2 = databaseaccess.get_Player_Id_By_Team_Id(self.team2id)
        buzzerList2 = ['t', 'y', 'u', 'i']
        activePlayerList2 = [0,  1,  2,  3]
        teamWidget2 = TeamWidget(team2)
        teamObject2 = TeamObject(team2, playerPictureList2, playerNameList2, playerIdList2, buzzerList2, activePlayerList2, teamWidget2)
        self.team2Layout.addWidget(teamWidget2)
        self.teamObjectList.append(teamObject2)
    
    def deHighlightTeam(self, teamWidget):
        teamWidget.deHighlight()

    def functionHandler(self, keyPress):
        if keyPress == config.clearButton:
            self.clearBuzzers()
        elif keyPress == config.negButton:
            self.changeScoreTossupNeg(config.negPoints)
        elif keyPress == config.correctButton:
            self.changeScoreTossup(config.correctPoints)
        elif keyPress == config.powerButton:
            self.changeScoreTossup(config.powerPoints)
        if keyPress == config.oneBonus:
            self.changeScoreBonus(config.bonusPoints)
        elif keyPress == config.twoBonus:
            self.changeScoreBonus(2 * config.bonusPoints)
        elif keyPress == config.threeBonus:
            self.changeScoreBonus(3 * config.bonusPoints)
        elif keyPress == config.startTimer:
            self.startTimer(5)
        elif keyPress == config.previousQuestion:
            self.emit(SIGNAL('previousQuestion'))
        elif keyPress == config.nextQuestion:
            self.emit(SIGNAL('nextQuestion'))

    def highlightTeam(self, teamWidget):
        teamWidget.highlight()

    def isBuzzer(self, text):
        status = False
        self.stopTimer()
        for team in self.teamObjectList:
            if text in team.buzzerList:
                status = True
        return status
    
    def setTimerDisplay(self, time):
        time = round(time, 1)
        time = float(time)
        self.lcdTimer.display(time)

    def setupGame(self, team1, team2):
        self.questionNumber = 0
        self.roundNumber = str(1)
        self.tournamentId = str(2)
        from modules import databaseaccess
        self.gameId = databaseaccess.create_Game(self.tournamentId, self.roundNumber, self.team1id, self.team2id)
        self.tournamentName = "Capstone Tournament of Champions"
        self.setWindowTitle('Quizbowl Scorekeeper')
        self.tournamentLabel.setText(self.tournamentName)
        self.roundLabel.setText('Round: ' + self.roundNumber)
        self.playerWidget = PlayerWidget()
        self.playerWidgetLayout.addWidget(self.playerWidget)
        self.blankPlayerWidget()
        self.constructTeams(team1,  team2)
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.tick)
        self.setupSounds()
        self.timeUp = False
        self.emit(SIGNAL('nextQuestion'))
    
    def setupSounds(self):
        self.beep = QSound("sounds/beep.wav")
        self.buzzer = QSound("sounds/buzzer.wav")

    def startTimer(self,  time = 0):
        if time == 0:
            ##Just restarting the timer
            pass
        else:
            self.activeTime = time
            self.setTimerDisplay(time)
        self.timer.start(100)

    def stopTimer(self):
        self.timer.stop()
    
    def tick(self):
        self.activeTime -= .1
        if self.activeTime <= 0.001:
            self.timeUp = True
            self.stopTimer()
            self.buzzer.play()
        self.setTimerDisplay(self.activeTime)
    
    def teamIsHighlighted(self):
        status = False
        for team in self.teamObjectList:
            if team.teamWidget.isHighlighted():
                status = True
        return status
Exemple #7
0
class Track(QtGui.QWidget):
    UPDATE_PLAYING_TRACK_TIME = 100

    def __init__(self, track_model, window):
        super(Track, self).__init__(window)
        track_model.call_after_wave_state_changed.append(self.update_track)
        track_model.call_after_change.append(self.repaint)
        self.track_model = track_model
        self.window = window

        self.channels_list = ChannelsList(self.track_model)
        self.horizontal_layout = QtGui.QHBoxLayout()
        self.horizontal_layout.addWidget(self.channels_list)
        self.actions_panel = ActionsPanel(self.parent())
        self.horizontal_layout.addWidget(self.actions_panel)

        self.setLayout(self.horizontal_layout)
        self._temp_sound_file = None
        self._q_sound_object = None
        self._time_of_start = 0
        self._played_start = 0
        self._play_sound_timer = QtCore.QTimer()
        self._play_sound_timer.setSingleShot(False)
        self._play_sound_timer.timeout.connect(self.tick_timer)
        self.play_pause_button = None

    @property
    def captured_area_container(self):
        return self.track_model.captured_area_container

    @property
    def wave_state(self):
        return self.track_model.wave_state

    def update_track(self):
        self.channels_list.update_track()

    def _delete_temp_sound_file(self):
        if self._temp_sound_file is not None:
            os.remove(self._temp_sound_file)
            self._temp_sound_file = None
            self._q_sound_object = None

    def play(self):
        (opened, file) = tempfile.mkstemp()
        os.close(opened)
        if self.captured_area_container.is_released:
            self._played_start = self.captured_area_container.start
            wave_state = self.wave_state.get_part(self._played_start,
                                                  len(self.wave_state))
        else:
            self._played_start = 0
            wave_state = self.wave_state
        wave_state.save_to_file(file)
        self._q_sound_object = QSound(file)
        self._temp_sound_file = file
        self._q_sound_object.play()
        self._time_of_start = time.time()
        self._play_sound_timer.start(Track.UPDATE_PLAYING_TRACK_TIME)

    def tick_timer(self):
        cur_time = time.time()
        passed_time = cur_time - self._time_of_start
        frame_number = self._played_start + int(
            self.wave_state.frame_rate * passed_time)
        if frame_number > len(self.wave_state):
            self.window.switch_play_pause(self)
        else:
            self.captured_area_container.capture_segment(frame_number, 0)
        self.track_model.update()

    def set_play_pause_button(self, button):
        self.play_pause_button = button

    def stop(self):
        if self._q_sound_object is not None:
            self._q_sound_object.stop()
            self._play_sound_timer.stop()
            self._delete_temp_sound_file()

    def closeEvent(self, event):
        self._delete_temp_sound_file()