def run(self, q, processdict): print "I:P: CALC: zakladam process.." self.dstore = ProcessDstore(processdict) myevent2.set() """ DATABASE """ try: self.db = db_utils.connect("db/test_db.sqlite") except: print "E: Database" while(1): #delay ztime = time.clock() self.timesDfs = [pd.DataFrame(), pd.DataFrame(), pd.DataFrame()] self.lapsDfs = [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 "P: C: GetJoinedDf() 1", time.clock() - ytime,"s" """ update times """ ytime = time.clock() self.GetTimesDfs() self.UpdateTimes(self.timesDfs) self.GetJoinedDf() #print "P: C: UpdateTimes()", time.clock() - ytime,"s" #print "P: 2: ucDf", self.joinedDf #laps ytime = time.clock() self.GetLapsDfs() self.UpdateLaps(self.lapsDfs) self.GetJoinedDf() #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) #sort and copy ytime = time.clock() if self.joinedDf.empty: self.joinedDfFreeze = pd.DataFrame() print "NIC" else: columns = [item[0] for item in sorted(DEF_COLUMN.TIMES['table'].items(), key = lambda (k,v): (v["index"]))] self.joinedDfFreeze = self.joinedDf[columns].copy() #print "P: C: sort and copy", time.clock() - ytime,"s" #print(".",end='') #print "P: I: Calc: COMPLETE", time.clock() - ztime,"s" #print "===============================================" #print 'process id:', os.getpid() self.joinedDfFreeze["name"].iloc[0] = self.i self.i = self.i +1 self.joinedDfFreeze = getDf() time.sleep(0.1) q.put(self.joinedDfFreeze) print "P: name: ",self.joinedDfFreeze["name"].iloc[0], q.empty() sys.stdout.flush() #print "P: df", self.joinedDfFreeze # sys.stdout.write('.') # self.calctime = time.clock() - ztime # if self.calctime > self.maxcalctime: # self.maxcalctime = self.calctime # print "MAX CALC-TIME:", self.maxcalctime # time.sleep(2)
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()