Beispiel #1
0
 def sSelectionChanged(self, selected, deselected):    
     
        
     idx = selected.indexes()[0]        
     if(self.run_id != self.proxy_model.data(idx).toInt()[0]):             
         self.run_id = self.proxy_model.data(idx).toInt()[0] 
         dstore.Set("current_run", self.run_id)
         eventCalcNow.set()              
         time.sleep(0.9)           
         tableTimes.Update()
Beispiel #2
0
 def Update_AutoNumbers(self, new_time):
     ds_times = dstore.Get("times")
     if(ds_times["auto_number_enable"] and ds_times["auto_number_logic"]):
         updates = ttAutonumbers.Update(self.model.GetDataframe(), new_time)                
         #self.model.Update()
         for update in updates:
             user = tableUsers.model.getUserParNr(int(update['nr']))                                                                                   
             if user != None:
                 db.update_from_dict(self.model.name, {"id":update["id"], "user_id":user["id"]})
                 print "I: auto number: update:", update['nr'], "id:", update["id"]
                 eventCalcNow.set()
                 return True #only one number at once
     return False
Beispiel #3
0
 def sCivilsToZeroes(self):
     if (uiAccesories.showMessage("Civils to zeroes", "Are you sure you want to set civils numbers to zeroes?", MSGTYPE.warning_dialog) != True):            
         return
     print "A: Times: Civils to zeroes.. "
     query = \
             " UPDATE times" +\
                 " SET user_id=0, time1 = Null, lap1 = Null, time2 = Null, lap2 = Null, time3 = Null, lap3 = Null,  time4 = Null, lap4 = Null" +\
                 " WHERE (times.user_id > 100000)"                    
     res = db.query(query)                        
                     
     db.commit()
     eventCalcNow.set()
     print "A: Times: Civils to zeroes.. press F5 to finish"
     return res
Beispiel #4
0
    def sRecalculate(self):
        if (uiAccesories.showMessage("Recalculate", "Are you sure you want to recalculate times and laptimes?", MSGTYPE.warning_dialog) != True):            
            return

        query = \
                " UPDATE times" +\
                    " SET time1 = Null, lap1 = Null, time2 = Null, lap2 = Null, time3 = Null, lap3 = Null,  time4 = Null, lap4 = Null"

        res = db.query(query)

        #self.ResetStatus() 

        db.commit()
        eventCalcNow.set()
        print "A: Times: Recalculating.. press F5 to finish"
        return res                    
Beispiel #5
0
 def sRecalculate(self, run_id):
     if (uiAccesories.showMessage("Recalculate", "Are you sure you want to recalculate times and laptimes? \n (only for the current run) ", MSGTYPE.warning_dialog) != True):            
         return
     print "A: Times: Recalculating.. run id:", run_id
     query = \
             " UPDATE times" +\
                 " SET time1 = Null, lap1 = Null, time2 = Null, lap2 = Null, time3 = Null, lap3 = Null,  time4 = Null, lap4 = Null" +\
                 " WHERE (times.run_id = \""+str(run_id)+"\")"
                     
     res = db.query(query)
             
     #self.ResetStatus() 
                     
     db.commit()
     eventCalcNow.set()
     print "A: Times: Recalculating.. press F5 to finish"
     return res                    
Beispiel #6
0
 def runGetTime(self):     
     
     aux_diagnostic = dstore.Get("diagnostic")    
                                         
     """ GET NEW TIME """                                                                  
     aux_time = self.send_receive_frame("GET_TIME_PAR_INDEX", self.index_times, diagnostic = aux_diagnostic["log_cyclic"])                                                                                    
                 
     if(aux_time['error'] == 0):
         print"================="
                                            
     if(aux_time['error'] != 0):
         dstore.SetItem("diagnostic", ["no_new_time_cnt"], aux_diagnostic["no_new_time_cnt"]+1)            
                                                                                                                                                                             
             
     """ STORE NEW TIME TO THE DATABASE """
     if(aux_time['error'] == 0):                 
         self.AddTimeToDb(aux_time)                                                                                                                           
         self.index_times += 1 # done, take next 
         eventCalcNow.set()                                                                            
     else:
         pass # no new time                  
