-
Notifications
You must be signed in to change notification settings - Fork 21
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
Flowmachine unique location count #979
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
afc178d
Merge branch 'master' into flowmachine-unique-location-count
BhavinPanch 3eff57d
Auto stash before merge of "flowmachine-unique-location-count" and "m…
BhavinPanch 20fce48
change for unique_location_counts test
BhavinPanch 85c1347
Fix error caused by aggregation unit being present in query_json for …
dc7c5d6
Integration test changes for flowapi
BhavinPanch 8da3bab
Acceptance test for flowmachine server
BhavinPanch db6cb03
Changes for test api specs
BhavinPanch 67bf6f8
Changes in test_queries.py
BhavinPanch 336c750
Updated acceptance tests
BhavinPanch 03c47ea
Merge branch 'master' into flowmachine-unique-location-count
BhavinPanch 7c9c8c9
Changed column name and test
BhavinPanch 410809e
Added details in changelog
BhavinPanch a479561
Merge branch 'master' into flowmachine-unique-location-count
BhavinPanch f6a4157
Reformating using pre-commit hook
BhavinPanch dc95276
Reformatting
BhavinPanch 67be84f
Requested changes for client and unique location count file
BhavinPanch cc54a8b
Merge branch 'master' into flowmachine-unique-location-count
BhavinPanch 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
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
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
52 changes: 52 additions & 0 deletions
52
flowmachine/flowmachine/core/server/query_schemas/unique_location_counts.py
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,52 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
from marshmallow import Schema, fields, post_load | ||
from marshmallow.validate import OneOf, Length | ||
|
||
from flowmachine.features import UniqueLocationCounts | ||
from .base_exposed_query import BaseExposedQuery | ||
from .custom_fields import SubscriberSubset, AggregationUnit | ||
|
||
__all__ = ["UniqueLocationCountsSchema", "UniqueLocationCountsExposed"] | ||
|
||
|
||
class UniqueLocationCountsSchema(Schema): | ||
query_kind = fields.String(validate=OneOf(["unique_location_counts"])) | ||
start_date = fields.Date(required=True) | ||
end_date = fields.Date(required=True) | ||
aggregation_unit = AggregationUnit() | ||
subscriber_subset = SubscriberSubset() | ||
|
||
@post_load | ||
def make_query_object(self, params): | ||
return UniqueLocationCountsExposed(**params) | ||
|
||
|
||
class UniqueLocationCountsExposed(BaseExposedQuery): | ||
def __init__( | ||
self, *, start_date, end_date, aggregation_unit, subscriber_subset=None | ||
): | ||
# Note: all input parameters need to be defined as attributes on `self` | ||
# so that marshmallow can serialise the object correctly. | ||
self.start_date = start_date | ||
self.end_date = end_date | ||
self.aggregation_unit = aggregation_unit | ||
self.subscriber_subset = subscriber_subset | ||
|
||
@property | ||
def _flowmachine_query_obj(self): | ||
""" | ||
Return the underlying flowmachine unique_location_counts object. | ||
|
||
Returns | ||
------- | ||
Query | ||
""" | ||
return UniqueLocationCounts( | ||
start=self.start_date, | ||
stop=self.end_date, | ||
level=self.aggregation_unit, | ||
subscriber_subset=self.subscriber_subset, | ||
) |
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 |
---|---|---|
|
@@ -122,7 +122,7 @@ def __init__( | |
|
||
@property | ||
def column_names(self) -> List[str]: | ||
return ["subscriber", "unique_location_counts"] | ||
return ["subscriber", "value"] | ||
|
||
def _make_query(self): | ||
""" | ||
|
@@ -134,13 +134,13 @@ def _make_query(self): | |
get_columns_for_level(self.ul.level, self.ul.column_name) | ||
) | ||
sql = """ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we change this to an f-string while we're here? |
||
SELECT | ||
subscriber, | ||
COUNT(*) as unique_location_counts | ||
SELECT | ||
subscriber, | ||
COUNT(*) as value | ||
FROM | ||
(SELECT DISTINCT subscriber, {rc} | ||
(SELECT DISTINCT subscriber, {rc} | ||
FROM ({all_locs}) AS all_locs) AS _ | ||
GROUP BY subscriber | ||
GROUP BY subscriber | ||
""".format( | ||
all_locs=self.ul.get_query(), rc=relevant_columns | ||
) | ||
|
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
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
Oops, something went wrong.
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.
These need to be type annotated.