From 9226ddb7bbdeb65c80398bd0884621497f22443c Mon Sep 17 00:00:00 2001 From: Mathew Biddle <8480023+MathewBiddle@users.noreply.github.com> Date: Thu, 23 May 2024 14:01:53 -0400 Subject: [PATCH] grabbing gbif downloads adding column to tests --- ioos_metrics/ioos_metrics.py | 10 ++++++++++ tests/test_metrics.py | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ioos_metrics/ioos_metrics.py b/ioos_metrics/ioos_metrics.py index 9464f34..3814d8f 100644 --- a/ioos_metrics/ioos_metrics.py +++ b/ioos_metrics/ioos_metrics.py @@ -588,6 +588,7 @@ def mbon_stats(): 'doi': [df['results'].values[0][0]['doi']] })], ignore_index=True) + df_gbif = pd.DataFrame() for key in df_mapping['gbif_uuid']: @@ -601,6 +602,15 @@ def mbon_stats(): # merge the OBIS and GBIF data frames together df_obis = df_obis.merge(df_mapping, on='obis_id') + # add gbif download stats + + for key in df_obis['gbif_uuid']: + url = f'https://api.gbif.org/v1/occurrence/download/statistics/export?datasetKey={key}' + df2 = pd.read_csv(url,sep='\t') + df2_group = df2.groupby('year').agg({'number_downloads':'sum'}) + + 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 diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 8d373e7..093c19b 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -89,7 +89,8 @@ def test_mbon_stats(): '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'] + '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])