]> git.xn--bdkaa.com Git - where-are-you.py.git/commitdiff
Add score. Fix moving
authorzharkovstas <zharkovstas@skbkontur.ru>
Sun, 19 May 2019 00:07:06 +0000 (05:07 +0500)
committerzharkovstas <zharkovstas@skbkontur.ru>
Sun, 19 May 2019 00:08:10 +0000 (05:08 +0500)
app.py
stemmer.py

diff --git a/app.py b/app.py
index ab336bb4db41212c86194be46bdafd89d23e77a8..1eb1eee572fa73d196fbe26ea898e795cd751f39 100644 (file)
--- a/app.py
+++ b/app.py
@@ -38,6 +38,7 @@ class Game:
         self.tips = []
         self.shown_tips = []
         self.route = [current_coordinates]
+        self.score = 0
 
     def move(self, direction, value=move_distance):
         if direction == 'north':
@@ -140,6 +141,7 @@ def convert_sightseeing_type(type):
         return None
     return None
 
+
 districts_tips = {
     'кировский': ' назван в честь Сергея Мироновича, фамилия которого послужила названием еще и для города',
     'ленинский': ' назвали в честь Ильича. Все знают Ильича ☭',
@@ -148,6 +150,7 @@ districts_tips = {
     'железнодорожный': ' наверняка расположил внутри себя вокзал, ну или паровозное депо'
 }
 
+
 def create_district_tip(district_name):
     for district_key, district_tip in districts_tips.items():
         if district_key in district_name.lower():
@@ -194,6 +197,12 @@ def enable_cors(fn):
     return _enable_cors
 
 
+def count_score(game):
+    dist = distance(game.current_coordinates, game.answer_coordinates)
+
+    return 100_000_000 / (1 + dist)
+
+
 @get('/api/games')
 @enable_cors
 def get_games():
@@ -202,6 +211,7 @@ def get_games():
                   games.values()]
     }
 
+
 def handle_post_game(city_id):
     game_id = str(uuid.uuid4())
     if city_id not in cities:
@@ -226,11 +236,13 @@ def handle_post_game(city_id):
         "max_lon": max_lon
     }
 
+
 @post('/api/games')
 @enable_cors
 def post_game_without_city():
     return handle_post_game('Екатеринбург')
 
+
 @post('/api/games/<city>')
 @enable_cors
 def post_game(city):
@@ -278,6 +290,11 @@ def move(game_id, direction):
 
     game = games[game_id]
 
+    if not direction:
+        return bottle.HTTPResponse(status=400, body='direction is required')
+
+    game.move(direction)
+
     game.tips = []
 
     add_tips(game)
@@ -307,12 +324,14 @@ def finish_game(game_id):
         game.is_finished = True
         game.answer_coordinates = answer_coordinates
         game.distance = d
+        game.score = count_score(game)
 
     return {
         "right_coordinates": game.current_coordinates,
         "distance": d,
         "address": get_text_by_coordinates(game.current_coordinates),
-        "route": game.route
+        "route": game.route,
+        "score": game.score
     }
 
 
index 35fa757190234f35f8578d51426d7d8c9f0fd20b..b7e5b7994a04a12a7b10e66c9e0523a928f5c424 100644 (file)
@@ -15,9 +15,9 @@ def normalize(line):
     return result.strip()
 
 
-def stemming(word):
-    return stemmer.stemWord(word)
-
-def text_stemming(text):
+def stemming(text):
     normilized_text = normalize(text)
     return ' '.join(stemmer.stemWords(normilized_text.split()))
+
+if __name__ == "__main__":
+    print(stemming('Спланой мост'))