@@ -14,6 +14,7 @@ import sys
14
14
import pandas as pd
15
15
import collections
16
16
from fractions import Fraction
17
+ import json
17
18
# import yaml
18
19
# from sailing_robot.navigation import Navigation
19
20
@@ -29,10 +30,10 @@ def latlon_to_utm(lat, lon):
29
30
"""Returns (x, y) coordinates in metres"""
30
31
return projection (lon , lat )
31
32
32
- # def utm_to_latlon(x, y ):
33
- # """Returns a LatLon object"""
34
- # lon, lat = projection(x, y , inverse=True)
35
- # return LatLon( lat, lon)
33
+ def utm_to_latlon (coord ):
34
+ """Returns a LatLon object"""
35
+ lon , lat = projection (coord [ 0 ], coord [ 1 ] , inverse = True )
36
+ return lat , lon
36
37
37
38
38
39
@@ -41,7 +42,7 @@ def latlon_to_utm(lat, lon):
41
42
# Lat *10^^7
42
43
# Lon *10^^7
43
44
44
- # C
45
+ # C D
45
46
# +-+-+-+-+-+
46
47
# +-+-+-+-+-+
47
48
# +-+-+-+-+-+
@@ -55,7 +56,7 @@ def latlon_to_utm(lat, lon):
55
56
# Number of subdivision of the grid
56
57
subY = 58
57
58
subX = 45
58
-
59
+ cell_size = 4
59
60
60
61
# gps log file given as the 2nd argument
61
62
# cvs_file = sys.argv[2]
@@ -88,8 +89,16 @@ vAB_orth = vAC
88
89
# vAB_orth = np.array([-vAB[1], vAB[0]])
89
90
90
91
91
-
92
-
92
+ def cell_ij_to_coord (i ,j ):
93
+ A = wpA_utm + vAB * cell_size * i + vAB_orth * cell_size * j
94
+ B = A + vAB_orth * cell_size
95
+ C = B + vAB * cell_size
96
+ D = A + vAB * cell_size
97
+ A = utm_to_latlon (A )
98
+ B = utm_to_latlon (B )
99
+ C = utm_to_latlon (C )
100
+ D = utm_to_latlon (D )
101
+ return A ,B ,C ,D
93
102
94
103
95
104
def generate_visit_set (filename ):
@@ -106,8 +115,8 @@ def generate_visit_set(filename):
106
115
for point in position_utm :
107
116
# projection of point in the (wpA_utm; vAB,vAB_orth) base
108
117
point_base = [point [0 ] - wpA_utm [0 ], point [1 ] - wpA_utm [1 ]]
109
- point_i = np .dot (point_base , vAB )* subX / 2 / AB
110
- point_j = np .dot (point_base , vAB_orth )* subY / 2 / AC
118
+ point_i = np .dot (point_base , vAB )* subX / AB
119
+ point_j = np .dot (point_base , vAB_orth )* subY / AC
111
120
112
121
if point_i < 0 or point_j < 0 or point_i > subX or point_j > subY :
113
122
continue
@@ -127,8 +136,17 @@ CellVisitors = collections.namedtuple('CellVisitors', 'in_window out_of_window')
127
136
# in_window
128
137
master_data = pd .read_csv (sys .argv [1 ])
129
138
master_data ['visit_set' ] = master_data .filename .apply (generate_visit_set )
139
+ attempt_per_cell = collections .defaultdict (int )
130
140
for row in master_data .itertuples ():
131
141
print (row .filename , len (row .visit_set ))
142
+ for cell_pos in row .visit_set :
143
+ attempt_per_cell [cell_pos ] += 1
144
+
145
+ data = []
146
+ for cell , count in attempt_per_cell .items ():
147
+ data .append ([cell_ij_to_coord (cell [0 ],cell [1 ]), count ])
148
+ with open ("heat_map_data" + sys .argv [1 ]+ ".json" ,'w' ) as f :
149
+ json .dump (data ,f )
132
150
133
151
# Build map of what teams visited which cells, in their in-window and out-of-window attempts
134
152
cell_visits = collections .defaultdict (lambda : CellVisitors (set (), set ()))
0 commit comments