From cc67e698f94805215eb0001533e991dbe3f3975e Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 18 Nov 2024 17:36:46 +1300 Subject: [PATCH] Add OKR output (#5) --- get_org_stats.py | 17 ++++++++++++++--- requirements.txt | 2 +- test-requirements.txt | 4 ++-- tests/fixtures/total_stats.csv | 2 ++ tests/test_get_org_stats.py | 2 ++ 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/total_stats.csv diff --git a/get_org_stats.py b/get_org_stats.py index c5c61df..c8ebb8d 100644 --- a/get_org_stats.py +++ b/get_org_stats.py @@ -178,7 +178,7 @@ def main(downloads, output_dir, **ignore): organisation["delinquent datasets"] += 1 if datasetstats.in_explorer_or_grid == "Y": organisation["in explorer or grid"] = "Yes" - if datasetstats.updated_by_cod_script == "Y": + if datasetstats.updated_by_cod_script == "Y" and is_public_not_requestable_archived: organisation["updated by cod script"] += 1 total_updated_by_cod += 1 if datasetstats.created > organisation["latest created dataset date"]: @@ -188,7 +188,7 @@ def main(downloads, output_dir, **ignore): "latest scripted update date"]: organisation[ "latest scripted update date"] = datasetstats.last_modified - if datasetstats.updated_by_noncod_script == "Y": + if datasetstats.updated_by_noncod_script == "Y" and is_public_not_requestable_archived: organisation["updated by script"] += 1 total_updated_by_script += 1 if datasetstats.outdated_lastmodified == "Y": @@ -357,11 +357,22 @@ def get_number_percentage(organisation, key): message.append("\n") logger.warning("".join(message)) - logger.info(f"Total public datasets = {total_public}") + logger.info(f"Total public datasets (excluding requestable, archived) = {total_public}") logger.info(f"Total public updated by cod script = {total_updated_by_cod}") logger.info( f"Total public updated by all other scripts = {total_updated_by_script}" ) + quarterly_okr = get_fraction_str( + total_updated_by_script * 100, + total_public, + format="%.0f", + ) + logger.info(f"Quarterly OKR = {quarterly_okr}") + filepath = join(output_dir, "total_stats.csv") + logger.info(f"Writing totals to {filepath}") + headers = ["Public - request & archive", "Updated by COD", "Updated by Script", "Quarterly OKR"] + rows = [[total_public, total_updated_by_cod, total_updated_by_script, quarterly_okr]] + write_list_to_csv(filepath, rows, headers, encoding="utf-8") return total_public, total_updated_by_cod, total_updated_by_script diff --git a/requirements.txt b/requirements.txt index 6e7562a..ace3d70 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -hdx-python-api==6.3.1 +hdx-python-api==6.3.5 mixpanel-utils diff --git a/test-requirements.txt b/test-requirements.txt index cdd616b..1020052 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,3 @@ -pytest==8.3.1 -pytest-cov==5.0.0 +pytest==8.3.3 +pytest-cov==6.0.0 -r requirements.txt diff --git a/tests/fixtures/total_stats.csv b/tests/fixtures/total_stats.csv new file mode 100644 index 0000000..b2030ed --- /dev/null +++ b/tests/fixtures/total_stats.csv @@ -0,0 +1,2 @@ +Public - request & archive,Updated by COD,Updated by Script,Quarterly OKR +20823,583,16594,80 diff --git a/tests/test_get_org_stats.py b/tests/test_get_org_stats.py index 24765a4..85ca833 100644 --- a/tests/test_get_org_stats.py +++ b/tests/test_get_org_stats.py @@ -18,3 +18,5 @@ def test_get_org_stats(self, configuration, fixtures, mock_downloads): assert total_updated_by_script == 16594 filename = "org_stats.csv" assert_files_same(join(fixtures, filename), join(folder, filename)) + filename = "total_stats.csv" + assert_files_same(join(fixtures, filename), join(folder, filename))