Skip to content

Commit

Permalink
fix all lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed May 29, 2024
1 parent 83293b8 commit 93cb084
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 25 deletions.
14 changes: 6 additions & 8 deletions ioos_metrics/ioos_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def hf_radar_installations():

@functools.lru_cache(maxsize=128)
def mbon_stats():
"""This function collects download statistics about MBON affiliated datasets shared with the Ocean Biodiversity
"""Collects download statistics about MBON affiliated datasets shared with the Ocean Biodiversity
Information System (OBIS) and the Global Biodiversity Information Framework (GBIF). The function returns a
dataframe with rows corresponding to each paper citing a dataset.
"""
Expand Down Expand Up @@ -589,10 +589,10 @@ def mbon_stats():
df_mapping,
pd.DataFrame(
{
"gbif_uuid": df["results"].values[0][0]["key"],
"title": [df["results"].values[0][0]["title"]],
"gbif_uuid": df["results"].to_numpy()[0][0]["key"],
"title": [df["results"].to_numpy()[0][0]["title"]],
"obis_id": [df_obis.loc[df_obis["obis_title"] == title, "obis_id"].to_string(index=False)],
"doi": [df["results"].values[0][0]["doi"]],
"doi": [df["results"].to_numpy()[0][0]["doi"]],
},
),
],
Expand All @@ -602,7 +602,7 @@ def mbon_stats():
df_gbif = pd.DataFrame()
for key in df_mapping["gbif_uuid"]:
url = f"https://api.gbif.org/v1/literature/export?format=CSV&gbifDatasetKey={key}"
df2 = pd.read_csv(url) # collect liturature cited information
df2 = pd.read_csv(url) # collect literature cited information
df2.columns = ["literature_" + str(col) for col in df2.columns]
df2["gbif_uuid"] = key

Expand All @@ -620,9 +620,7 @@ def mbon_stats():

df_obis.loc[df_obis["gbif_uuid"] == key, "gbif_downloads"] = str(df2_group.to_dict())

df_out = df_gbif.merge(df_obis, on="gbif_uuid")

return df_out
return df_gbif.merge(df_obis, on="gbif_uuid")


def update_metrics(*, debug=False):
Expand Down
67 changes: 50 additions & 17 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,57 @@ def test_update_metrics():
df = update_metrics(debug=True)
df.to_csv("updated_metrics.csv")


def test_mbon_stats():
df = ioos_metrics.mbon_stats()
columns = ['literature_title', 'literature_authors', 'literature_source',
'literature_discovered', 'literature_published',
'literature_open_access', 'literature_peer_review',
'literature_citation_type', 'literature_countries_of_coverage',
'literature_countries_of_researcher', 'literature_keywords',
'literature_literature_type', 'literature_websites',
'literature_identifiers', 'literature_id', 'literature_abstract',
'literature_topics', 'literature_added', 'literature_gbif_download_key',
'gbif_uuid', 'obis_id', 'obis_url', 'obis_archive', 'obis_published',
'obis_created', 'obis_updated', 'obis_core', 'obis_extensions',
'obis_statistics', 'obis_extent', 'obis_title', 'obis_citation',
'obis_citation_id', 'obis_abstract', 'obis_intellectualrights',
'obis_feed', 'obis_institutes', 'obis_contacts', 'obis_nodes',
'obis_keywords', 'obis_downloads', 'obis_records', 'title', 'doi',
'gbif_downloads']
columns = [
"literature_title",
"literature_authors",
"literature_source",
"literature_discovered",
"literature_published",
"literature_open_access",
"literature_peer_review",
"literature_citation_type",
"literature_countries_of_coverage",
"literature_countries_of_researcher",
"literature_keywords",
"literature_literature_type",
"literature_websites",
"literature_identifiers",
"literature_id",
"literature_abstract",
"literature_topics",
"literature_added",
"literature_gbif_download_key",
"gbif_uuid",
"obis_id",
"obis_url",
"obis_archive",
"obis_published",
"obis_created",
"obis_updated",
"obis_core",
"obis_extensions",
"obis_statistics",
"obis_extent",
"obis_title",
"obis_citation",
"obis_citation_id",
"obis_abstract",
"obis_intellectualrights",
"obis_feed",
"obis_institutes",
"obis_contacts",
"obis_nodes",
"obis_keywords",
"obis_downloads",
"obis_records",
"title",
"doi",
"gbif_downloads",
]

assert isinstance(df, pd.DataFrame)
assert all([col in df.columns for col in columns])
assert not df.empty
assert all(col in df.columns for col in columns)
assert not df.empty

0 comments on commit 93cb084

Please sign in to comment.