def GetDataframe(self): df = mgr.GetDfs()["table"] if eventCalcReady.is_set() == False: for index, row in self.changed_rows.iterrows(): if index in df.index: df.loc[index] = row else: self.changed_rows = pd.DataFrame() return df
def GetDataframe(self): df = mgr.GetDfs()["table"] if eventCalcReady.is_set() == False: for index, row in self.changed_rows.iterrows(): if index in df.index: df.loc[index] = row else: self.changed_rows = pd.DataFrame() #ToDo: remove #mynr = len(df.index) #print "mynr:", mynr #if(mynr > self.mynr): # print "TT: new record", time.clock() #self.mynr = mynr return df
def run(self, dstore, dfs, info, eventCalcNow, eventCalcReady): print "I:P: CALC: zakladam process.." #, dstore self.dstore = ProcessDstore(dstore) print "I:P: CALC: dstore.." #, self.dstore.GetData() #myevent2.set() """ DATABASE """ try: self.db = db_utils.connect("db/test_db.sqlite") except: print "E: Database" sys.stdout = sys.__stdout__ complete_calc_flag = False while(1): # if(eventCalcReady.is_set() == False): complete_calc_flag = True #delay ztime = time.clock() self.timesDfs = [pd.DataFrame(), pd.DataFrame(), pd.DataFrame(), pd.DataFrame()] self.lapsDfs = [pd.DataFrame(), pd.DataFrame(), pd.DataFrame(), pd.DataFrame()] self.orderDfs = [{'total':pd.DataFrame(), "category": None}, {'total':pd.DataFrame(), "category": None}, {'total':pd.DataFrame(), "category": None}] """ update DFs """ ytime = time.clock() self.ucDf = self.GetUserCategoryDf() #print "P: C: GetUserCategoryDf()", time.clock() - ytime,"s" """ update joined DF""" ytime = time.clock() self.GetJoinedDf() #print "#1", self.joinedDf #print "P: C: GetJoinedDf() 1", time.clock() - ytime,"s" """ update times """ ytime = time.clock() self.GetTimesDfs() self.UpdateTimes(self.timesDfs) self.GetJoinedDf() #print "#2", self.joinedDf #print "TTT", self.joinedDf.loc[2237] #print "P: C: UpdateTimes()", time.clock() - ytime,"s" #laps ytime = time.clock() self.GetLapsDfs() self.UpdateLaps(self.lapsDfs) self.GetJoinedDf() #print "#3", self.joinedDf #print "P: C: UpdateLaps()", time.clock() - ytime,"s" #orderX self.orderDfs = self.GetOrderDfs() ytime = time.clock() self.joinedDf = self.UpdateOrder() #print "P: C: UpdateOrder() 1", time.clock() - ytime,"s" #points ytime = time.clock() self.joinedDf = self.UpdatePoints(self.joinedDf) #print "P: C: UpdatePoints()", time.clock() - ytime,"s" #orderX ytime = time.clock() self.GetOrderDfs() ytime = time.clock() self.UpdateOrder() #print "P: C: UpdateOrder() 1", time.clock() - ytime,"s" #update status #self.joinedDf = self.GetJoinedDf() #convert times to string format self.joinedDf = self.df2tableDf(self.joinedDf) #time.sleep(6) #sort and copy ytime = time.clock() if self.joinedDf.empty: dfs["table"] = pd.DataFrame() else: columns = [item[0] for item in sorted(DEF_COLUMN.TIMES['table'].items(), key = lambda (k,v): (v["index"]))] #self.joinedDf.loc[self.joinedDf.user_id == 0, self.joinedDf.columns - ["id", "cell"]] = None self.joinedDf.loc[self.joinedDf.user_id == 0, ["nr", "name", "category", "start_nr", "time1", "time2", "time3", "time4", "lap1", "lap2", "lap3", "lap4"]] = [0, "UNKNOWN unknown", "not def", 1, None, None, None, None, None, None, None, None] #print self.joinedDf #self.joinedDf.loc[pd.isnull(self.joinedDf.nr) , ["nr", "name", "category", "start_nr", "time1", "time2", "time3", "lap1", "lap2", "lap3"]] = [0, "UNKNOWN user id: "+self.joinedDf[pd.isnull(self.joinedDf.nr)]["user_id"].astype(str), "not def", 1, None, None, None, None, None, None] self.joinedDf.loc[pd.isnull(self.joinedDf.nr) , ["nr", "name", "category", "start_nr", "time1", "time2", "time3", "time4", "lap1", "lap2", "lap3", "lap4"]] = [0, "UNKNOWN user", "not def", 1, None, None, None, None, None, None, None, None] #print self.joinedDf #umele pretypovani na long, defaultne float a 7.00 self.joinedDf["nr"] = self.joinedDf["nr"].astype(long) dfs["table"] = self.joinedDf[columns].copy() if(complete_calc_flag): eventCalcReady.set() #print "P: C: sort and copy", time.clock() - ytime,"s" #print "P: I: Calc: COMPLETE", time.clock() - ztime,"s" #print 'process id:', os.getpid() sys.stdout.write('.') info["wdg_calc"] = info["wdg_calc"] + 1 info["lastcalctime"] = time.clock() - ztime if info["lastcalctime"] > self.maxcalctime: self.maxcalctime = info["lastcalctime"] print "MAX CALC-TIME:", self.maxcalctime sys.stdout.flush() eventCalcNow.wait(2) eventCalcNow.clear()