Skip to content

Commit 7f58851

Browse files
Merge dicts
1 parent a4b6247 commit 7f58851

File tree

2 files changed

+60
-62
lines changed

2 files changed

+60
-62
lines changed

datascience/src/pipeline/flows/vessel_profiles.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from prefect import Flow, case, task
77

88
from src.pipeline.generic_tasks import extract, load
9+
from src.pipeline.processing import merge_dicts
910
from src.pipeline.shared_tasks.control_flow import check_flow_not_running
1011
from src.pipeline.shared_tasks.dates import get_utcnow
1112

@@ -128,7 +129,7 @@ def transform_profiles(
128129
)
129130
profiles = (
130131
profiles.groupby("cfr")["share_dict"]
131-
.agg(list)
132+
.agg(merge_dicts)
132133
.rename(result_column_name)
133134
.reset_index()
134135
)

datascience/tests/test_pipeline/test_flows/test_vessel_profiles.py

+58-61
Original file line numberDiff line numberDiff line change
@@ -21,77 +21,74 @@ def expected_vessel_profiles():
2121
{
2222
"cfr": ["ABC000306959", "CFR000888888"],
2323
"gears": [
24-
[
25-
{"OTB": 0.9533061485568082},
26-
{"OTM": 0.03997761253697929},
27-
{"LLS": 0.006716238906212521},
28-
],
29-
[{"OTB": 1.0}],
24+
{
25+
"LLS": 0.006716238906212521,
26+
"OTB": 0.9533061485568082,
27+
"OTM": 0.03997761253697929,
28+
},
29+
{"OTB": 1.0},
3030
],
3131
"species": [
32-
[
33-
{"ABC": 0.7995522507395858},
34-
{"DEF": 0.08795074758135445},
35-
{"GHI": 0.059966418805468935},
36-
{"PIL": 0.03997761253697929},
37-
{"NEP": 0.003997761253697929},
38-
{"BSS": 0.0031982090029583432},
39-
{"HKE": 0.0022787239146078195},
40-
{"SOL": 0.0015991045014791716},
41-
{"SWO": 0.0012792836011833373},
42-
{"COD": 0.00019988806268489645},
43-
{"BFT": 0.0},
44-
],
45-
[
46-
{"ABC": 0.8438818565400844},
47-
{"DEF": 0.09282700421940929},
48-
{"GHI": 0.06329113924050633},
49-
],
32+
{
33+
"ABC": 0.7995522507395858,
34+
"BFT": 0.0,
35+
"BSS": 0.0031982090029583432,
36+
"COD": 0.00019988806268489645,
37+
"DEF": 0.08795074758135445,
38+
"GHI": 0.059966418805468935,
39+
"HKE": 0.0022787239146078195,
40+
"NEP": 0.003997761253697929,
41+
"PIL": 0.03997761253697929,
42+
"SOL": 0.0015991045014791716,
43+
"SWO": 0.0012792836011833373,
44+
},
45+
{
46+
"ABC": 0.8438818565400844,
47+
"DEF": 0.09282700421940929,
48+
"GHI": 0.06329113924050633,
49+
},
5050
],
5151
"fao_areas": [
52-
[
53-
{"27.7.d": 0.7995522507395858},
54-
{"27.7.e": 0.08795074758135445},
55-
{"27.8.a": 0.06668265771168146},
56-
{"27.8": 0.019988806268489645},
57-
{"27.9": 0.019988806268489645},
58-
{"27.7.a": 0.005836731430398976},
59-
],
60-
[
61-
{"27.7.d": 0.8438818565400844},
62-
{"27.7.e": 0.09282700421940929},
63-
{"28.8.a": 0.06329113924050633},
64-
],
52+
{
53+
"27.8": 0.019988806268489645,
54+
"27.9": 0.019988806268489645,
55+
"27.7.a": 0.005836731430398976,
56+
"27.7.d": 0.7995522507395858,
57+
"27.7.e": 0.08795074758135445,
58+
"27.8.a": 0.06668265771168146,
59+
},
60+
{
61+
"27.7.d": 0.8438818565400844,
62+
"27.7.e": 0.09282700421940929,
63+
"28.8.a": 0.06329113924050633,
64+
},
6565
],
6666
"segments": [
67-
[
68-
{"NO_SEGMENT": 0.9104101703046295},
69-
{"T8-9": 0.06288478452066842},
70-
{"T8-PEL": 0.019988806268489645},
71-
{"L": 0.005836731430398976},
72-
{"L HKE": 0.000679619413128648},
73-
{"L BFT": 0.00019988806268489645},
74-
],
75-
[{"FT": 0.9367088607594937}, {"NO_SEGMENT": 0.06329113924050633}],
67+
{
68+
"L": 0.005836731430398976,
69+
"T8-9": 0.06288478452066842,
70+
"L BFT": 0.00019988806268489645,
71+
"L HKE": 0.000679619413128648,
72+
"T8-PEL": 0.019988806268489645,
73+
"NO_SEGMENT": 0.9104101703046295,
74+
},
75+
{"FT": 0.9367088607594937, "NO_SEGMENT": 0.06329113924050633},
7676
],
77-
"landing_ports": [[{"FRXXX": 1.0}], [{"FRLEH": 1.0}]],
78-
"recent_gears": [[{"OTB": 0.5}, {"LLS": 0.5}], None],
77+
"landing_ports": [{"FRXXX": 1.0}, {"FRLEH": 1.0}],
78+
"recent_gears": [{"LLS": 0.5, "OTB": 0.5}, None],
7979
"recent_species": [
80-
[
81-
{"NEP": 0.3424657534246575},
82-
{"BSS": 0.273972602739726},
83-
{"SOL": 0.136986301369863},
84-
{"HKE": 0.136986301369863},
85-
{"SWO": 0.1095890410958904},
86-
],
80+
{
81+
"BSS": 0.273972602739726,
82+
"HKE": 0.136986301369863,
83+
"NEP": 0.3424657534246575,
84+
"SOL": 0.136986301369863,
85+
"SWO": 0.1095890410958904,
86+
},
8787
None,
8888
],
89-
"recent_fao_areas": [[{"27.8.a": 0.5}, {"27.7.a": 0.5}], None],
90-
"recent_segments": [
91-
[{"L": 0.5}, {"NO_SEGMENT": 0.25}, {"T8-9": 0.25}],
92-
None,
93-
],
94-
"recent_landing_ports": [[{"FRXXX": 1.0}], [{"FRLEH": 1.0}]],
89+
"recent_fao_areas": [{"27.7.a": 0.5, "27.8.a": 0.5}, None],
90+
"recent_segments": [{"L": 0.5, "T8-9": 0.25, "NO_SEGMENT": 0.25}, None],
91+
"recent_landing_ports": [{"FRXXX": 1.0}, {"FRLEH": 1.0}],
9592
"latest_landing_port": ["FRXXX", "FRLEH"],
9693
"latest_landing_facade": ["Hors façade", "SA"],
9794
}

0 commit comments

Comments
 (0)