-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unmoving at reference location counts to api, and remove some sam…
…pling from top level queries
- Loading branch information
Showing
10 changed files
with
240 additions
and
79 deletions.
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
16 changes: 16 additions & 0 deletions
16
flowmachine/flowmachine/core/server/query_schemas/reference_location.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,16 @@ | ||
# 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_oneofschema import OneOfSchema | ||
|
||
from flowmachine.core.server.query_schemas.daily_location import DailyLocationSchema | ||
from flowmachine.core.server.query_schemas.modal_location import ModalLocationSchema | ||
|
||
|
||
class ReferenceLocationSchema(OneOfSchema): | ||
type_field = "query_kind" | ||
type_schemas = { | ||
"daily_location": DailyLocationSchema, | ||
"modal_location": ModalLocationSchema, | ||
} |
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
64 changes: 64 additions & 0 deletions
64
flowmachine/flowmachine/core/server/query_schemas/unmoving_at_reference_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,64 @@ | ||
# 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 fields, post_load, Schema | ||
from marshmallow.validate import OneOf | ||
|
||
from flowmachine.features.location.redacted_unmoving_at_reference_location_counts import ( | ||
RedactedUnmovingAtReferenceLocationCounts, | ||
) | ||
from flowmachine.features.location.unmoving_at_reference_location_counts import ( | ||
UnmovingAtReferenceLocationCounts, | ||
) | ||
from flowmachine.features.subscriber.unmoving_at_reference_location import ( | ||
UnmovingAtReferenceLocation, | ||
) | ||
from . import BaseExposedQuery | ||
from .reference_location import ReferenceLocationSchema | ||
from .base_query_with_sampling import BaseQueryWithSamplingSchema | ||
from .unique_locations import UniqueLocationsSchema | ||
|
||
__all__ = [ | ||
"UnmovingAtReferenceLocationCountsSchema", | ||
"UnmovingAtReferenceLocationCountsExposed", | ||
] | ||
|
||
|
||
class UnmovingAtReferenceLocationCountsSchema(Schema): | ||
# query_kind parameter is required here for claims validation | ||
query_kind = fields.String( | ||
validate=OneOf(["unmoving_at_reference_location_counts"]) | ||
) | ||
locations = fields.Nested(UniqueLocationsSchema) | ||
reference_locations = fields.Nested(ReferenceLocationSchema) | ||
|
||
@post_load | ||
def make_query_object(self, params, **kwargs): | ||
return UnmovingAtReferenceLocationCountsExposed(**params) | ||
|
||
|
||
class UnmovingAtReferenceLocationCountsExposed(BaseExposedQuery): | ||
def __init__(self, locations, reference_locations): | ||
# Note: all input parameters need to be defined as attributes on `self` | ||
# so that marshmallow can serialise the object correctly. | ||
self.locations = locations | ||
self.reference_locations = reference_locations | ||
|
||
@property | ||
def _flowmachine_query_obj(self): | ||
""" | ||
Return the underlying flowmachine object. | ||
Returns | ||
------- | ||
Query | ||
""" | ||
return RedactedUnmovingAtReferenceLocationCounts( | ||
unmoving_at_reference_location_counts=UnmovingAtReferenceLocationCounts( | ||
UnmovingAtReferenceLocation( | ||
locations=self.locations._flowmachine_query_obj, | ||
reference_locations=self.reference_locations._flowmachine_query_obj, | ||
) | ||
) | ||
) |
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.