]> git.xn--bdkaa.com Git - where-are-you.py.git/commitdiff
Fixes
authorzharkovstas <zharkovstas@skbkontur.ru>
Sat, 18 May 2019 18:11:04 +0000 (23:11 +0500)
committerzharkovstas <zharkovstas@skbkontur.ru>
Sat, 18 May 2019 18:11:04 +0000 (23:11 +0500)
app.py
street_predictor.py

diff --git a/app.py b/app.py
index 30de07cd57fa0c9fbcac5a3624bd8fa07424ed0b..1052a81b2107486c8cd704621296e894c4fa74e0 100644 (file)
--- a/app.py
+++ b/app.py
@@ -9,6 +9,7 @@ from osm.osm import describe_objects
 
 min_lat, max_lat, min_lon, max_lon = 56.807556, 56.847826, 60.570744, 60.657791
 
+
 class Game:
     def __init__(self, game_id, current_coordinates):
         self.id = game_id
@@ -24,14 +25,15 @@ def add_tips(game):
     radius = 0.0025
     coordinate = game.current_coordinates
     near_objects = describe_objects(coordinate[0] - radius, coordinate[1] - radius, coordinate[0] + radius,
-                               coordinate[1] + radius)
+                                    coordinate[1] + radius)
 
     for o in near_objects['amenities']:
         game.tips.append(f'Рядом с вами находится {o["name"]}')
 
     for s in near_objects['streets']:
 
-        success, summary = parse_summary(s['name'].replace('улица', '').replace('проспект', '').replace('переулок', '').strip())
+        success, summary = parse_summary(
+            s['name'].replace('улица', '').replace('проспект', '').replace('переулок', '').strip())
 
         if success:
             game.tips.append(f'Недалеко есть улица, имя которой дал(а) {summary}')
@@ -46,13 +48,18 @@ def show_tips(game, count):
         game.shown_tips.append(not_shown_tips[i])
 
 
-lat = min_lat + (max_lat - min_lat) * random()
-lon = min_lon + (max_lon - min_lon) * random()
+def create_test_game():
+    lat = min_lat + (max_lat - min_lat) * random()
+    lon = min_lon + (max_lon - min_lon) * random()
+
+    test_game = Game('test', (lat, lon))
+    add_tips(test_game)
+    show_tips(test_game, 20)
+
+    return test_game
 
-test_game = Game('test', (lat, lon))
-add_tips(test_game)
-show_tips(test_game, 20)
-games = {'test': test_game}
+
+games = {'test': create_test_game()}
 
 
 @get('/api/games')
@@ -67,7 +74,10 @@ def get_games():
 def post_game():
     game_id = str(uuid.uuid4())
 
-    game = Game(game_id, (56.832469, 60.605989))
+    lat = min_lat + (max_lat - min_lat) * random()
+    lon = min_lon + (max_lon - min_lon) * random()
+
+    game = Game(game_id, (lat, lon))
     games[game_id] = game
 
     return {
index bfea4b2d31752fd6d523da90fa407e027591ebf5..6322341492e70c6b79134e9c12a4c4c01789ee08 100644 (file)
@@ -5,7 +5,7 @@ w.set_lang('ru')
 
 
 def parse_summary(query='str'):
-    print('query: ' + query)
+    #print('query: ' + query)
     try:
         summary = w.summary(query)
         full_description = re.split(r'\) —', summary)[1]