Beispiel #7
0
 def Update_AutoNumbers(self, new_time):  
     ret = False      
     ds_times = dstore.Get("times")
     if(ds_times["auto_number_enable"] and ds_times["auto_number_logic"]):
         updates = ttAutonumbers.Update(self.model.GetDataframe(), new_time)
         #print "00: Update_AutoNumbers: ", updates, time.clock()                
         #self.model.Update()
         for update in updates:
             user = tableUsers.model.getUserParNr(int(update['nr']))                                                                                   
             if user != None:
                                     
                 #update user id in db
                 if user["nr"] < 0:
                     #for civils also write name to user string
                     db.update_from_dict(self.model.name, {"id":update["id"], "user_id":user["id"], "us1":user["name"]})
                 else:    
                     db.update_from_dict(self.model.name, {"id":update["id"], "user_id":user["id"]})
                 print "I: auto number: update:", update['nr'], "id:", update["id"]
                 ret = True #only one number at once
         if ret == True:
             eventCalcNow.set()                  
     return ret
Beispiel #8
0
    def run(self):       
        print "COMM: zakladam vlakno.."
        dstore.Set("com_init", 2)       
        
        ''' CONNECT TO EWITIS '''        
        try:
            self.protokol.open_port()
        except serial.SerialException:
            print "E: Cant open port"                                    
            dstore.SetItem("port", ["opened"], False)                        
            return            
        
        
        """ DATABASE """        
        try:           
            self.db = sqlite.sqlite_db("db/test_db.sqlite")
        
            '''connect to db'''  
            self.db.connect()
        except:
            #dstore.Set("port_enable", False)
            dstore.SetItem("port", ["opened"], False)
            print "E: Database"
        
        
        """communication established"""
        #dstore.Set("port_enable", True)
        dstore.SetItem("port", ["opened"], True)
            
                                                                                    
        while(1):
                                  
            #wait X millisecond, test if thread should be terminated
            ztime = time.clock()
            for i in range(10): 
                
                #wait              
                time.sleep(0.01)
                               
                #terminate thread?                                                 
                if dstore.Get("port")["opened"] == False:
                    self.stop()                                       
                    return
                
            #print "I: Comm: waiting:",time.clock() - ztime,"s", datetime.datetime.now().strftime("%H:%M:%S.%f")[:-3]                            
            #print "I: Comm: waiting:",time.clock()
                                         
            #communication enabled?
            if(dstore.Get("port")["enabled"] == False):                
                continue
            
            #add diagnostic? 
            diagnostic = False
            if(dstore.Get("diagnostic")["log_cyclic"] == 2):                
                diagnostic = True  
                
            """ 
            GET HW-SW-VERSION 
                only once (after start sw,hw = none)
            """            
            if(dstore.Get("versions")["hw"] == None) or (dstore.Get("versions")["fw"] == None):
                
                aux_version = self.send_receive_frame("GET_HW_SW_VERSION")
                print "version:", aux_version
                                
                if ('error' in aux_version): 
                    print "E: Comm: no Hw and Fw versions on device"                
                    continue #no other commands as long as no version
                
                dstore.SetItem("versions", ["hw"], aux_version["hw"])
                dstore.SetItem("versions", ["fw"], aux_version["fw"])
                dstore.SetItem("versions", ["device"], aux_version["device"])
            """ end of hw-sw-version """
            
            """ 
            SEND COMMAND 
                diagnostic purpose
            """ 
            if(dstore.Get("diagnostic")["sendcommandkey"] != None):
                                
                #send command                
                aux_response = self.send_receive_frame(dstore.Get("diagnostic")["sendcommandkey"], (dstore.Get("diagnostic")["senddata"]).decode('hex'))                                
                                
                if ('error' in aux_response): 
                    print "COMM: sendcommand response: ERROR"                                     
                
                #smazat request
                dstore.SetItem("diagnostic", ["sendcommandkey"], None)
                                
                #set response (text to label)                
                dstore.SetItem("diagnostic", ["sendresponse"], json.dumps(aux_response, indent = 4))
                                
            
            
            """
            RUNS & TIMES & DATABASE PART
             - get new time
             - get new run
             - store new time to the databasae
             - store new run to the databasae
            """          
                                                
            """ GET NEW TIME """                                                                  
            aux_time = self.send_receive_frame("GET_TIME_PAR_INDEX", self.index_times, diagnostic = diagnostic)                                                
            
            """ GET NEW RUN """                                                                                   
            aux_run = self.send_receive_frame("GET_RUN_PAR_INDEX", self.index_runs, diagnostic = diagnostic)                      
            
                        
            if(aux_time['error'] == 0 or aux_run['error'] == 0):
                print"================="

            """ GET NEW RUN """           
            aux_diagnostic = dstore.Get("diagnostic")                
            if(aux_time['error'] != 0):
                dstore.SetItem("diagnostic", ["no_new_time_cnt"], aux_diagnostic["no_new_time_cnt"]+1)
                
            if(aux_run['error'] != 0):
                dstore.SetItem("diagnostic", ["no_new_run_cnt"], aux_diagnostic["no_new_run_cnt"]+1)                        
            
            #dstore.SetItem("diagnostic", ["communication"], aux_diagnostic["communication"]+"<font color='red'>no new times (100)</font><br>")
            #dstore.SetItem("diagnostic", ["communication"], aux_diagnostic["communication"]+"<font color='green'>no new times (100)</font><br>")
            #dstore.SetItem("diagnostic", ["communication"], aux_diagnostic["communication"]+"<font color='blue'>no new times (100)</font><br>")                                                                                                                                                                    
                    
            """ STORE NEW TIME TO THE DATABASE """
            if(aux_time['error'] == 0):                 
                self.AddTimeToDb(aux_time)                                                                                                                           
                self.index_times += 1 # done, take next 
                eventCalcNow.set()                                                                            
            else:
                pass # no new time                  
        
            """ STORE NEW RUN TO THE DATABASE """
            if(aux_run['error'] == 0):                       
                self.AddRunToDb(aux_run)                                                                              
                self.index_runs += 1 # done, take next                                                                                                                            
            else:
                pass # no new run
            
            """ end of Run & Times & Database """
            
            """ GET RACE TIME """                                                                                   
            aux_racetime = self.send_receive_frame("GET_ACTUAL_RACE_TIME", diagnostic = diagnostic)
            dstore.Set("race_time", aux_racetime['time'])              
                            
                
            """
            barCellActions            
             - enable/disable startcell
             - enable/disable finishcell
             - generate starttime
             - generate finishtime
             - quit timing                        
             - clear database                        
             - enable/disable tags reading
            """
            
            '''CELL ADDRESS ACTIONS, toolbar'''
            
            """ set cell diag info""" 
            set_cell_diagnostic = dstore.Get("set_cell_diag_info", "SET")                           
            if(set_cell_diagnostic['address'] != 0):                                
                ret = self.send_receive_frame("SET_CELL_DIAG_INFO", set_cell_diagnostic) 
                dstore.SetItem("set_cell_diag_info", ['address'],0, "SET")
                
            """ ping cell """ 
            address = dstore.Get("ping_cell", "SET")                           
            if(address != 0):                                
                ret = self.send_receive_frame("PING_CELL", address) 
                dstore.Set("ping_cell", 0, "SET")
                
            """ run cell diagnostic""" 
            address = dstore.Get("run_cell_diagnostic", "SET")                           
            if(address != 0):                                
                ret = self.send_receive_frame("RUN_CELL_DIAGNOSTIC", address) 
                dstore.Set("run_cell_diagnostic", 0, "SET")
                
            '''CELL TASK ACTIONS, tab cells'''
                
            """ get cell last times """ 
            task = dstore.Get("get_cell_last_times", "SET")                           
            if(task != 0):                                
                ret = self.send_receive_frame("GET_CELL_LAST_TIME", task) 
                dstore.Set("get_cell_last_times", 0, "SET")
                
            """ enable cell """ 
            task = dstore.Get("enable_cell", "SET")                           
            if(task != 0):                                
                ret = self.send_receive_frame("ENABLE_CELL", task) 
                dstore.Set("enable_cell", 0, "SET")
                                 
            """ disable cell """ 
            task = dstore.Get("disable_cell", "SET")                           
            if(task != 0):                                
                ret = self.send_receive_frame("DISABLE_CELL", task) 
                dstore.Set("disable_cell", 0, "SET")
                                 
            """ generate celltime """ 
            generate_celltime = dstore.Get("generate_celltime", "SET")                           
            if(generate_celltime['task'] != 0):                                
                ret = self.send_receive_frame("GENERATE_CELLTIME", generate_celltime) 
                dstore.Set("generate_celltime", {'task':0, 'user_id':0}, "SET")                 
                                                                    
                    
            """ quit timing """
            if(dstore.IsChanged("quit_timing")):                                                                                     
                ret = self.send_receive_frame("QUIT_TIMING")
                dstore.ResetChangedFlag("quit_timing")
                
            """ clear database """
            if(dstore.IsChanged("clear_database")):                                                                                     
                ret = self.send_receive_frame("CLEAR_DATABASE")
                print "I: Comm: clearing database, please wait.. "
                time.sleep(21)
                dstore.ResetChangedFlag("clear_database")
                print "I: Comm: database should be empty now"
                
            """ enable/disable tags reading """
            if(dstore.IsChanged("tags_reading")):         
                on_off = dstore.Get("tags_reading", "SET")                                                                                               
                ret = self.send_receive_frame("SET_TAGS_READING", on_off)
                dstore.ResetChangedFlag("tags_reading")
                if(on_off):
                    print "I: Comm: Enable tags reading"
                else:
                    print "I: Comm: Disable tags reading"
            
            """ end of ACTIONS """
            
            """
            tab RACE SETTINGS & tab DEVICE            
             - set speaker             
             - get terminal info
             - set timing settings                                                                          
            """                                                                   
            if(dstore.GetItem("gui", ["active_tab"]) == TAB.race_settings)\
                or (dstore.GetItem("gui", ["active_tab"]) == TAB.device):                                
                                                                  
                """ synchronize system """
                if(dstore.IsChanged("synchronize_system")):                                                                                     
                    ret = self.send_receive_frame("SYNCHRONIZE_SYSTEM")
                    print "I: Comm: synchronize system.. "
                    dstore.ResetChangedFlag("synchronize_system")                    
                
                
                """ set speaker """
                if(dstore.IsChanged("speaker")):                                                                                                
                    aux_speaker = dstore.Get("speaker", "SET")                                                                                                                              
                    ret = self.send_receive_frame("SET_SPEAKER", aux_speaker)
                    dstore.ResetChangedFlag("speaker")                                                                                            
                                
                                                                                    
                """ get terminal-info """                     
                aux_terminal_info = self.send_receive_frame("GET_TERMINAL_INFO")                         
                """ store terminal-info to the datastore """
                if not('error' in aux_terminal_info): 
                    if(dstore.IsReadyForRefresh("terminal_info")):           
                        dstore.Set("terminal_info", aux_terminal_info, "GET")
                    else:
                        print "I: COMM: terminal info: not ready for refresh", aux_terminal_info               
                
                """ set timing settings """                
                if(dstore.IsChanged("timing_settings")):                    
                    aux_timing_settings = dstore.Get("timing_settings", "SET")
                    #print  "TS", aux_timing_settings                                                                                                         
                    ret = self.send_receive_frame("SET_TIMING_SETTINGS", aux_timing_settings)                
                    dstore.ResetChangedFlag("timing_settings")  
        
            """
            tab CELLs
            - clear diag, run diag, buttons ping,                                                                        
            """ 
            if(dstore.GetItem("gui", ["active_tab"]) == TAB.cells):
                pass
            
            """
            tab DIAGNOSTIC                        
             - get diagnostic                                    
            """
            if(dstore.GetItem("gui", ["active_tab"]) == TAB.diagnostic):                    
                """ get diagnostic """
                #for cmd_group in DEF_COMMANDS.DEF_COMMAND_GROUP['diagnostic']:                                          
                cmd_group = DEF_COMMANDS.DEF_COMMAND_GROUP['diagnostic']['development']
                aux_diagnostic = self.send_receive_frame("GET_DIAGNOSTIC", cmd_group)
                                
                #print "aux_diagnostic", aux_diagnostic
                            
                """ store terminal-states to the datastore """ 
                #if(dstore.IsReadyForRefresh("timing_settings")):           
                #    dstore.Set("timing_settings", aux_timing_setting, "GET")
                #else:
                #    print "not ready for refresh", aux_timing_setting     
            
            """
            ALL TABs            
             - get timing settings                                    
            """
                                    
            """ get timing-settings """            
            aux_timing_setting = self.send_receive_frame("GET_TIMING_SETTINGS", diagnostic = diagnostic)            
            #aux_timing_setting["name_id"] = 4
                                    
            """ store terminal-states to the datastore """ 
            if not('error' in aux_timing_setting):
                if(dstore.IsReadyForRefresh("timing_settings")):            
                    dstore.Set("timing_settings", aux_timing_setting, "GET")
                #else:
                #   print "I: COMM: aux_timing_setting: not ready for refresh",aux_timing_setting
                    
            """ get cell info """
            if OPTIKA_V2:
                #SET CELL INFO
                nr_changed_cells = dstore.IsChanged("cells_info")
                if(nr_changed_cells):
                    print nr_changed_cells
                    for nr_changed_cell in nr_changed_cells:                                          
                        aux_cell_info = dstore.GetItem("cells_info", [nr_changed_cell], "SET")                                                                                                                                                                                                                                                   
                        #print "COMM: set cell info", nr_changed_cell, aux_cell_info
                        ret = self.send_receive_frame("SET_CELL_INFO", aux_cell_info)
                    dstore.ResetChangedFlag("cells_info")
                
                #GET CELL INFO                                
                aux_cells_info = [None] * NUMBER_OF.CELLS                
                for i in range(0,  NUMBER_OF.CELLS):                                       
                    aux_cells_info[i] = self.send_receive_frame("GET_CELL_INFO", i+1, diagnostic = diagnostic)                                                 
                
                    """ store terminal-states to the datastore """ 
                    if not('error' in aux_cells_info[i]):                    
                        if(dstore.IsReadyForRefresh("cells_info")):             
                            dstore.SetItem("cells_info", [i], aux_cells_info[i], "GET", permanent = False)
                            if dstore.Get("com_init"): #synchro get a set, tzn. comboboxu s lineedit - po navazani komunikace
                                #print "nastavuju", aux_cells_info[i]["task"]
                                dstore.SetItem("cells_info", [i, "task"], aux_cells_info[i]["task"], "SET", permanent = False, changed = False)                                                              
            
            """
            ALL SETs            
             - potom bude parametr refreh v datastore zbytecny                                    
            """            
            
            """
            """
            if dstore.Get("com_init") != 0:
                dstore.Set("com_init", dstore.Get("com_init") - 1)
            
            
            dstore.SetItem("systemcheck", ["wdg_comm"],  dstore.GetItem("systemcheck", ["wdg_comm"])+1) 
