-
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
Aggregate network objects #607
Changes from 2 commits
af8b6c9
da6a9ec
e3709c1
0362d40
fdabdcb
5bee2a9
2ffd1d0
7515587
ead7c62
abafc78
ff17cf1
08c392c
e406b34
711485b
300b73c
032ed58
358b92b
93fec24
7851ba7
4dc986e
818c009
cf63cd0
4653d1b
7e87031
5c6cd3b
655a067
28e21f6
0d26c19
49f2378
a9f6129
deea38e
4a12e7a
1632cd8
48e05f0
cf1664e
a41060f
9a97e6d
e9116bb
3f723b4
9a1689e
4bab4ed
9204ede
c1f4cfe
1d4c2bd
a0b7212
79d179e
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 |
---|---|---|
|
@@ -90,6 +90,10 @@ The API exposes four routes: | |
|
||
At present, the following query types are accessible through FlowAPI: | ||
|
||
- `aggregate_network_objects` | ||
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. 👍 |
||
|
||
Statistics about unique cells/sites aggregated to a period. | ||
|
||
- `daily_location` | ||
|
||
A statistic representing where subscribers are on a given day, aggregated to a spatial unit. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1022,3 +1022,31 @@ def total_network_objects( | |
"end_date": end_date, | ||
"aggregation_unit": aggregation_unit, | ||
} | ||
|
||
|
||
def aggregate_network_objects( | ||
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. I've been giving the params for this some thought - I actually think what would be most useful is to have it take: network_objects, statistic, by. That can be achieved without touching the underlying Flowmachine class, by constructing a tno object, and then calling aggregate on it with the by and statistic arguments. 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. You'll have to expand on that a bit, in terms of roughly how the call would look. I gather tno is TotalNetworkObject, and "by" is possibly the date range?! But also, I thought you were trying to do away with calls to aggregate() (#599) 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. As you were, I understand now what you are driving at! (in view of the review comment further down) 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. Arguments need to be |
||
start_date: str, end_date: str, aggregation_unit: str | ||
) -> dict: | ||
""" | ||
Return query spec for aggregate network objects | ||
|
||
Parameters | ||
---------- | ||
start_date : str | ||
ISO format date of the first day of the count, e.g. "2016-01-01" | ||
end_date : str | ||
ISO format date of the day _after_ the final date of the count, e.g. "2016-01-08" | ||
aggregation_unit : str | ||
Unit of aggregation, e.g. "admin3" | ||
|
||
Returns | ||
------- | ||
dict | ||
Dict which functions as the query specification | ||
""" | ||
return { | ||
"query_kind": "aggregate_network_objects", | ||
"start_date": start_date, | ||
"end_date": end_date, | ||
"aggregation_unit": aggregation_unit, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 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 AggregateNetworkObjects | ||
from .base_exposed_query import BaseExposedQuery | ||
from .custom_fields import AggregationUnit | ||
|
||
__all__ = ["AggregateNetworkObjectsSchema", "AggregateNetworkObjectsExposed"] | ||
|
||
|
||
class AggregateNetworkObjectsSchema(Schema): | ||
|
||
start_date = fields.Date(required=True) | ||
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. Needs to have the right fields, one of which is a bit tricky because it should refer to another schema. See FlowsSchema, or ModalLocationSchema for an example of how to do that. |
||
end_date = fields.Date(required=True) | ||
aggregation_unit = AggregationUnit() | ||
|
||
@post_load | ||
def make_query_object(self, params): | ||
return AggregateNetworkObjectsExposed(**params) | ||
|
||
|
||
class AggregateNetworkObjectsExposed(BaseExposedQuery): | ||
def __init__(self, *, start_date, end_date, aggregation_unit): | ||
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. This needs to match the |
||
# 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 | ||
|
||
@property | ||
def _flowmachine_query_obj(self): | ||
""" | ||
Return the underlying flowmachine aggregate_network_objects object. | ||
|
||
Returns | ||
------- | ||
Query | ||
""" | ||
return AggregateNetworkObjects( | ||
maxalbert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
start=self.start_date, stop=self.end_date, level=self.aggregation_unit | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,7 +203,7 @@ def aggregate(self, by=None, statistic="avg"): | |
) | ||
|
||
|
||
class AggregateNetworkObjects(GeoDataMixin, Query): | ||
class AggregateNetworkObjects(TotalNetworkObjects, Query): | ||
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. What's going on here? 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. This relates to your comment in #601 "Refactor AggregateNetworkObjects to take TotalNetworkObjects as main argument" 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. Ah. I think I've failed to communicate what I meant there - the suggestion was that rather than taking all the arguments necessary to create a This change actually alters the class hierarchy of the class (https://www.digitalocean.com/community/tutorials/understanding-class-inheritance-in-python-3 is a decent overview of class inheritance in python), and I imagine will cause a few issues because 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. OK I'll amend the code accordingly. (I do understand python class hierarchies, but I'll have a quick skim of that page) |
||
""" | ||
Class for calculating statistics about unique cells/sites | ||
and aggregate it by period. | ||
|
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.
Can we have a changed entry here as well to reflect that the names of the arguments to
TotalNetworkObjects
andAggregateNetworkObjects
have been altered?