]> git.xn--bdkaa.com Git - where-are-you.py.git/commitdiff
Moving API
authorzharkovstas <zharkovstas@skbkontur.ru>
Sat, 18 May 2019 19:21:12 +0000 (00:21 +0500)
committerzharkovstas <zharkovstas@skbkontur.ru>
Sat, 18 May 2019 19:21:24 +0000 (00:21 +0500)
app.py
geo.py

diff --git a/app.py b/app.py
index 7e2d4184679ce238dd8c5558141d0186327dd752..4df0094aaa87a1bf54d0b217c8e31fb360887e0e 100644 (file)
--- a/app.py
+++ b/app.py
@@ -2,7 +2,7 @@ from random import shuffle, random
 
 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
@@ -20,6 +20,16 @@ class Game:
         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
@@ -42,7 +52,8 @@ def add_tips(game):
 
     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)
 
@@ -130,6 +141,25 @@ def get_game(game_id):
     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]
diff --git a/geo.py b/geo.py
index 2e13c6b36a91da8383f65b7c874fb5fca99b8294..92af2abef66832e5ab03d715c4b5410d34491b38 100644 (file)
--- a/geo.py
+++ b/geo.py
@@ -16,3 +16,8 @@ def distance(point1, point2):
     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