new = {('E_1E_2', 1.0235591568933329): [datetime.datetime(2019, 6, 25, 4, 38, 47)],
('E_1E_2', 0.9023917716540885): [datetime.datetime(2019, 6, 25, 4, 38, 51)],
('E_12E_2', 1.4927612857980848): [datetime.datetime(2019, 6, 25, 3, 18, 42)],
('E12_1E_2', 1.0235591568933329): [datetime.datetime(2019, 6, 25, 3, 30, 17)],
('E_1E_2', 0.9023917716540885): [datetime.datetime(2019, 6, 25, 3, 13, 51)],
('E_1E_2', 1.4927612857980848): [datetime.datetime(2019, 6, 25, 3, 8, 42)]}
这是我的数据输入的样子。我需要显示学生每小时完成任务所花费的时间。字典键由完成任务的学生对和他们之间的距离组成。该值由它们彼此靠近的时间戳组成。
tasktime=0
prev=datetime.datetime(1,1,1)
for i,j in new.items():
#print(k[0],k[1])
print(i[0],"-------------------------------------------------")
for k,l in new.items():
if i[0]==k[0]:
if k[1] < 1 and len(l)==1 and j[0].hour==l[0].hour:
print("distance=======",k[1])
print(l[0].hour,i[0],l)
if (k[0],l[0]) not in sample.keys():
sample[k[0],l[0].hour]=0
if prev==datetime.datetime(1,1,1):
prev=l[0]
else:
diff=(l[0]-prev).seconds
tasktime=tasktime+diff
prev=l[0]
elif loitime!=0 and k[1] > 1:
print(k[0],"loitered for ",tasktime/60,"minutes")
print("timestamp ++++++++++++++++",l[0])
我得到了他们完成全部数据所需的时间,而不是每小时。