MCPcopy Create free account
hub / github.com/RocketMap/RocketMap / main

Function main

Tools/Spawnpoint-Clustering/cluster.py:123–184  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

121 assert cluster.min_time <= p.time <= cluster.max_time
122
123def main(args):
124 radius = args.radius
125 time_threshold = args.time_threshold
126
127 with open(args.filename, 'r') as f:
128 rows = json.loads(f.read())
129
130 spawnpoints = [Spawnpoint(x) for x in rows]
131
132 print 'Processing', len(spawnpoints), 'spawnpoints...'
133
134 start_time = time.time()
135 clusters = cluster(spawnpoints, radius, time_threshold)
136 end_time = time.time()
137
138 print 'Completed in {:.2f} seconds.'.format(end_time - start_time)
139 print len(clusters), 'clusters found.'
140 print '{:.2f}% compression achieved.'.format(100.0 * len(clusters) / len(spawnpoints))
141
142 try:
143 for c in clusters:
144 test(c, radius, time_threshold)
145 except AssertionError:
146 print 'error: something\'s seriously broken.&#x27;
147 raise
148
149 # clusters.sort(key=lambda x: len(x))
150
151 if args.output_clusters:
152 rows = []
153 for c in clusters:
154 row = dict()
155 row['spawnpoints'] = [x.serialize() for x in c]
156 row['latitude'] = c.centroid[0]
157 row['longitude'] = c.centroid[1]
158 row['min_time'] = c.min_time
159 row['max_time'] = c.max_time
160 rows.append(row)
161
162 with open(args.output_clusters, 'w') as f:
163 f.write(json.dumps(rows, indent=4, separators=(',', ': ')))
164
165 if args.output_spawnpoints:
166 rows = []
167 for c in clusters:
168 row = dict()
169 # pick a random id from a clustered spawnpoint
170 # we should probably not do this
171 if args.long_keys:
172 row['spawnpoint_id'] = random.choice(c).spawnpoint_id
173 row['latitude'] = c.centroid[0]
174 row['longitude'] = c.centroid[1]
175 else:
176 row['sid'] = random.choice(c).spawnpoint_id
177 row['lat'] = c.centroid[0]
178 row['lng'] = c.centroid[1]
179 # pick the latest time so earlier spawnpoints have already spawned
180 row['time'] = c.max_time

Callers 1

cluster.pyFile · 0.70

Calls 5

SpawnpointClass · 0.85
clusterFunction · 0.85
testFunction · 0.85
serializeMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected