/
voyages_timeseries.py
284 lines (218 loc) · 16.9 KB
/
voyages_timeseries.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
"""
Try me out in your browser:
[![Binder](https://img.shields.io/badge/try%20me%20out-launch%20notebook-579ACA.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABZCAMAAABi1XidAAAB8lBMVEX///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJXmsrmZYH1olL1olJXmsr1olJXmsrmZYH1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olJXmsrmZYH1olL1olL0nFf1olJXmsrmZYH1olJXmsq8dZb1olJXmsrmZYH1olJXmspXmspXmsr1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olLeaIVXmsrmZYH1olL1olL1olJXmsrmZYH1olLna31Xmsr1olJXmsr1olJXmsrmZYH1olLqoVr1olJXmsr1olJXmsrmZY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7VgjZjyVPrjw1te5otM7RmP7xm+sK2Gv9I8Gi++BRbEkR9EBw8zRUcKxwp73xkaLiqQb+kGduJTNHG72zcW9LoJgqQxpP3/Tj//c3yB0tqzaml05/+orHLksVO+95kX7/7qgJvnjlrfr2Ggsyx0eoy9uPzN5SPd86aXggOsEKW2Prz7du3VID3/tzs/sSRs2w7ovVHKtjrX2pd7ZMlTxAYfBAL9jiDwfLkq55Tm7ifhMlTGPyCAs7RFRhn47JnlcB9RM5T97ASuZXIcVNuUDIndpDbdsfrqsOppeXl5Y+XVKdjFCTh+zGaVuj0d9zy05PPK3QzBamxdwtTCrzyg/2Rvf2EstUjordGwa/kx9mSJLr8mLLtCW8HHGJc2R5hS219IiF6PnTusOqcMl57gm0Z8kanKMAQg0qSyuZfn7zItsbGyO9QlnxY0eCuD1XL2ys/MsrQhltE7Ug0uFOzufJFE2PxBo/YAx8XPPdDwWN0MrDRYIZF0mSMKCNHgaIVFoBbNoLJ7tEQDKxGF0kcLQimojCZopv0OkNOyWCCg9XMVAi7ARJzQdM2QUh0gmBozjc3Skg6dSBRqDGYSUOu66Zg+I2fNZs/M3/f/Grl/XnyF1Gw3VKCez0PN5IUfFLqvgUN4C0qNqYs5YhPL+aVZYDE4IpUk57oSFnJm4FyCqqOE0jhY2SMyLFoo56zyo6becOS5UVDdj7Vih0zp+tcMhwRpBeLyqtIjlJKAIZSbI8SGSF3k0pA3mR5tHuwPFoa7N7reoq2bqCsAk1HqCu5uvI1n6JuRXI+S1Mco54YmYTwcn6Aeic+kssXi8XpXC4V3t7/ADuTNKaQJdScAAAAAElFTkSuQmCC)](https://mybinder.org/v2/gh/VorTECHsa/python-sdk/master?filepath=docs%2Fexamples%2Ftry_me_out%2Fvoyages_timeseries.ipynb)
"""
from datetime import datetime
from typing import List, Union
from vortexasdk.api import ID
from vortexasdk.api.shared_types import Tag, to_ISODate
from vortexasdk.endpoints.breakdown_result import BreakdownResult
from vortexasdk.endpoints.endpoints import VOYAGES_TIMESERIES
from vortexasdk.operations import Search
from vortexasdk.utils import convert_to_list
class VoyagesTimeseries(Search):
"""
Please note: you will require a subscription to our Freight module to access this endpoint.
"""
def __init__(self):
Search.__init__(self, VOYAGES_TIMESERIES)
# noinspection PyUnresolvedReferences
def search(
self,
breakdown_frequency: str = None,
breakdown_property: str = None,
breakdown_split_property: str = None,
time_min: datetime = datetime(2022, 1, 1, 0),
time_max: datetime = datetime(2022, 1, 1, 1),
voyage_id: Union[ID, List[ID]] = None,
cargo_movement_id: Union[ID, List[ID]] = None,
voyage_status: Union[str, List[str]] = None,
voyage_status_excluded: Union[str, List[str]] = None,
movement_status: Union[str, List[str]] = None,
movement_status_excluded: Union[str, List[str]] = None,
cargo_status: Union[str, List[str]] = None,
cargo_status_excluded: Union[str, List[str]] = None,
location_status: Union[str, List[str]] = None,
location_status_excluded: Union[str, List[str]] = None,
commitment_status: Union[str, List[str]] = None,
commitment_status_excluded: Union[str, List[str]] = None,
exclude_overlapping_entries: bool = None,
products: Union[ID, List[ID]] = None,
products_excluded: Union[ID, List[ID]] = None,
latest_products: Union[ID, List[ID]] = None,
latest_products_excluded: Union[ID, List[ID]] = None,
charterers: Union[ID, List[ID]] = None,
charterers_excluded: Union[ID, List[ID]] = None,
effective_controllers: Union[ID, List[ID]] = None,
effective_controllers_excluded: Union[ID, List[ID]] = None,
origins: Union[ID, List[ID]] = None,
origins_excluded: Union[ID, List[ID]] = None,
destinations: Union[ID, List[ID]] = None,
destinations_excluded: Union[ID, List[ID]] = None,
locations: Union[ID, List[ID]] = None,
locations_excluded: Union[ID, List[ID]] = None,
vessels: Union[ID, List[ID]] = None,
vessels_excluded: Union[ID, List[ID]] = None,
flags: Union[ID, List[ID]] = None,
flags_excluded: Union[ID, List[ID]] = None,
ice_class: Union[ID, List[ID]] = None,
ice_class_excluded: Union[ID, List[ID]] = None,
vessel_propulsion: Union[ID, List[ID]] = None,
vessel_propulsion_excluded: Union[ID, List[ID]] = None,
vessel_age_min: int = None,
vessel_age_max: int = None,
vessel_dwt_min: int = None,
vessel_dwt_max: int = None,
vessel_wait_time_min: int = None,
vessel_wait_time_max: int = None,
vessel_scrubbers: str = None,
vessels_tags: Union[Tag, List[Tag]] = None,
vessels_tags_excluded: Union[Tag, List[Tag]] = None,
vessel_risk_level: Union[str, List[str]] = None,
vessel_risk_level_excluded: Union[str, List[str]] = None,
has_ship_to_ship: bool = None,
has_charterer: bool = None
) -> BreakdownResult:
"""
Returns a count of voyages per record for the requested date period
# Arguments
breakdown_frequency: Frequency denoting the granularity of the time series. Must be one of the following: `'day'`, `'week'`, `'doe_week'`, `'month'`, `'quarter'`, `'year'`.
breakdown_property: Property to aggregate upon. Can be one of: `'vessel_count'`, `'cargo_quantity'`, `'avg_wait_time'`,`'dwt'`, `'cubic_capacity'`,
`'tonne_miles'`.
breakdown_split_property: Property to split results by. Can be one of: `'vessel_status'`, `'vessel_class'`, `'vessel_flag'`,`'fixture_status'`, `'origin_region'`,
`'origin_shipping_region'`,`'origin_trading_region'`,`'origin_trading_sub_region'`,`'origin_trading_block'`,`'origin_country'`,`'origin_port'`,
`'origin_terminal'`,`'destination_region'`,`'destination_shipping_region'`,`'destination_trading_region'`,`'destination_trading_sub_region'`,`'destination_trading_block'`,
`'destination_country'`,`'destination_port'`,`'destination_terminal'`,`'location_port'`,`'location_country'`,`'location_shipping_region'`,
`'congestion_location_port'`,`'congestion_location_country'`,`'congestion_location_shipping_region'`,`'product_group'`,`'product_group_product'`,`'product_category'`, `'product_grade'`, `'none'` or not provided.
time_min: The UTC start date of the time filter.
time_max: The UTC end date of the time filter.
voyage_id: An array of unique voyage ID(s) to filter on.
cargo_movement_id: An array of unique cargo movement ID(s) to filter on.
voyage_status: A voyage status, or list of voyage statuses to filter on. Can be one of: `'ballast'`, `'laden'`.
voyage_status_excluded: A voyage status, or list of voyage statuses to exclude.
movement_status: A movement status, or list of movement statuses to filter on. Can be one of: `'moving'`, `'stationary'`, `'waiting'`, `'congestion'`, `'slow'`.
movement_status_excluded: A movement status, or list of movement statuses to exclude.
cargo_status: A cargo status, or list of cargo statuses to filter on. Can be one of: `'in-transit'`, `'floating-storage'`, `'loading'`, `'discharging'`.
cargo_status_excluded: A cargo status, or list of cargo statuses to exclude.
location_status: A location status, or list of location statuses to filter on. Can be one of: `'berth'`, `'anchorage-zone'`, `'dry-dock'`, `'on-the-sea'`.
location_status_excluded: A location status, or list of location statuses to exclude.
commitment_status: A commitment status, or list of commitment statuses to filter on. Can be one of: `'committed'`, `'uncommitted'`, `'open'`, `'unknown'`.
commitment_status_excluded: A commitment status, or list of commitment statuses to exclude.
exclude_overlapping_entries: A boolean to only consider the latest voyage in days where two or more Voyages overlap.
products: A product ID, or list of product IDs to filter on.
products_excluded: A product ID, or list of product IDs to exclude.
latest_products: A product ID, or list of product IDs of the latest cargo on board to filter on.
latest_products_excluded: A product ID, or list of product IDs of the latest cargo on board to exclude.
charterers: A charterer ID, or list of charterer IDs to filter on.
charterers_excluded: A charterer ID, or list of charterer IDs to exclude.
effective_controllers: A vessel owner ID, or list of vessel owner IDs to filter on.
effective_controllers_excluded: A vessel owner ID, or list of vessel owner IDs to exclude.
origins: An origin ID, or list of origin IDs to filter on.
origins_excluded: An origin ID, or list of origin IDs to exclude.
destinations: A destination ID, or list of destination IDs to filter on.
destinations_excluded: A destination ID, or list of destination IDs to exclude.
locations: A location ID, or list of location IDs to filter on.
locations_excluded: A location ID, or list of location IDs to exclude.
vessels: A vessel ID or vessel class, or list of vessel IDs/vessel classes to filter on.
vessels_excluded: A vessel ID or vessel class, or list of vessel IDs/vessel classes to exclude.
flags: A flag, or list of flags to filter on.
flags_excluded: A flag, or list of flags to exclude.
ice_class: An ice class, or list of ice classes to filter on.
ice_class_excluded: An ice class, or list of ice classes to ęxclude.
vessel_propulsion: A propulsion method, or list of propulsion methods to filter on.
vessel_propulsion_excluded: A propulsion method, or list of propulsion methods to ęxclude.
vessel_age_min: A number between 1 and 100 (representing years).
vessel_age_max: A number between 1 and 100 (representing years).
vessel_dwt_min: A number representing minimum deadweight tonnage of a vessel.
vessel_dwt_max: A number representing maximum deadweight tonnage of a vessel.
vessel_wait_time_min: A number representing a minimum number of days until a vessel becomes available.
vessel_wait_time_max: A number representing a maximum number of days until a vessel becomes available.
vessel_scrubbers: Either inactive 'disabled', or included 'inc' or excluded 'exc'.
vessels_tags: A time bound vessel tag, or list of time bound vessel tags to filter on.
vessels_tags_excluded: A time bound vessel tag, or list of time bound vessel tags to exclude.
vessel_risk_level: A vessel risk level, or list of vessel risk levels to filter on.
vessel_risk_level_excluded: A vessel risk level, or list of vessel risk levels to exclude.
has_ship_to_ship: A boolean to show data where at least one STS transfer occurs.
has_charterer: A boolean to show data where at least one charterer is specified.
# Returns
`BreakdownResult`
# Example
_Sum of vessels departing from Rotterdam between 26th-28th April 2022, split by location country._
```python
>>> from vortexasdk import VoyagesTimeseries, Geographies
>>> from datetime import datetime
>>> rotterdam = [g.id for g in Geographies().search("rotterdam").to_list() if "port" in g.layer]
>>> search_result = VoyagesTimeseries().search(
... origins=rotterdam,
... time_min=datetime(2022, 4, 26),
... time_max=datetime(2022, 4, 28, 23, 59),
... breakdown_frequency="day",
... breakdown_property="vessel_count",
... breakdown_split_property="location_country",
... ).to_df()
```
Gives the following result:
```
| | key | value | count | breakdown.0.label | breakdown.0.count | breakdown.0.value |
|---:|:--------------------------|--------:|--------:|:--------------------|--------------------:|--------------------:|
| 0 | 2022-04-26 00:00:00+00:00 | 294 | 294 | Netherlands | 85 | 85 |
| 1 | 2022-04-27 00:00:00+00:00 | 281 | 281 | Netherlands | 82 | 82 |
| 2 | 2022-04-28 00:00:00+00:00 | 279 | 279 | Netherlands | 85 | 85 |
```
"""
api_params = {
"voyage_id": convert_to_list(voyage_id),
"cargo_movement_id": convert_to_list(cargo_movement_id),
"voyage_status": convert_to_list(voyage_status),
"cargo_status": convert_to_list(cargo_status),
"location_status": convert_to_list(location_status),
"commitment_status": convert_to_list(commitment_status),
"movement_status": convert_to_list(movement_status),
"products": convert_to_list(products),
"latest_products": convert_to_list(latest_products),
"charterers": convert_to_list(charterers),
"effective_controllers": convert_to_list(effective_controllers),
"origins": convert_to_list(origins),
"destinations": convert_to_list(destinations),
"locations": convert_to_list(locations),
"flags": convert_to_list(flags),
"ice_class": convert_to_list(ice_class),
"vessel_propulsion": convert_to_list(vessel_propulsion),
"vessels": convert_to_list(vessels),
"vessels_tags": convert_to_list(vessels_tags),
"vessel_risk_level": convert_to_list(vessel_risk_level),
"vessel_age_min": vessel_age_min,
"vessel_age_max": vessel_age_max,
"vessel_dwt_min": vessel_dwt_min,
"vessel_dwt_max": vessel_dwt_max,
"vessel_wait_time_min": vessel_wait_time_min,
"vessel_wait_time_max": vessel_wait_time_max,
"vessel_scrubbers": vessel_scrubbers,
"has_charterer": has_charterer,
"has_ship_to_ship": has_ship_to_ship,
"exclude_overlapping_entries": exclude_overlapping_entries,
"time_max": to_ISODate(time_max) if time_max else None,
"time_min": to_ISODate(time_min) if time_min else None,
"breakdown_frequency": breakdown_frequency,
"breakdown_split_property": breakdown_split_property,
"breakdown_property": breakdown_property,
"voyage_status_excluded": convert_to_list(voyage_status_excluded),
"cargo_status_excluded": convert_to_list(cargo_status_excluded),
"location_status_excluded": convert_to_list(location_status_excluded),
"commitment_status_excluded": convert_to_list(commitment_status_excluded),
"movement_status_excluded": convert_to_list(movement_status_excluded),
"products_excluded": convert_to_list(products_excluded),
"latest_products_excluded": convert_to_list(latest_products_excluded),
"charterers_excluded": convert_to_list(charterers_excluded),
"effective_controllers_excluded": convert_to_list(effective_controllers_excluded),
"origins_excluded": convert_to_list(origins_excluded),
"destinations_excluded": convert_to_list(destinations_excluded),
"locations_excluded": convert_to_list(locations_excluded),
"flags_excluded": convert_to_list(flags_excluded),
"ice_class_excluded": convert_to_list(ice_class_excluded),
"vessel_propulsion_excluded": convert_to_list(vessel_propulsion_excluded),
"vessels_excluded": convert_to_list(vessels_excluded),
"vessels_tags_excluded": convert_to_list(vessels_tags_excluded),
"vessel_risk_level_excluded": convert_to_list(vessel_risk_level_excluded),
}
return BreakdownResult(super().search(response_type="breakdown", **api_params))