Skip to content

Commit

Permalink
Ess-3110 Not all fields are mapped when getting a campaign (#42)
Browse files Browse the repository at this point in the history
* Map all fields on get_campaign, and fix get_swimops_campaign to return gracefully if no operations
* Add black formatter to extension list in vs code
* Fix a double return
* Add diff to see the test failures in full
* Add new expected parameters to response

---------

Co-authored-by: hakon-molven-4ss <70759227+hakon-molven-4ss@users.noreply.github.com>
Co-authored-by: Bjørn Einar Bjartnes <88324093+bjorn-einar-bjartnes-4ss@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent e6b0fb0 commit 2cf4c78
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-python.black-formatter"
]
}
14 changes: 11 additions & 3 deletions fourinsight/campaigns/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ def get_campaign(self, campaign_id):
response_map = {
("id", "CampaignID"): None,
("projectnumber", "Project Number"): None,
("campaignname", "Name"): None,
("campaigntype", "Type"): None,
("client", "Client"): None,
("ponumber", "PO Number"): None,
("vessel", "Vessel"): None,
("vesselcontractor", "Vessel Contractor"): None,
("wellname", "Well Name"): None,
Expand All @@ -205,6 +208,12 @@ def get_campaign(self, campaign_id):
("maindataprovider", "Main Data Provider"): None,
("startdate", "Start Date"): None,
("enddate", "End Date"): None,
("geopositionid", "GeoTrack Position ID"): None,
("geolocation", "GeoTrack Location"): None,
("geotitle", "GeoTrack Title"): None,
("hstimeseriesid", "Hs Timeseries ID"): None,
("tptimeseriesid", "Tp Timeseries ID"): None,
("wdtimeseriesid", "Wd Timeseries ID"): None,
}

# change to v1.1 when available
Expand Down Expand Up @@ -343,8 +352,6 @@ def _get_channels(self, campaign_id, sensor_id):
]
return response_out

return response_out

def get_sensors(self, campaign_id):
"""
Get sensors.
Expand Down Expand Up @@ -430,7 +437,8 @@ def get_swimops_campaign(self, campaign_id):
}

response = self._get_payload(self._url(f"/{campaign_id}/Swimops"))

if not response or not isinstance(response, list):
return
response_out = _dict_rename(response[0], response_map)
return response_out

Expand Down
8 changes: 5 additions & 3 deletions fourinsight/campaigns/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ def events(self, value=None, by="Event Type"):
def _sort_list_by_start(list_):
sorted_list = sorted(
list_,
key=lambda x: pd.to_datetime(x["Start"])
if x["Start"]
else pd.to_datetime(0).tz_localize("UTC"),
key=lambda x: (
pd.to_datetime(x["Start"])
if x["Start"]
else pd.to_datetime(0).tz_localize("UTC")
),
)
return sorted_list

Expand Down
18 changes: 18 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ def test_get_campaign(self, campaigns_api, auth_session, response, headers_expec
response.json.assert_called()
expect = {
"CampaignID": "028ff3a8-2e08-463d-a4fe-bc10a53450ea",
"Name": "0872 - 30_17a-J4 (P3)",
"Type": "SWIM Campaign",
"PO Number": None,
"Project Number": "0872",
"Client": "Maersk Oil",
"Vessel": "Ocean Valiant",
Expand All @@ -248,6 +251,12 @@ def test_get_campaign(self, campaigns_api, auth_session, response, headers_expec
"Main Data Provider": "4Subsea",
"Start Date": "2017-04-08T00:00:00+00:00",
"End Date": "2017-05-13T00:00:00+00:00",
"GeoTrack Location": "10#21",
"GeoTrack Position ID": "c1092920-0434-483a-ac6b-2511715ab84c",
"GeoTrack Title": "10 er test 2",
"Hs Timeseries ID": "e2ba4833-44ae-4cef-b8a7-18ae82fef327",
"Tp Timeseries ID": "4cfe7e31-f4b5-471f-92c6-b260ee236cff",
"Wd Timeseries ID": "2c6454b8-a274-4845-80e0-cb29c0efc32b",
}
assert expect == out

Expand Down Expand Up @@ -278,6 +287,15 @@ def test_get_campaign_camelcase(
"Main Data Provider": "4Subsea",
"Start Date": "2017-04-08T00:00:00+00:00",
"End Date": "2017-05-13T00:00:00+00:00",
"GeoTrack Location": "10#21",
"GeoTrack Position ID": "c1092920-0434-483a-ac6b-2511715ab84c",
"GeoTrack Title": "10 er test 2",
"Hs Timeseries ID": "e2ba4833-44ae-4cef-b8a7-18ae82fef327",
"Name": "0872 - 30_17a-J4 (P3)",
"PO Number": None,
"Tp Timeseries ID": "4cfe7e31-f4b5-471f-92c6-b260ee236cff",
"Type": "SWIM Campaign",
"Wd Timeseries ID": "2c6454b8-a274-4845-80e0-cb29c0efc32b",
}
assert expect == out

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ envlist =

[testenv]
commands =
pytest --basetemp={envtmpdir} --cov=fourinsight.campaigns --cov-report html:cov_html-{envname} --junitxml=junit-{envname}.xml ./tests
pytest --basetemp={envtmpdir} --cov=fourinsight.campaigns --cov-report html:cov_html-{envname} --junitxml=junit-{envname}.xml ./tests -vv
deps =
pytest
pytest-cov
Expand Down

0 comments on commit 2cf4c78

Please sign in to comment.