Skip to content

Instantly share code, notes, and snippets.

@markbrough
Created March 10, 2013 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markbrough/5131054 to your computer and use it in GitHub Desktop.
Save markbrough/5131054 to your computer and use it in GitHub Desktop.
IATI Data Quality codelists lookup
## possibly at top of mapping.py:
def codelist_lookup(value, codelist, codelists=codelists):
""" codelists is a variable which looks like this:
'Sector': { '11100', '11110', '11120'},
'OrganisationType': { '10', '11', '12'} etc. (this is not 100% accurate data)
"""
if (value in codelists[codelist]):
return True
else:
return False
## IN mapping.py:
def codelist_check(activity, xpath, codelist_name):
return bool(codelist_lookup(activity.xpath(xpath), codelist_name))
@add_partial('(\S*) is on codelist (\S*)\?')
def is_on_codelist(activity, groups):
return codelist_check(activity, groups[0], groups[1])
## IN test_queue.py:
codelists = generateCodelists()
def generateCodelists():
# get list of codelists and associated codes from db
# turn into a dict of the form:
# 'Sector': { '11100', '11110', '11120'},
# 'OrganisationType': { '10', '11', '12'}
# ... etc. (this is not 100% accurate data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment