from bottle import get, post, run, request
import uuid
-from geo import distance
+from geo import distance, move_coordinate
from street_predictor import parse_summary
from osm.osm import describe_objects
self.tips = []
self.shown_tips = []
+ def move(self, direction, value=100):
+ if direction == 'north':
+ self.current_coordinates = move_coordinate(self.current_coordinates[0], value), self.current_coordinates[1]
+ elif direction == 'south':
+ self.current_coordinates = move_coordinate(self.current_coordinates[0], -value), self.current_coordinates[1]
+ elif direction == 'east':
+ self.current_coordinates = self.current_coordinates[0], move_coordinate(self.current_coordinates[1], value)
+ elif direction == 'west':
+ self.current_coordinates = self.current_coordinates[0], move_coordinate(self.current_coordinates[1], -value)
+
def add_tips(game):
radius = 0.0025
if len(buildings) > 0:
game.tips.append(
- 'Вы рядом с ' + convert_building_type(buildings[0]['building_type']) + ' высотой в ' + buildings[0]['levels'] + ' этажей')
+ 'Вы рядом с ' + convert_building_type(buildings[0]['building_type']) + ' высотой в ' + buildings[0][
+ 'levels'] + ' этажей')
shuffle(game.tips)
return {'tips': game.shown_tips}
+@post('/api/games/<game_id>/move')
+def get_game(game_id):
+ game = games[game_id]
+
+ direction = request.json['direction']
+
+ game.move(direction)
+
+ game.tips = []
+
+ add_tips(game)
+
+ game.shown_tips.append('Вы переместились на 100 м на ' + direction)
+
+ show_tips(game, 1)
+
+ return {'tips': game.shown_tips}
+
+
@post('/api/games/<game_id>/finish')
def finish_game(game_id):
game = games[game_id]
c = 2 * atan2(sqrt(a), sqrt(1 - a))
return R * c
+
+
+def move_coordinate(cordinate, meters):
+ meters_in_gradus = 111_111
+ return cordinate + meters / meters_in_gradus