-
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.
- Loading branch information
Showing
6 changed files
with
4,019 additions
and
1 deletion.
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
49 changes: 49 additions & 0 deletions
49
flowmachine/flowmachine/core/server/query_schemas/unmoving_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,49 @@ | ||
# 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 | ||
from marshmallow.validate import OneOf | ||
|
||
from flowmachine.features.location.redacted_unmoving_counts import ( | ||
RedactedUnmovingCounts, | ||
) | ||
from flowmachine.features.location.unmoving_counts import UnmovingCounts | ||
from flowmachine.features.subscriber.unmoving import Unmoving | ||
from . import BaseExposedQuery | ||
from .base_query_with_sampling import BaseQueryWithSamplingSchema | ||
from .unique_locations import UniqueLocationsSchema | ||
|
||
__all__ = ["UnmovingCountsSchema", "UnmovingCountsExposed"] | ||
|
||
|
||
class UnmovingCountsSchema(BaseQueryWithSamplingSchema): | ||
# query_kind parameter is required here for claims validation | ||
query_kind = fields.String(validate=OneOf(["unmoving_counts"])) | ||
locations = fields.Nested(UniqueLocationsSchema) | ||
|
||
@post_load | ||
def make_query_object(self, params, **kwargs): | ||
return UnmovingCountsExposed(**params) | ||
|
||
|
||
class UnmovingCountsExposed(BaseExposedQuery): | ||
def __init__(self, locations): | ||
# Note: all input parameters need to be defined as attributes on `self` | ||
# so that marshmallow can serialise the object correctly. | ||
self.locations = locations | ||
|
||
@property | ||
def _flowmachine_query_obj(self): | ||
""" | ||
Return the underlying flowmachine object. | ||
Returns | ||
------- | ||
Query | ||
""" | ||
return RedactedUnmovingCounts( | ||
unmoving_counts=UnmovingCounts( | ||
Unmoving(self.locations._flowmachine_query_obj) | ||
) | ||
) |
Oops, something went wrong.