Created
March 10, 2013 23:49
-
-
Save markbrough/5131054 to your computer and use it in GitHub Desktop.
IATI Data Quality codelists lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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