Skip to content

Commit

Permalink
factor out national platforms call
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Apr 18, 2024
1 parent 32588ce commit 9639aea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
27 changes: 2 additions & 25 deletions ioos_metrics/ioos_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@
from fake_useragent import UserAgent
from gliderpy.fetchers import GliderDataFetcher

from ioos_metrics.national_platforms import (
get_cbibs,
get_cdip,
get_coops,
get_ndbc,
get_nerrs,
get_oap,
)
from ioos_metrics.national_platforms import national_platforms

logging.basicConfig(
filename="metric.log",
Expand Down Expand Up @@ -554,21 +547,13 @@ def update_metrics(*, debug=False):
"IOOS": ioos,
"MBON Projects": mbon_projects,
"Metadata Records": metadata_records,
"National Platforms": national_platforms,
"NGDAC Glider Days": ngdac_gliders_fast,
"OTT Projects": ott_projects,
"QARTOD Manuals": qartod_manuals,
"Regional Associations": regional_associations,
"Regional Platforms": regional_platforms,
}
# We do the national platforms separately b/c this one hits multiple services.
national_platforms_functions = [
get_cbibs,
get_cdip,
get_coops,
get_ndbc,
get_nerrs,
get_oap,
]

# We cannot write the log in parallel. When debugging we should run the queries in seral mode.
if debug:
Expand All @@ -582,9 +567,6 @@ def update_metrics(*, debug=False):
# Log status.
message = _compare_metrics(column=column, num=num)
logging.info(f"{message}")

national_platforms = [function() for function in national_platforms_functions]
new_row.update({"National Platforms": national_platforms})
else:
cpu_count = joblib.cpu_count()
parallel = joblib.Parallel(n_jobs=cpu_count, return_as="generator")
Expand All @@ -593,11 +575,6 @@ def update_metrics(*, debug=False):
columns = dict(zip(functions.keys(), values, strict=False))
new_row.update(columns)

national_platforms = sum(
parallel(joblib.delayed(function)() for function in national_platforms_functions),
)
new_row.update({"National Platforms": national_platforms})

new_row = pd.DataFrame.from_dict(data=new_row, orient="index").T

# only update numbers if it's a new day
Expand Down
5 changes: 5 additions & 0 deletions ioos_metrics/national_platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,8 @@ def get_cdip():
df = table_list[0]

return df["Stn"].unique().size


def national_platforms() -> int:
"""Adds all the national platforms metrics."""
return get_cbibs() + get_cdip() + get_coops() + get_ndbc() + get_nerrs() + get_oap()

0 comments on commit 9639aea

Please sign in to comment.