/
voyages_product_breakdown.py
382 lines (295 loc) · 21.2 KB
/
voyages_product_breakdown.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
"""
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///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJXmsrmZYH1olL1olJXmsr1olJXmsrmZYH1olL1olJXmsrmZYH1olJXmsr1olL1olJ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CC)](https://mybinder.org/v2/gh/VorTECHsa/python-sdk/master?filepath=docs%2Fexamples%2Ftry_me_out%2Fvoyages_product_breakdown.ipynb)
"""
from datetime import datetime
from typing import Any, Dict, List, Union
from vortexasdk.api import ID
from vortexasdk.api.shared_types import Tag, to_ISODate
from vortexasdk.endpoints.endpoints import VOYAGES_BREAKDOWN
from vortexasdk.endpoints.voyages_breakdown_result import (
VoyagesBreakdownResult,
)
from vortexasdk.operations import Search
from vortexasdk.utils import convert_to_list
# noinspection PyUnresolvedReferences
class VoyagesProductBreakdown(Search):
"""
VoyagesProductBreakdown class has an optional _second_breakdown_ property.
Please note: you will require a subscription to our Freight module to access this endpoint.
# Arguments
second_breakdown: An optional second breakdown property. Can be: `'status'`.
"""
def __init__(
self,
second_breakdown: str = None, # path parameter
):
product_property = "product"
if second_breakdown:
endpoint = (
f"{VOYAGES_BREAKDOWN}/{product_property}/{second_breakdown}"
)
else:
endpoint = f"{VOYAGES_BREAKDOWN}/{product_property}"
Search.__init__(self, endpoint)
# noinspection PyUnresolvedReferences
def search(
self,
breakdown_product: str,
breakdown_size: int = None,
time_min: datetime = datetime(2024, 1, 1, 0),
time_max: datetime = datetime(2024, 3, 31, 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,
voyage_origins: Union[ID, List[ID]] = None,
voyage_origins_excluded: Union[ID, List[ID]] = None,
voyage_destinations: Union[ID, List[ID]] = None,
voyage_destinations_excluded: Union[ID, List[ID]] = None,
locations: Union[ID, List[ID]] = None,
locations_excluded: Union[ID, List[ID]] = None,
congestion_target_location: Union[str, List[str]] = None,
congestion_target_location_excluded: Union[str, List[str]] = 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_cbm_min: int = None,
vessel_cbm_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,
vessel_owners: Union[ID, List[ID]] = None,
vessel_owners_excluded: Union[ID, List[ID]] = None,
time_charterer: Union[ID, List[ID]] = None,
time_charterer_excluded: Union[ID, List[ID]] = None,
intra_movements: str = None,
) -> VoyagesBreakdownResult:
"""
Returns buckets by frequency of specified metric, each bucket includes breakdown by specified breakdown_property of a metric.
# Arguments
breakdown_product: Determines the product layer of the breakdown.
breakdown_size: Optional number of top hits to return.
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.
time_charterer: A time charterer ID, or list of time charterer IDs to filter on.
time_charterer_excluded: A time charterer ID, or list of time charterer IDs to exclude.
effective_controllers: A vessel effective controller ID, or list of vessel effective controller IDs to filter on.
effective_controllers_excluded: A effective controller ID, or list of effective controller IDs to exclude.
vessel_owners: A vessel owner ID, or list of vessel owners IDs to filter on.
vessel_owners_excluded: A vessel owner ID, or list of vessel owners IDs to exclude.
origins: An origin ID, or list of origin IDs for all the cargoes of a voyage to filter on.
origins_excluded: An origin ID, or list of origin IDs for all the cargoes of a voyage to exclude.
destinations: A destination ID, or list of destination IDs for all the cargoes of a voyage to filter on.
destinations_excluded: A destination ID, or list of destination IDs for all the cargoes of a voyage to exclude.
voyage_origins: An origin ID, or list of origin IDs for the first origin of voyage to filter on.
voyage_origins_excluded: An origin ID, or list of origin IDs for the first origin of voyage to exclude.
voyage_destinations: A destination ID, or list of destination IDs for the last destination of a voyage to filter on.
voyage_destinations_excluded: A destination ID, or list of destination IDs for the final destination of a voyage 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.
congestion_target_location: A congestion location ID, or list of congestion location IDs to filter on.
congestion_target_location_excluded: A congestion location ID, or list of congestion 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_cbm_min: A number representing minimum cubic capacity of a vessel.
vessel_cbm_max: A number representing maximum cubic capacity 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: Filter data where at least one STS transfer occurs, or none. - one of: `'disabled'`, `'inc'`, `'exc'`. Passing disabled means the filter is not active.
has_charterer: Filter data where at least one charterer is specified, or none. - one of: `'disabled'`, `'inc'`, `'exc'`. Passing disabled means the filter is not active.
intra_movements: Filter movements based on whether the vessel started and ended in the same country, or geographical layer.
# Returns
`BreakdownResult`
# Example
_Vessels breakdown by product and status between 1st of January 2024 - 29th of Fabuary 2024 with a "category" layer breakdown._
```python
>>> from vortexasdk import VoyagesProductBreakdown
>>> from datetime import datetime
>>> search_result = VoyagesProductBreakdown(
... second_breakdown="status",
... ).search(
... time_min=datetime(2024, 1, 1),
... time_max=datetime(2024, 2, 29, 23, 59),
... breakdown_product="category",
... origins=["c4b606ff15bd9b86c37e4fbccf8b5f7e57890c6f675e7a250538e297b4c1303e"],
... ).to_df()
```
Gives the following result:
```
| | id | label | value | breakdown.0.id | breakdown.0.label | breakdown.0.value | breakdown.1.id | breakdown.1.label | breakdown.1.value |
|---:|:-----------------|:--------------------------------|--------:|:-----------------|:--------------------|:--------------------|:-----------------|:--------------------|:--------------------|
| 0 | 903edb3eea470524 | Chemicals | 23 | ballast | ballast | 1 | laden | laden | 22 |
| 1 | 9d52ede1cff0421a | Biodiesel Feedstock | 22 | ballast | ballast | 1 | laden | laden | 20 |
| 2 | 46c5395c665a4dc1 | Other Biodiesel/ Edible Oils | 5 | ballast | ballast | 1 | laden | laden | 4 |
| 3 | b2034f1ad3a4ac26 | Gasoil | 4 | ballast | ballast | 3 | laden | laden | 1 |
| 4 | 3c227f964d804a12 | ULSD (Ultra Low Sulphur Diesel) | 3 | ballast | ballast | 3 | laden | laden | |
| 5 | 1854369f995f26cb | Blending Components | 1 | ballast | ballast | | laden | laden | 1 |
| 6 | c76d43ed46524d62 | Finished Gasoline | 1 | ballast | ballast | | laden | laden | 1 |
```
"""
api_params: Dict[str, Any] = {
"breakdown_product": breakdown_product,
"breakdown_size": breakdown_size,
"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),
"time_charterer": convert_to_list(time_charterer),
"effective_controllers": convert_to_list(effective_controllers),
"vessel_owners": convert_to_list(vessel_owners),
"origins": convert_to_list(origins),
"destinations": convert_to_list(destinations),
"voyage_origins": convert_to_list(voyage_origins),
"voyage_destinations": convert_to_list(voyage_destinations),
"locations": convert_to_list(locations),
"congestion_target_location": convert_to_list(
congestion_target_location
),
"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_cbm_min": vessel_cbm_min,
"vessel_cbm_max": vessel_cbm_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,
"intra_movements": intra_movements,
"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),
"time_charterer_excluded": convert_to_list(
time_charterer_excluded
),
"effective_controllers_excluded": convert_to_list(
effective_controllers_excluded
),
"vessel_owners_excluded": convert_to_list(vessel_owners_excluded),
"origins_excluded": convert_to_list(origins_excluded),
"destinations_excluded": convert_to_list(destinations_excluded),
"voyage_origins_excluded": convert_to_list(
voyage_origins_excluded
),
"voyage_destinations_excluded": convert_to_list(
voyage_destinations_excluded
),
"locations_excluded": convert_to_list(locations_excluded),
"congestion_target_location_excluded": convert_to_list(
congestion_target_location_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
),
}
response = super().search_with_client(**api_params)
return VoyagesBreakdownResult(
records=response["data"], reference=response["reference"]
)