-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathontologyStopEvent.py
248 lines (210 loc) · 7.92 KB
/
ontologyStopEvent.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
from Point import GPSPoint
import math
import sendDataToApiOntology
import datetime
s= 0.5
speedAccuracy= 0.1
orientationAccuracy= 10
tabDegrees= []
tabDegrees2= []
sensors= []
def medianeF(f1, f2, f3):
f= [f1, f2, f3]
return (max(f) + min(f))/2
def mediane(p1, p2, p3):
lat= [p1.lat, p2.lat, p3.lat]
long= [p1.long, p2.long, p3.long]
minLat= min(lat)
maxLat= max(lat)
minLong= min(long)
maxLong= max(long)
mediane= GPSPoint()
mediane.lat= (minLat+maxLat)/2
mediane.long= (minLong+maxLong)/2
mediane.timestamp= p2.timestamp
return mediane
def ontologyPorcessing(dataDict, store):
print "Ontology processing..."
fusedTraj = {}
'''
longTab= []
latTab= []
iTab = []
for object in dataDict:
iTab= range(0, len(dataDict[object]["trajectory"]))
for p in dataDict[object]["trajectory"]:
longTab.append(p[1][0])
latTab.append(p[1][1])
break
plt.plot(latTab, longTab)
#plt.show()
'''
for object in dataDict:
fusedTraj[object] = {}
fusedTraj[object]["trajectory"] = []
fusedTraj[object]["sensor"] = dataDict[object]["sensor"]
points= []
#reduction de l'echantillonnage
first_point= dataDict[object]["trajectory"][0]
point = GPSPoint();
point.long = first_point[1][0]
point.lat = first_point[1][1]
point.timestamp = first_point[0]
points.append(point)
for p in dataDict[object]["trajectory"]:
if (p[0] - first_point[0]) >= datetime.timedelta(seconds=1):
point = GPSPoint()
point.long = p[1][0]
point.lat = p[1][1]
point.timestamp= p[0]
points.append(point)
first_point = p
# points lisses
mPoints = []
# distance entre deux points lisses
distance = []
mDistance = []
mTemps = []
temps= []
# Recuperation et lissage des points
i = 0
for point in points:
# Lissage des points et acquisition des distances et deltaT
fusedTraj[object]["trajectory"].append([])
index = points.index(point)
coordinates = []
if (index + 1 < len(points)):
pAfter = points[index + 1]
# calcul de l'azimut (orientation) avec les valeurs brutes
x = math.cos(point.lat) * math.sin(pAfter.lat) - math.sin(point.lat) * math.cos(pAfter.lat) * math.cos(
pAfter.long - point.long)
y = math.sin(pAfter.long - point.long) * math.cos(pAfter.lat)
azimut = math.atan2(y, x)
degrees = math.degrees(azimut) + 180
# print degrees
tabDegrees.append(degrees)
if (index - 1 >= 0):
pBefore = points[index - 1]
medianePoint = mediane(pBefore, point, pAfter)
fusedTraj[object]["trajectory"][index].append(medianePoint.timestamp)
mPoints.append(medianePoint)
coordinates.append(medianePoint.long)
coordinates.append(medianePoint.lat)
mIndex = mPoints.index(medianePoint)
mBefore = mPoints[mIndex - 1]
deltaD = mBefore.distanceTo(medianePoint)
distance.append(deltaD)
medianePoint.deltaT = (medianePoint.timestamp - pBefore.timestamp).total_seconds()
temps.append(medianePoint.deltaT)
else:
coordinates.append(point.long)
coordinates.append(point.lat)
mPoints.append(point)
distance.append(0)
temps.append(0)
fusedTraj[object]["trajectory"][index].append(point.timestamp)
fusedTraj[object]["trajectory"][index].append(coordinates)
else:
coordinates.append(point.long)
coordinates.append(point.lat)
fusedTraj[object]["trajectory"][index].append(point.timestamp)
fusedTraj[object]["trajectory"][index].append(coordinates)
mPoints.append(point)
distance.append(0)
temps.append(0)
i += 1
i = 0
# calcul de l'azimuth avec les points lisses
for point in mPoints:
index = mPoints.index(point)
if (index + 1 < len(mPoints)):
pAfter = mPoints[index + 1]
x = math.cos(point.lat) * math.sin(pAfter.lat) - math.sin(point.lat) * math.cos(
pAfter.lat) * math.cos(
pAfter.long - point.long)
y = math.sin(pAfter.long - point.long) * math.cos(pAfter.lat)
azimut = math.atan2(y, x)
degrees = math.degrees(azimut) + 180
# calcul de l'azimuth accuracy
oldDegree = tabDegrees[i]
diff = abs(degrees - oldDegree)
diffMin = min(diff, 360 - diff)
if diffMin > orientationAccuracy:
percent = orientationAccuracy / diffMin
else:
percent = 1.0
else:
degrees = 0
percent = 0
fusedTraj[object]["trajectory"][i].append(degrees)
fusedTraj[object]["trajectory"][i].append(percent)
i += 1
# lissage des distances
for d in distance:
index = distance.index(d)
if (index - 1 >= 0 and index + 1 < len(distance)):
dBefore = distance[index - 1]
dAfter = distance[index + 1]
medianeDistance = medianeF(dBefore, d, dAfter)
mDistance.append(medianeDistance)
else:
mDistance.append(d)
for t in temps:
index = temps.index(t)
if (index - 1 >= 0 and index + 1 < len(temps)):
tBefore = temps[index - 1]
tAfter = temps[index + 1]
medianeTemps = medianeF(tBefore, t, tAfter)
mTemps.append(medianeTemps)
else:
mTemps.append(t)
vitesses = []
mVitesse = []
i = 0
for t in mTemps:
d = mDistance[i]
if (t != 0):
v = d / t
else:
v = 0
vitesses.append(v)
i += 1
i = 0
for v in vitesses:
index = vitesses.index(v)
if (index - 1 >= 0 and index + 1 < len(vitesses)):
vBefore = vitesses[index - 1]
vAfter = vitesses[index + 1]
medianeVitesse = medianeF(vBefore, v, vAfter)
mVitesse.append(medianeVitesse)
else:
medianeVitesse = v
mVitesse.append(v)
fusedTraj[object]["trajectory"][i].append(medianeVitesse)
if medianeVitesse <= s:
moveState = "Stopping"
else:
moveState = "Walking"
fusedTraj[object]["trajectory"][i].append(moveState)
#print dataDict[object]["trajectory"][i]
# calcul du pourcentage de la speedAccuracy de la vitesse
dist = abs(v - medianeVitesse)
if (dist >= speedAccuracy):
percent = speedAccuracy / dist
else:
percent = 1.0
fusedTraj[object]["trajectory"][i].append(percent)
i += 1
'''
longTab2= []
latTab2= []
for object in fusedTraj:
for p in fusedTraj[object]["trajectory"]:
longTab2.append(p[1][0])#+0.000001001)
latTab2.append(p[1][1])#+0.000001001)
iTab2= range(0, len(fusedTraj[object]["trajectory"]))
break
plt.plot(latTab2, longTab2)
#plt.show()
'''
sendDataToApiOntology.sendData(fusedTraj, store)