-
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
Exposing PerSubscriberAggregate #4590
base: master
Are you sure you want to change the base?
Changes from all commits
6ee584d
a568b85
e2fa1cd
916789d
e5dcba3
858f53d
ef90f5f
333b460
0ae659e
36d4811
b12e04c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
from .geography import GeographySchema | ||
from .location_event_counts import LocationEventCountsSchema | ||
from .most_frequent_location import MostFrequentLocationSchema | ||
from .per_subscriber_aggregate import PerSubscriberAggregateSchema | ||
from .trips_od_matrix import TripsODMatrixSchema | ||
from .unique_subscriber_counts import UniqueSubscriberCountsSchema | ||
from .location_introversion import LocationIntroversionSchema | ||
|
@@ -66,6 +67,7 @@ class FlowmachineQuerySchema(OneOfSchema): | |
"unmoving_counts": UnmovingCountsSchema, | ||
"unmoving_at_reference_location_counts": UnmovingAtReferenceLocationCountsSchema, | ||
"trips_od_matrix": TripsODMatrixSchema, | ||
"per_subscriber_aggregate": PerSubscriberAggregateSchema, | ||
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. Any query schema included in |
||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from marshmallow_oneofschema import OneOfSchema | ||
|
||
from flowmachine.core.server.query_schemas.displacement import DisplacementSchema | ||
from flowmachine.core.server.query_schemas.event_count import EventCountSchema | ||
from flowmachine.core.server.query_schemas.nocturnal_events import NocturnalEventsSchema | ||
from flowmachine.core.server.query_schemas.pareto_interactions import ( | ||
ParetoInteractionsSchema, | ||
) | ||
from flowmachine.core.server.query_schemas.radius_of_gyration import ( | ||
RadiusOfGyrationSchema, | ||
) | ||
from flowmachine.core.server.query_schemas.subscriber_degree import ( | ||
SubscriberDegreeSchema, | ||
) | ||
from flowmachine.core.server.query_schemas.topup_amount import TopUpAmountSchema | ||
from flowmachine.core.server.query_schemas.topup_balance import TopUpBalanceSchema | ||
from flowmachine.core.server.query_schemas.total_active_periods import ( | ||
TotalActivePeriodsSchema, | ||
) | ||
from flowmachine.core.server.query_schemas.unique_location_counts import ( | ||
UniqueLocationCountsSchema, | ||
) | ||
|
||
|
||
class NumericSubscriberMetricsSchema(OneOfSchema): | ||
type_field = "query_kind" | ||
type_schemas = { | ||
"radius_of_gyration": RadiusOfGyrationSchema, | ||
"unique_location_counts": UniqueLocationCountsSchema, | ||
"topup_balance": TopUpBalanceSchema, | ||
"subscriber_degree": SubscriberDegreeSchema, | ||
"topup_amount": TopUpAmountSchema, | ||
"event_count": EventCountSchema, | ||
"pareto_interactions": ParetoInteractionsSchema, | ||
"nocturnal_events": NocturnalEventsSchema, | ||
"displacement": DisplacementSchema, | ||
"total_active_periods": TotalActivePeriodsSchema, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# 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 functools import reduce | ||
|
||
from marshmallow import fields | ||
from marshmallow.validate import OneOf, Length | ||
|
||
from flowmachine.core.server.query_schemas import BaseExposedQuery | ||
from flowmachine.core.server.query_schemas.numeric_subscriber_metrics import ( | ||
NumericSubscriberMetricsSchema, | ||
) | ||
from flowmachine.core.server.query_schemas.base_schema import BaseSchema | ||
from flowmachine.features.subscriber.per_subscriber_aggregate import ( | ||
PerSubscriberAggregate, | ||
agg_methods, | ||
) | ||
|
||
|
||
class PerSubscriberAggregateExposed(BaseExposedQuery): | ||
def __init__(self, subscriber_queries, agg_method): | ||
self.subscriber_queries = subscriber_queries | ||
self.agg_method = agg_method | ||
|
||
@property | ||
def _flowmachine_query_obj(self): | ||
subscriber_query = reduce( | ||
# TODO: Replace with Jono's new list input to union | ||
lambda x, y: x._flowmachine_query_obj.union(y._flowmachine_query_obj), | ||
self.subscriber_queries, | ||
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. Actually, this won't work - sorry. You want 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. It's going to be moot soon - Jono's working on #4593 , we may as well wait for that and incorporate it into this PR. |
||
) | ||
return PerSubscriberAggregate( | ||
subscriber_query=subscriber_query, | ||
agg_column="value", | ||
agg_method=self.agg_method, | ||
) | ||
|
||
|
||
class PerSubscriberAggregateSchema(BaseSchema): | ||
query_kind = fields.String(validate=OneOf(["per_subscriber_aggregate"])) | ||
subscriber_queries = fields.List( | ||
fields.Nested(NumericSubscriberMetricsSchema), validate=Length(min=1) | ||
) | ||
agg_method = fields.String(validate=OneOf(agg_methods)) | ||
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. We've got a custom field for this ( |
||
|
||
__model__ = PerSubscriberAggregateExposed |
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.
Re-adding my comment here following the file move, for visibility: