-
Notifications
You must be signed in to change notification settings - Fork 2
/
autofill.py
100 lines (72 loc) · 2.13 KB
/
autofill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import csv
from datetime import datetime
import time
import calendar
path = input("Enter the File name with .csv extension, default : 'data/clean-out.csv'.")
if path == "":
path = "data/clean-out.csv"
print(path)
df=pd.read_csv(path)
newdf=df
s1=df.loc[0].time
s2=df.loc[1].time
FMT = '%H:%M:%S'
tdelta = (datetime.strptime(s2, FMT) - datetime.strptime(s1, FMT))*2
w1= df.loc[0].time
w2= df.loc[1].time
h1, m1, s1 = w1.split(':')
h2, m2, s2 = w2.split(':')
t1=int(h1) * 3600 + int(m1) * 60 +int(s1)
t2=int(h2) * 3600 + int(m2) * 60 +int(s2)
interval=int(m2)-int(m1)
interval
try:
from itertools import product
except ImportError:
def product(*seqs):
if len(seqs) == 2:
for s1 in seqs[0]:
for s2 in seqs[1]:
yield (s1,s2)
else:
for s in seqs[0]:
for p in product(*seqs[1:]):
yield (s,) + p
hhmmss = {}
i = 0
for (h,m,s) in product(range(24),range(60),range(60)):
hhmmss[i] = "%02d:%02d:%02d" % (h,m,s)
i += 1
count=0
counter=0
for index, row in df.iterrows():
print(index)
if(index>0):
w1= df.loc[index].time
h1, m1, s1 = w1.split(':')
w2= df.loc[index-1].time
h2, m2, s2 = w2.split(':')
current_hour=int(h1)
prev_hour=int(h2)
prev_hour_str=h2
current_min=int(m1)
prev_min=int(m2)
prev_min_str=m2
if(prev_min>current_min):
current_min=current_min+60
if(current_min-prev_min == interval):
print('fine')
else:
prev_min=prev_min+interval
prev_min=prev_min % 60
strin= prev_hour_str + ':' + prev_min_str + ':' + '00'
newdf.loc[counter,'date'] = df.loc[index,'date']
newdf.loc[counter,'time'] = strin
newdf.loc[counter,'value'] = -1
counter=counter+1
newdf = newdf[newdf['value']== -1]
newdf.to_csv('data/autofill-out.csv', index=False)
print('data/autofill-out.csv')