Skip to content

Commit

Permalink
[IATI/IATI-Dashboard#291] Download and use the 2.01 mapping file
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jan 22, 2015
1 parent 5197478 commit 4619c3f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion helpers/get_codelist_mapping.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
wget https://raw.github.com/IATI/IATI-Codelists/version-1.05/mapping.xml -O mapping.xml
wget https://raw.github.com/IATI/IATI-Codelists/version-1.05/mapping.xml -O mapping-1.xml
wget https://raw.github.com/IATI/IATI-Codelists/version-2.01/mapping.xml -O mapping-2.xml
18 changes: 11 additions & 7 deletions stats/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ def all_and_not_empty(bool_iterable):

## In order to test whether or not correct codelist values are being used in the data
## we need to pull in data about how codelists map to elements
codelist_mapping_xml = etree.parse('helpers/mapping.xml')
codelist_mappings = [ x.text for x in codelist_mapping_xml.xpath('mapping/path') ]
codelist_mappings = [ re.sub('^\/\/iati-activity', './',path) for path in codelist_mappings]
codelist_mappings = [ re.sub('^\/\/', './/', path) for path in codelist_mappings ]
def get_codelist_mapping(major_version):
codelist_mapping_xml = etree.parse('helpers/mapping-{}.xml'.format(major_version))
codelist_mappings = [ x.text for x in codelist_mapping_xml.xpath('mapping/path') ]
codelist_mappings = [ re.sub('^\/\/iati-activity', './',path) for path in codelist_mappings]
codelist_mappings = [ re.sub('^\/\/', './/', path) for path in codelist_mappings ]
return codelist_mappings

codelist_mappings = { major_version: get_codelist_mapping(major_version) for major_version in ['1', '2'] }

CODELISTS = {'1':{}, '2':{}}
for major_version in ['1', '2']:
Expand Down Expand Up @@ -203,7 +207,7 @@ def element_versions(self):
@returns_numberdict
@memoize
def _major_version(self):
version = self.element.attrib.get('version')
version = self.element.getparent().attrib.get('version')
if version and version.startswith('2.'):
return '2'
else:
Expand Down Expand Up @@ -288,15 +292,15 @@ def elements_total(self):
@returns_numberdictdict
def codelist_values(self):
out = defaultdict(lambda: defaultdict(int))
for path in codelist_mappings:
for path in codelist_mappings[self._major_version()]:
for value in self.element.xpath(path):
out[path][value] += 1
return out

@returns_numberdictdict
def codelist_values_by_major_version(self):
out = defaultdict(lambda: defaultdict(int))
for path in codelist_mappings:
for path in codelist_mappings[self._major_version()]:
for value in self.element.xpath(path):
out[path][value] += 1
return { self._major_version(): out }
Expand Down

0 comments on commit 4619c3f

Please sign in to comment.