python - How Do I Keep Total Time with Multiple Duplicate Entries? -


i attach code, importing csv file start times/end times picking cases of particular item. cases go "cart", identified id number. want find total time pick cases. format of time hh:mm:ss and, initially, using datetime module not figure out documentation, ended converting times seconds, subtracting end/start each case, , adding duration total time. in end, converted total time hours. had number of cases picked total, , divided total time in hrs cases picked per hr. correct logic? got number very, low: 7.99 cases/hr, leads me believe timing/duration code incorrect (already checked quantity correct).

#instantiate totaltime 0 totaltime = 0  #every line/row in file; assume opened above line in lines:      #if there different case pick, find start time     if taskid != entrylist[0]: #this doesnt duplicate times          timestart = entrylist[7]         colonstartindex = timestart.find(":")         hourstart = int(timestart[0:colonstartindex])         minutestart = int(timestart[colonstartindex+1:colonstartindex+3])         colonstartindex2 = timestart.find(":", colonstartindex+1)         secondstart = int(timestart[colonstartindex2 +1:colonstartindex2 +3])         start = hourstart*3600 + minutestart*60 + secondstart          #start = datetime(year=1, month=1, day=1,hour=hourstart,minute=minutestart,second=secondstart)         #start = datetime.time(start)          timeend = entrylist[9]         colonendindex = timeend.find(":")         hourend = int(timeend[0:colonendindex])         minuteend = int(timeend[colonendindex+1:colonendindex+3])         colonendindex2 = timeend.find(":", colonendindex+1)         secondend = int(timeend[colonendindex2+1:colonendindex2+3])         end = hourend*3600 + minuteend*60 + secondend          #end = datetime(year=1,month=1,day=1,hour=hourend,minute=minuteend,second=secondend)         #end = datetime.time(end)         #duration = datetime.combine(date.today(), end) - datetime.combine(date.today(), start)          duration = end - start         if duration >= 0:             duration = duration         elif duration < 0:             duration = -1*duration         totaltime = totaltime + duration         taskid = entrylist[0] #first entry in csv file of each line cartid    totaltime = totaltime/3600 print(totaltime) print(quantitycount) avgnumcases = quantitycount/totaltime print(avgnumcases) 

thank help!! also, included datetime stuff, commented out, if suggest solution based on that, open it:) frustrated because spent bit of time trying figure out, i'm not super familiar w , documentation pretty hard understand (esp b/c datetime objects, blah blah)

there obvious problem in section:

duration = end - start if duration >= 0:     duration = duration elif duration < 0:     duration = -1*duration 

if start point 22:00:00 , end point 21:00:00 duration 1 hour instead of 23 hours.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -