Skip to content

Commit

Permalink
Merge pull request #77 from MathewBiddle/mbon_stats
Browse files Browse the repository at this point in the history
grabbing gbif downloads
  • Loading branch information
laurabrenskelle authored May 23, 2024
2 parents c820df0 + 9226ddb commit 0938661
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ioos_metrics/ioos_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 0938661

Please sign in to comment.