2024-06-08 12:14:20 发布
网友
所以我想对智能家居的数据库数据进行分析。我的数据是这样的:
ID NAME STATUS TIME 1 light 1 2016-06-25 08:00:00 2 light 1 2016-06-25 08:01:05 3 light 1 2016-06-25 08:00:21 4 light 1 2016-06-25 08:00:30 ...
基本上,我所需要的就是除以(某个时刻的灯亮的次数)除以某个时刻的不同日期。在
此脚本从数据库中获取最短和最长时间,并计算这些时间之间的时间。在
# db.txt 1 light 1 2016-06-25 08:00:00 1 light 1 2016-06-25 08:01:05 1 light 1 2016-06-25 08:00:21 1 light 1 2016-06-25 08:00:30 # python script import datetime def data(): with open('db.txt', 'r') as f: for line in f.readlines(): row = line.split() if row[2] == '1': yield row[4] data = sorted(data()) early = datetime.datetime.strptime(data[0], '%H:%M:%S') lately = datetime.datetime.strptime(data[1], '%H:%M:%S') sth_between = (lately - early)/2 print (early + sth_between).time()
此脚本从数据库中获取最短和最长时间,并计算这些时间之间的时间。在
相关问题 更多 >
编程相关推荐