Beispiel #9
0
    def setDataFromDict(self, mydict):
        print "setDataFromDict()", mydict, self.name
                        
        #dict => df
        dfChange = pd.DataFrame([mydict])
        dfChange.set_index(dfChange.id, inplace=True)                   
                       
        #take row before change (from global df)
        dfChangedRow = self.df.loc[dfChange.id]
        #take user before change                                                        
        old_user = tableUsers.model.getUserParNr(int(dfChangedRow['nr']))
               
        #update row before change with change                 
        dfChangedRow.update(dfChange)        
        
        #category changed        
        if "nr" in mydict:            
                                                                        
            user_id = self.checkChangedNumber(dfChangedRow.iloc[0])                                                                                            
            if user_id == None: #dialog inside checkChangedNumber()
                return False
            
            #adjust dict for writing to db
            mydict["user_id"] = user_id
            if mydict["nr"] < 0:                       
                mydict["us1"] = "Civil #"+str(abs(mydict["nr"]))
            del mydict["nr"]                            
                                         
        elif "cell" in mydict:                                                                      
            pass
                      
        # TIMERAW column
        elif "timeraw" in mydict:   
                              
            try:
                dbTimeraw = TimesUtils.TimesUtils.timestring2time(mydict['timeraw'])
            except TimesUtils.TimeFormat_Error:
                uiAccesories.showMessage(self.name+" Update error", "Wrong Time format!")
                return False
            
            #adjust dict for writing to db
            mydict["time_raw"] = dbTimeraw
            del mydict["timeraw"]            

            #change the state (C -> manually Changed)            
            state = str(dfChangedRow.iloc[0]['state'])         
            mydict["state"] = "C" + state[1] + state[2]            
            

        elif "un1" in mydict:
            pass 
        elif "un2" in mydict:
            pass 
        elif "un3" in mydict:
            pass 
        elif "us1" in mydict:
            pass 
        else:
            uiAccesories.showMessage(self.name+" Update error", "Unexpecting change!")
            return False                                                                                         
                                    
        # add changed row to "changed_rows"
        # keep as dataframe otherwise float issues for "nr" and "cell"
        cleared = self.ClearCalculated(dfChangedRow.iloc[0].copy())                                                                                
        self.changed_rows = self.changed_rows.append(cleared)
        try:
            self.changed_rows["nr"] = int(self.changed_rows["nr"])                           
            self.changed_rows["cell"] = int(self.changed_rows["cell"])                           
        except:
            pass        
        eventCalcReady.clear() #s                                 
                                                                                            
        #update db from mydict            
        db.update_from_dict(self.name, mydict)
        
        #user changed => reset all times for new user
        if mydict and ("user_id" in mydict):
            #print "mazu vsechny1", mydict["user_id"]
            self.ResetCalculatedValuesForUser(mydict["user_id"])        

        #reset 1 time
        elif mydict and ("id" in mydict):
            #print "mazu neco", mydict["id"]
            self.ResetCalculatedValues(mydict["id"])
        
        if old_user and ("id" in old_user):
            print "mazu vsechny2", old_user["id"]
            self.ResetCalculatedValuesForUser(old_user["id"])
                
        #self.ResetNrOfLaps()  
        eventCalcNow.set()
        return True