예제 #1
0
 def ResetNrOfLaps(self):
     query = \
             " UPDATE times" +\
                 " SET lap1 = Null, lap2 = Null, lap3 = Null, lap4 = Null"
     res = db.query(query)
     db.commit()
     return res
예제 #2
0
 def ResetCalculatedValuesForUser(self, user_id):
     query = \
             " UPDATE times" +\
                 " SET time1 = Null, lap1 = Null, time2 = Null, lap2 = Null, time3 = Null, lap3 = Null, time4 = Null, lap4 = Null" +\
                 " WHERE (times.user_id = \""+str(user_id)+"\")"
     res = db.query(query) 
     db.commit()
     return res
예제 #3
0
    def sImport(self):
        """import"""                                         
                                           
        #gui dialog                        
        filename = uiAccesories.getOpenFileName("Import CSV to table "+self.name,"dir_import_csv","Csv Files (*.csv)", self.name+".csv")                
        
        #cancel or close window
        if(filename == ""):                        
            return        
                  
        #IMPORT CSV TO DATABASE         
            
        #load csv to df
        try:            
            df = pd.DataFrame.from_csv(str(filename), sep=";", encoding = "utf8")
            #df.drop([df.columns[-1]], axis=1, inplace=True)
            df.fillna("", inplace=True)                        
        except:
            uiAccesories.showMessage(self.name+" CSV Import", "NOT Succesfully imported\n empty file or wrong format")
            return
        
        df["id"] = df.index

        #callback
        try:
            df = self.importDf2dbDdf(df)
        except KeyError:
            title = "Table '"+self.name + "' CSV Import"
            uiAccesories.showMessage(title, "NOT Succesfully"+"\n\n" +"Wrong format or not existing data.")
            return
        
        #counters
        state = {'ko':0, 'ok':0}
        
        #adding rows to DB                        
        for i,row in df.iterrows():
            
            try:
                self.importRow2dbRow(row)
            except:
                state['ko'] += 1
                continue
                 
            #to dict because of CZ
            row = dict(row)       
                                                         
            #if(db.insert_from_lists(self.name, columns, row, commit_flag = False) != False):
            if(db.insert_from_dict(self.name, row, commit = False) != False):
                                                                      
                state['ok'] += 1
            else:            
                state['ko'] += 1 #increment errors for error message                

        db.commit()                        
        self.model.Update()
        self.sImportDialog(state)
예제 #4
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
예제 #5
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                    
예제 #6
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