-
Notifications
You must be signed in to change notification settings - Fork 20
/
total_network_objects.py
55 lines (45 loc) · 1.89 KB
/
total_network_objects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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
from marshmallow.validate import OneOf
from flowmachine.features import TotalNetworkObjects
from .base_exposed_query import BaseExposedQuery
from .base_schema import BaseSchema
from .custom_fields import EventTypes, TotalBy, ISODateTime
from .aggregation_unit import AggregationUnitMixin
__all__ = ["TotalNetworkObjectsSchema", "TotalNetworkObjectsExposed"]
class TotalNetworkObjectsExposed(BaseExposedQuery):
def __init__(
self, *, start_date, end_date, aggregation_unit, total_by, event_types
):
# 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
self.total_by = total_by
self.event_types = event_types
@property
def _flowmachine_query_obj(self):
"""
Return the underlying flowmachine daily_location object.
Returns
-------
Query
"""
return TotalNetworkObjects(
start=self.start_date,
stop=self.end_date,
spatial_unit=self.aggregation_unit,
total_by=self.total_by,
table=self.event_types,
)
class TotalNetworkObjectsSchema(AggregationUnitMixin, BaseSchema):
# query_kind parameter is required here for claims validation
query_kind = fields.String(validate=OneOf(["total_network_objects"]))
start_date = ISODateTime(required=True)
end_date = ISODateTime(required=True)
total_by = TotalBy(required=False, missing="day")
event_types = EventTypes()
__model__ = TotalNetworkObjectsExposed