From 54403aa028ae49536a349ed8a7bd320a572d8b9e Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Thu, 7 Jun 2018 12:59:33 +0100 Subject: [PATCH 1/4] Make humanitarian-scope tests more complete MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If `` is used, is_humanitarian should be true. This checks that’s the case. --- stats/tests/test_humanitarian.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stats/tests/test_humanitarian.py b/stats/tests/test_humanitarian.py index 4f5d5da4617..1c14e006612 100644 --- a/stats/tests/test_humanitarian.py +++ b/stats/tests/test_humanitarian.py @@ -619,7 +619,10 @@ def test_humanitarian_scope_valid(version): ''') + assert activity_stats.humanitarian()['is_humanitarian'] == 1 + assert activity_stats.humanitarian()['is_humanitarian_by_attrib'] == 0 assert activity_stats.humanitarian()['contains_humanitarian_scope'] == 1 + assert activity_stats.humanitarian()['uses_humanitarian_clusters_vocab'] == 0 @pytest.mark.parametrize('version', ['2.02']) @@ -634,7 +637,10 @@ def test_humanitarian_scope_invalid(version): ''') + assert activity_stats.humanitarian()['is_humanitarian'] == 1 + assert activity_stats.humanitarian()['is_humanitarian_by_attrib'] == 0 assert activity_stats.humanitarian()['contains_humanitarian_scope'] == 0 + assert activity_stats.humanitarian()['uses_humanitarian_clusters_vocab'] == 0 @pytest.mark.parametrize('version', ['2.02']) From b3e1acf1f133f87ccd4cc1a304d822c5c33ac229 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Thu, 7 Jun 2018 11:15:38 +0100 Subject: [PATCH 2/4] Inc. activities using humanitarian-scope in count --- stats/dashboard.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stats/dashboard.py b/stats/dashboard.py index d70b939f338..7d199f874d4 100644 --- a/stats/dashboard.py +++ b/stats/dashboard.py @@ -1215,6 +1215,8 @@ def humanitarian(self): is_not_humanitarian_by_attrib_transaction = 1 if not is_humanitarian_by_attrib_transaction and set(self.element.xpath('transaction/@humanitarian')).intersection(['0', 'false']) else 0 is_humanitarian_by_attrib = (self._version() in ['2.02']) and (is_humanitarian_by_attrib_activity or (is_humanitarian_by_attrib_transaction and not is_not_humanitarian_by_attrib_activity)) + is_humanitarian_by_scope = (self._version() in ['2.02']) and (self.element.xpath('humanitarian-scope') != []) + # logic around DAC sector codes deemed to be humanitarian is_humanitarian_by_sector_5_digit_activity = 1 if set(self.element.xpath('sector[@vocabulary="{0}" or not(@vocabulary)]/@code'.format(self._dac_5_code()))).intersection(humanitarian_sectors_dac_5_digit) else 0 is_humanitarian_by_sector_5_digit_transaction = 1 if set(self.element.xpath('transaction[not(@humanitarian="0" or @humanitarian="false")]/sector[@vocabulary="{0}" or not(@vocabulary)]/@code'.format(self._dac_5_code()))).intersection(humanitarian_sectors_dac_5_digit) else 0 @@ -1226,7 +1228,7 @@ def humanitarian(self): is_humanitarian_by_sector = is_humanitarian_by_sector_activity or (is_humanitarian_by_sector_transaction and (self._major_version() in ['2'])) # combine the various ways in which an activity may be humanitarian - is_humanitarian = 1 if (is_humanitarian_by_attrib or is_humanitarian_by_sector) else 0 + is_humanitarian = 1 if (is_humanitarian_by_attrib or is_humanitarian_by_scope or is_humanitarian_by_sector) else 0 # deal with some edge cases that have veto if is_not_humanitarian_by_attrib_activity: is_humanitarian = 0 From 0465194e719851e60f0442f80670517ac85bc16e Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Thu, 7 Jun 2018 11:16:41 +0100 Subject: [PATCH 3/4] Refactor very slightly, for clarity --- stats/dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stats/dashboard.py b/stats/dashboard.py index 7d199f874d4..fcb62106692 100644 --- a/stats/dashboard.py +++ b/stats/dashboard.py @@ -1236,7 +1236,7 @@ def humanitarian(self): return { 'is_humanitarian': is_humanitarian, 'is_humanitarian_by_attrib': is_humanitarian_by_attrib, - 'contains_humanitarian_scope': 1 if (self._version() in ['2.02']) and self.element.xpath('humanitarian-scope/@type') and self.element.xpath('humanitarian-scope/@code') else 0, + 'contains_humanitarian_scope': 1 if is_humanitarian_by_scope and self.element.xpath('humanitarian-scope/@type') and self.element.xpath('humanitarian-scope/@code') else 0, 'uses_humanitarian_clusters_vocab': 1 if (self._version() in ['2.02']) and self.element.xpath('sector/@vocabulary="10"') else 0 } From 2a4633cd808da8f20ca154164b3e403eb305d5ba Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Thu, 7 Jun 2018 11:18:32 +0100 Subject: [PATCH 4/4] Add v2.03 support for humanitarian-scope This just saves updating the PR that adds v2.03 support. --- stats/dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stats/dashboard.py b/stats/dashboard.py index fcb62106692..d3ae42fb69a 100644 --- a/stats/dashboard.py +++ b/stats/dashboard.py @@ -1215,7 +1215,7 @@ def humanitarian(self): is_not_humanitarian_by_attrib_transaction = 1 if not is_humanitarian_by_attrib_transaction and set(self.element.xpath('transaction/@humanitarian')).intersection(['0', 'false']) else 0 is_humanitarian_by_attrib = (self._version() in ['2.02']) and (is_humanitarian_by_attrib_activity or (is_humanitarian_by_attrib_transaction and not is_not_humanitarian_by_attrib_activity)) - is_humanitarian_by_scope = (self._version() in ['2.02']) and (self.element.xpath('humanitarian-scope') != []) + is_humanitarian_by_scope = (self._version() in ['2.02', '2.03']) and (self.element.xpath('humanitarian-scope') != []) # logic around DAC sector codes deemed to be humanitarian is_humanitarian_by_sector_5_digit_activity = 1 if set(self.element.xpath('sector[@vocabulary="{0}" or not(@vocabulary)]/@code'.format(self._dac_5_code()))).intersection(humanitarian_sectors_dac_5_digit) else 0