Skip to content
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

PIPELINE-1863 Normalize and standardize input fields on normalization #11

Merged
merged 5 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 111 additions & 1 deletion packages/pipe-vms-ingestion/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/pipe-vms-ingestion/pyproject-build.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ packages = [
python = ">=3.9,<3.11"
apache-beam = {extras = ["gcp"], version = "2.56.0"}
jinja2 = "^3.0.3"
shipdataprocess = "^0.8.6"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to take ownership of that library put some love there. Currently, its including pytest in its dependencies 😞 .


[tool.poetry.group.dev.dependencies]
autopep8 = "2.0.2"
Expand Down
2 changes: 2 additions & 0 deletions packages/pipe-vms-ingestion/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ readme = 'README.md'
python = ">=3.9,<3.11"
apache-beam = {extras = ["gcp"], version = "2.56.0"}
jinja2 = "^3.0.3"
shipdataprocess = "^0.8.6"
pandas = "^2.2.2"

[tool.poetry.dependencies.bigquery]
path = "../libs/bigquery"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
class TestBRANormalize(unittest.TestCase):

options = build_pipeline_options_with_defaults(
argv=["--country_code=bra", '--source=""', '--destination=""', '--start_date=""', '--end_date=""']
argv=[
"--country_code=bra",
'--source=""',
'--destination=""',
'--start_date=""',
'--end_date=""',
]
)

# Our input data, which will make up the initial PCollection.
Expand All @@ -34,7 +40,7 @@ class TestBRANormalize(unittest.TestCase):
# Our output data, which is the expected data that the final PCollection must match.
EXPECTED = [
{
"msgid": "bb84c21c72cb41d85d724245b52cf2ab",
"msgid": "5411260da7a997217b865007b51e7295",
"source": "ONYXSAT_BRAZIL_VMS",
"source_type": "VMS",
"source_tenant": "BRA",
Expand All @@ -43,18 +49,18 @@ class TestBRANormalize(unittest.TestCase):
"source_ssvid": "4961089",
"type": "VMS",
"internal_id": "4961089",
"ssvid": "BRA|i:4961089|s:Cibradep X",
"ssvid": "BRA|i:4961089|s:CIBRADEP10",
"timestamp": datetime.fromisoformat("2024-05-01 05:35:45+00:00"),
"lat": -1.21861112117767,
"lon": -48.4911117553711,
"speed": 9.1792656587473,
"course": 192.0,
"heading": None,
"shipname": "Cibradep X",
"shipname": "CIBRADEP X",
"callsign": None,
"destination": None,
"imo": None,
"shiptype": "fishing",
"shiptype": "FISHING",
"receiver_type": None,
"receiver": None,
"length": None,
Expand All @@ -63,7 +69,9 @@ class TestBRANormalize(unittest.TestCase):
"class_b_cs_flag": None,
"received_at": None,
"ingested_at": None,
"timestamp_date": datetime.date(datetime.fromisoformat("2024-05-01 05:35:45+00:00")),
"timestamp_date": datetime.date(
datetime.fromisoformat("2024-05-01 05:35:45+00:00")
),
}
]

Expand All @@ -78,4 +86,6 @@ def test_normalize(self):
output: pvalue.PCollection = input | BRANormalize(feed="bra")

# Assert that the output PCollection matches the EXPECTED data.
assert_that(output, pcol_equal_to(TestBRANormalize.EXPECTED), label="CheckOutput")
assert_that(
output, pcol_equal_to(TestBRANormalize.EXPECTED), label="CheckOutput"
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
class TestCHLNormalize(unittest.TestCase):

options = build_pipeline_options_with_defaults(
argv=["--country_code=chl", '--source=""', '--destination=""', '--start_date=""', '--end_date=""']
argv=[
"--country_code=chl",
'--source=""',
'--destination=""',
'--start_date=""',
'--end_date=""',
]
)

# Our input data, which will make up the initial PCollection.
Expand All @@ -33,15 +39,15 @@ class TestCHLNormalize(unittest.TestCase):
# Our output data, which is the expected data that the final PCollection must match.
EXPECTED = [
{
"msgid": "1d4e4dde1f0178df0f396c14587feb04",
"source": "chile_vms_some_fleet",
"msgid": "c8de2f410ae274c94fbd6583f722fc6b",
"source": "CHILE_VMS_SOME_FLEET",
"source_type": "VMS",
"source_tenant": "CHL",
"source_provider": "SERNAPESCA",
"source_fleet": "some_fleet",
"source_fleet": "SOME_FLEET",
"source_ssvid": None,
"type": "VMS",
"ssvid": "CHL|s:AUSTRAL TRAVELER|c:ABC123",
"ssvid": "CHL|s:AUSTRALTRAVELER|c:ABC123",
"timestamp": datetime.fromisoformat("2020-01-01 20:23:01+00:00"),
"lat": -52.546,
"lon": -71.947,
Expand All @@ -62,7 +68,9 @@ class TestCHLNormalize(unittest.TestCase):
"class_b_cs_flag": None,
"received_at": None,
"ingested_at": None,
"timestamp_date": datetime.date(datetime.fromisoformat("2020-01-01 20:23:01+00:00")),
"timestamp_date": datetime.date(
datetime.fromisoformat("2020-01-01 20:23:01+00:00")
),
}
]

Expand All @@ -77,4 +85,6 @@ def test_normalize(self):
output: pvalue.PCollection = input | CHLNormalize(feed="chl")

# Assert that the output PCollection matches the EXPECTED data.
assert_that(output, pcol_equal_to(TestCHLNormalize.EXPECTED), label="CheckOutput")
assert_that(
output, pcol_equal_to(TestCHLNormalize.EXPECTED), label="CheckOutput"
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
class TestCRINormalize(unittest.TestCase):

options = build_pipeline_options_with_defaults(
argv=["--country_code=cri", '--source=""', '--destination=""', '--start_date=""', '--end_date=""']
argv=[
"--country_code=cri",
'--source=""',
'--destination=""',
'--start_date=""',
'--end_date=""',
]
)

# Our input data, which will make up the initial PCollection.
Expand Down Expand Up @@ -51,24 +57,26 @@ class TestCRINormalize(unittest.TestCase):
"lat": 9.9798,
"length": None,
"lon": -84.8221,
"msgid": "758d0202a1b6b7166ddb9851e6731091",
"msgid": "0df1eb16d80e0b61fb9639177b3c71fb",
"received_at": None,
"receiver": None,
"receiver_type": None,
"registry_number": None,
"shipname": "K'IN",
"shiptype": None,
"source": "costarica_vms_sardineros",
"source_fleet": "sardineros",
"source": "COSTARICA_VMS_SARDINEROS",
"source_fleet": "SARDINEROS",
"source_provider": "INCOPESCA",
"source_tenant": "CRI",
"source_ssvid": None,
"source_type": "VMS",
"speed": 0.0,
"ssvid": "CRI|s:K'IN",
"ssvid": "CRI|s:KIN",
"status": None,
"timestamp": datetime.fromisoformat("2024-05-01 12:15:01+00:00"),
"timestamp_date": datetime.date(datetime.fromisoformat("2024-05-01 12:15:01+00:00")),
"timestamp_date": datetime.date(
datetime.fromisoformat("2024-05-01 12:15:01+00:00")
),
"type": "VMS",
"width": None,
},
Expand All @@ -85,4 +93,6 @@ def test_normalize(self):
output: pvalue.PCollection = input | CRINormalize(feed="cri")

# Assert that the output PCollection matches the EXPECTED data.
assert_that(output, pcol_equal_to(TestCRINormalize.EXPECTED), label="CheckOutput")
assert_that(
output, pcol_equal_to(TestCRINormalize.EXPECTED), label="CheckOutput"
)
Loading
Loading