From 549a80b755a9cd5852155ca31be0d9d6ce77305a Mon Sep 17 00:00:00 2001 From: zharkovstas Date: Sun, 19 May 2019 05:07:06 +0500 Subject: [PATCH] Add score. Fix moving --- app.py | 21 ++++++++++++++++++++- stemmer.py | 8 ++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index ab336bb..1eb1eee 100644 --- 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/') @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 } diff --git a/stemmer.py b/stemmer.py index 35fa757..b7e5b79 100644 --- a/stemmer.py +++ b/stemmer.py @@ -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('Спланой мост')) -- 2.50.1