Skip to content

Commit

Permalink
Add unmoving counts to api
Browse files Browse the repository at this point in the history
  • Loading branch information
greenape committed Apr 8, 2020
1 parent 422b892 commit a6af212
Show file tree
Hide file tree
Showing 6 changed files with 4,019 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from .total_network_objects import TotalNetworkObjectsSchema
from .dfs_metric_total_amount import DFSTotalMetricAmountSchema
from .unique_visitor_counts import UniqueVisitorCountsSchema
from .unmoving_counts import UnmovingCountsSchema


class FlowmachineQuerySchema(OneOfSchema):
Expand All @@ -57,6 +58,7 @@ class FlowmachineQuerySchema(OneOfSchema):
"active_at_reference_location_counts": ActiveAtReferenceLocationCountsSchema,
"unique_visitor_counts": UniqueVisitorCountsSchema,
"consecutive_trips": ConsecutiveTripsSchema,
"unmoving_counts": UnmovingCountsSchema,
}


Expand Down
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)
)
)
Loading

0 comments on commit a6af212

Please sign in to comment.