Skip to content
Open
Changes from all 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
23 changes: 19 additions & 4 deletions ioos_metrics/ioos_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,12 @@ def metadata_records():
"""These are the number of metadata records currently available through the
[IOOS Catalog](https://data.ioos.us).
Previously the number of records was on the order of 8,600.
Below are three different mechanisms to calculate this metric,
however they do differ and the reason for that difference is unclear.

Unfortunately, the total number of records returned from `package_search()`
contains duplicates.

This claculates the number of records by adding together the total number
of records per harvest source. Which seems to be more representative.

"""
from ckanapi import RemoteCKAN # noqa: PLC0415
Expand All @@ -479,8 +483,19 @@ def metadata_records():
user_agent = "ckanapiioos/1.0 (+https://ioos.us/)"

ioos_catalog = RemoteCKAN(url, user_agent=user_agent)
datasets = ioos_catalog.action.package_search()
return datasets["count"]
harvest_sources = ioos_catalog.action.package_search(fq='dataset_type:harvest', rows=1000)

grand_total = 0
df_totals = pd.DataFrame()
for harvest in harvest_sources['results']:
harvest_source = ioos_catalog.action.harvest_source_show(id=harvest['id'])
total_datasets = harvest_source['status']['total_datasets']
df_totals = pd.concat(
[df_totals,
pd.DataFrame({'source':[harvest_source['title']],'total_datasets':[total_datasets]})]
)

return df_totals['total_datasets'].sum()


@functools.lru_cache(maxsize=128)
Expand Down
Loading