-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcoos3.py
More file actions
149 lines (127 loc) · 4.49 KB
/
gcoos3.py
File metadata and controls
149 lines (127 loc) · 4.49 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import sqlite3
connection = sqlite3.connect("D:\database_new_2\gcoos_data_v3.sqlite")
connection2 = sqlite3.connect("D:\database_new\gcoos_data_v2.sqlite")
connection3 = sqlite3.connect("D:\database_new\gcoos_data_v1.sqlite")
crsr = connection.cursor()
crsr2 = connection2.cursor()
crsr3 = connection3.cursor()
sensortypeId = [1,2,3,4,5,6,8,9,10,14,15,17,24]
b,g=[],[]
l,q=0,0
z=0
for i in sensortypeId:
crsr.execute('''SELECT rowId from sensor where (lastObsDate = "" or lastObsDate = NULL) and sensorTypeId ==?''',(i,))
ans = crsr.fetchall()
rowId_missing = []
q=0
for k in ans:
rowId_missing.insert(q,k[0])
q=q+1
crsr.execute('''SELECT rowId from sensor where (firstObsDate = "" or firstObsDate = NULL) and sensorTypeId ==?''',(i,))
ans_first = crsr.fetchall()
rowId_missing_first = []
q_first=0
for k in ans_first:
rowId_missing_first.insert(q,k[0])
q_first = q_first+1
if i in (1,2,4,6,8,9,10,14,17):
crsr.execute('''select typeName from sensorType where rowId = ?''',(i,))
sensor_name_1= crsr.fetchall()
sensor_name_2 = sensor_name_1[0][0]
# print(sensor_name_2)
elif i == 5:
sensor_name_2 = 'oceanCurrents'
# print(sensor_name_2)
elif i == 3:
sensor_name_2 = 'wave'
# print(sensor_name_2)
elif i == 15:
sensor_name_2 = 'relhumidity'
# print(sensor_name_2)
elif i == 24:
sensor_name_2 = 'dewPoint'
# print(sensor_name_2)
k,m,n,o,p=0,0,0,0,0
a,c,d,e,f=[],[],[],[],[]
for j in rowId_missing:
crsr.execute("select sensorId, max(observationDate) from '" + sensor_name_2 + "' where sensorId ==?",(j,))
ans2 = (crsr.fetchall())
if ans2[0][0] == None:
a.insert(k,j)
k=k+1
else:
b.insert(l,[j,ans2[0][1]])
l=l+1
for j in a:
crsr2.execute("select sensorId, max(observationDate) from '" + sensor_name_2 + "' where sensorId ==?",(j,))
ans3 = (crsr2.fetchall())
if ans3[0][0] == None:
c.insert(m,j)
m=m+1
else:
b.insert(l,[j,ans3[0][1]])
l=l+1
for j in c:
crsr3.execute("select sensorId, max(observationDate) from '" + sensor_name_2 + "' where sensorId ==?",(j,))
ans4 = (crsr3.fetchall())
if ans4[0][0] == None:
b.insert(l,[j,''])
l=l+1
else:
b.insert(l,[j,ans4[0][1]])
l=l+1
for z in rowId_missing_first:
crsr3.execute("select sensorId, min(observationDate) from '" + sensor_name_2 + "' where sensorId ==?",(z,))
ans2_first = (crsr3.fetchall())
if ans2_first[0][0] == None:
d.insert(n,z)
n=n+1
else:
g.insert(q,[z,ans2_first[0][1]])
q=q+1
for z in d:
crsr2.execute("select sensorId, min(observationDate) from '" + sensor_name_2 + "' where sensorId ==?",(z,))
ans3_first = (crsr2.fetchall())
if ans3_first[0][0] == None:
e.insert(o,z)
o=o+1
else:
g.insert(q,[z,ans3_first[0][1]])
q=q+1
for z in e:
crsr.execute("select sensorId, min(observationDate) from '" + sensor_name_2 + "' where sensorId ==?",(z,))
ans4_first = (crsr.fetchall())
if ans4_first[0][0] == None:
g.insert(q,[z,''])
q=q+1
else:
g.insert(q,[z,ans4_first[0][1]])
q=q+1
h=0
for i in range(len(b)):
# print(b[i])
h=h+1
print(h)
r=0
for i in range(len(g)):
# print(g[i])
r=r+1
print(r)
v=[]
s=0
for i in range(len(b)):
for j in range(len(g)):
if b[i][0] == g[j][0]:
v.insert(s,[b[i][0],b[i][1],g[j][1]])
s=s+1
# for i in [373,374,410,644,650,651,927,1864,2637,2977,2983,2999,3004,3014,3285,3321,3468,3469,3489,3490,3491]:
for i in range(len(g)):
for j in (373,374,410,644,650,651,927,1864,2637,2977,2983,2999,3004,3014,3285,3321,3468,3469,3489,3490,3491):
if g[i][0] == j:
print("update sensor set firstObsDate = '"+g[i][1]+"' where rowId ="+str(g[i][0]))
# y=0
# for i in range(len(v)):
# print("UPDATE sensor SET firstObsDate = '"+str(v[i][2])+"' AND lastObsDate = '"+str(v[i][1])+"' WHERE rowId ="+str(v[i][0]))
connection.close()
connection2.close()
connection3.close()