-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tags in stats #4232
Merged
Merged
Add tags in stats #4232
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# coding=utf-8 | ||
# Copyright (c) 2001-2022, Hove and/or its affiliates. All rights reserved. | ||
# | ||
# This file is part of Navitia, | ||
# the software to build cool stuff with public transport. | ||
# | ||
# Hope you'll enjoy and contribute to this project, | ||
# powered by Hove (www.hove.com). | ||
# Help us simplify mobility and open public transport: | ||
# a non ending quest to the responsive locomotion way of traveling! | ||
# | ||
# LICENCE: This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# Stay tuned using | ||
# twitter @navitia | ||
# channel `#navitia` on riot https://riot.im/app/#/room/#navitia:matrix.org | ||
# https://groups.google.com/d/forum/navitia | ||
# www.navitia.io | ||
|
||
from __future__ import absolute_import, unicode_literals | ||
|
||
from jormungandr.stat_manager import StatManager | ||
from navitiacommon import stat_pb2 | ||
from jormungandr import app | ||
import unittest | ||
|
||
|
||
class TestStatManager(unittest.TestCase): | ||
def setUp(self): | ||
self.old_save_stat = app.config['SAVE_STAT'] | ||
app.config['SAVE_STAT'] = False | ||
|
||
def tearDown(self): | ||
app.config['SAVE_STAT'] = self.old_save_stat | ||
|
||
def test_fill_tags_empty_resp_journey(self): | ||
resp_journey = {} | ||
stat_manager = StatManager(auto_delete=True) | ||
stat_request = stat_pb2.StatRequest() | ||
stat_journey = stat_request.journeys.add() | ||
stat_manager.fill_tags(stat_journey, resp_journey) | ||
assert not stat_journey.tags | ||
|
||
def test_fill_tags_empty_tags(self): | ||
resp_journey = {"tags": []} | ||
stat_manager = StatManager(auto_delete=True) | ||
stat_request = stat_pb2.StatRequest() | ||
stat_journey = stat_request.journeys.add() | ||
stat_manager.fill_tags(stat_journey, resp_journey) | ||
assert not stat_journey.tags | ||
|
||
def test_fill_tags_one_tag(self): | ||
resp_journey = {"tags": ["olympics"]} | ||
stat_manager = StatManager(auto_delete=True) | ||
stat_request = stat_pb2.StatRequest() | ||
stat_journey = stat_request.journeys.add() | ||
stat_manager.fill_tags(stat_journey, resp_journey) | ||
assert len(stat_journey.tags) == 1 | ||
assert stat_journey.tags[0] == stat_pb2.JOURNEY_TAG_OLYMPICS | ||
|
||
def test_fill_tags_many_tags(self): | ||
resp_journey = {"tags": ["olympics", "best_olympics", "ecologic"]} | ||
stat_manager = StatManager(auto_delete=True) | ||
stat_request = stat_pb2.StatRequest() | ||
stat_journey = stat_request.journeys.add() | ||
stat_manager.fill_tags(stat_journey, resp_journey) | ||
assert len(stat_journey.tags) == 3 | ||
|
||
def test_fill_tags_unknown_tag(self): | ||
resp_journey = {"tags": ["toto"]} | ||
stat_manager = StatManager(auto_delete=True) | ||
stat_request = stat_pb2.StatRequest() | ||
stat_journey = stat_request.journeys.add() | ||
stat_manager.fill_tags(stat_journey, resp_journey) | ||
assert len(stat_journey.tags) == 1 | ||
assert stat_journey.tags[0] == stat_pb2.JOURNEY_TAG_UNKNOWN | ||
|
||
def test_fill_tags_many_unknown_tag(self): | ||
resp_journey = {"tags": ["toto", "tata", "titi"]} | ||
stat_manager = StatManager(auto_delete=True) | ||
stat_request = stat_pb2.StatRequest() | ||
stat_journey = stat_request.journeys.add() | ||
stat_manager.fill_tags(stat_journey, resp_journey) | ||
assert len(stat_journey.tags) == 1 | ||
assert stat_journey.tags[0] == stat_pb2.JOURNEY_TAG_UNKNOWN |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure it is worthwhile to add the tag
JOURNEY_TAG_UNKNOWN
to the stats proto message 🤷There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of empty value, better to use this one.
We better not communicate this information to any client and use only for internal analysis.