Skip to content

Commit

Permalink
Return % of grants with errors in extra checks
Browse files Browse the repository at this point in the history
  • Loading branch information
BibianaC authored and robredpath committed Jun 7, 2019
1 parent d89da07 commit 0723d95
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
20 changes: 13 additions & 7 deletions cove_360/lib/threesixtygiving.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def flatten_dict(grant, path=""):
class AdditionalTest():
def __init__(self, **kw):
self.grants = kw['grants']
self.grants_count = len(self.grants)
self.json_locations = []
self.failed = False
self.count = 0
Expand All @@ -216,22 +217,27 @@ def produce_message(self):
'message': self.message
}

def get_heading_count(self):
if self.grants_count == 1 and self.count == 1:
return '1'
return '{:.0%} of'.format(self.count / self.grants_count)

def format_heading_count(self, message, verb='have'):
'''Build a string with count of grants plus message
"""Build a string with count of grants plus message
The grant count phrase for the test is pluralized and
prepended to message, eg: 1 grant has + message,
2 grants have + message or 3 grants contain + message.
'''
noun = 'grant' if self.count == 1 else 'grants'
"""
noun = 'grant' if self.grants_count == 1 else 'grants'
if verb == 'have':
verb = 'has' if self.count == 1 else verb
verb = 'has' if self.grants_count == 1 else verb
elif verb == 'do':
verb = 'does' if self.count == 1 else verb
verb = 'does' if self.grants_count == 1 else verb
else:
# Naively!
verb = verb + 's' if self.count == 1 else verb
return '{} {} {} {}'.format(self.count, noun, verb, message)
verb = verb + 's' if self.grants_count == 1 else verb
return '{} {} {} {}'.format(self.get_heading_count(), noun, verb, message)


class ZeroAmountTest(AdditionalTest):
Expand Down
43 changes: 22 additions & 21 deletions cove_360/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@


ADDITIONAL_CHECKS_RESULTS = [
({'heading': "1 grant does not have recipient organisation location information",
({'heading': "33% of grants do not have recipient organisation location information",
'message': ("Your data is missing information about the geographic location of recipient "
"organisations; either <span style=\"background-color: #E7EBE8\">Recipient Org:Postal Code</span> "
"or <span style=\"background-color: #E7EBE8\">Recipient Org:Location:Geographic Code</span> combined "
Expand All @@ -302,20 +302,21 @@
"allows it to be used in tools that visualise grants geographically.")},
['grants/0/recipientOrganization/0/id'],
[{'sheet': 'grants', 'letter': 'J', 'row_number': 2, 'header': 'Recipient Org:Identifier'}]),
({'heading': "2 grants contain text that looks like an email address",
({'heading': "67% of grants contain text that looks like an email address",
'message': ("Your data may contain an email address (or something that looks like one), "
"which can constitute personal data. The use and distribution of personal data "
"is restricted by the Data Protection Act. You should ensure that any personal "
"data is only included with the knowledge and consent of the person to whom it refers.")},
['grants/0/Grant type', 'grants/0/title'],
[{'sheet': 'grants', 'letter': 'G', 'row_number': 2, 'header': 'Grant type'},
{'sheet': 'grants', 'letter': 'O', 'row_number': 2, 'header': 'Title'}]),
({'heading': "1 grant does not contain any <span style=\"background-color: #E7EBE8\">Grant Programme</span> fields",
({'heading': ("33% of grants do not contain any <span style=\"background-color: #E7EBE8\">Grant Programme</span> "
"fields"),
'message': ("Providing <span style=\"background-color: #E7EBE8\">Grant Programme</span> data, if available, helps "
"users to better understand your data.")},
['grants/0/id'],
[{'sheet': 'grants', 'letter': 'A', 'row_number': 2, 'header': 'Identifier'}]),
({'heading': "1 grant does not contain any beneficiary location fields",
({'heading': "33% of grants do not contain any beneficiary location fields",
'message': ("Providing beneficiary data, if available, helps users to "
"understand which areas ultimately benefitted from the grant.")},
['grants/1/id'],
Expand All @@ -330,17 +331,17 @@
# "data as it cannot be inferred.")},
# ['grants/0/beneficiaryLocation'],
# [{'sheet': 'grants', 'letter': 'AA', 'row_number': 2, 'header': 'Beneficiary Location'}]),
({'heading': "1 grant has a title and a description that are the same",
({'heading': "33% of grants have a title and a description that are the same",
'message': ("Users may find that the data is less useful as they are unable to "
"discover more about the grants. Consider including a more detailed "
"description if you have one.")},
['grants/2/description'],
[{'sheet': 'grants', 'letter': 'Z', 'row_number': 4, 'header': 'Description'}]),
({'heading': "1 grant has a title longer than recommended",
({'heading': "33% of grants have a title longer than recommended",
'message': "Titles for grant activities should be under 140 characters long."},
['grants/1/title'],
[{'sheet': 'grants', 'letter': 'O', 'row_number': 3, 'header': 'Title'}]),
({'heading': "2 grants have funder or recipient organisation IDs that might not be valid",
({'heading': "67% of grants have funder or recipient organisation IDs that might not be valid",
'message': ("The IDs might not be valid for the registration agency that they refer to "
"- for example, a 'GB-CHC' ID that contains an invalid charity number. Common "
"causes of this are missing leading digits, typos or incorrect values being "
Expand All @@ -352,16 +353,16 @@


QUALITY_ACCURACY_CHECKS_RESULTS = [
({'heading': "1 grant has a value of £0",
({'heading': "33% of grants have a value of £0",
'message': ("It’s worth taking a look at these grants and deciding if "
"they should be published. It’s unusual to have grants of £0, but "
"there may be a reasonable explanation. Additional information "
"on why these grants are £0 might be useful to anyone using the data, "
"so consider adding an explanation to the description of the grant.")},
['grants/0/amountAwarded'],
[{'sheet': 'grants', 'letter': 'Q', 'row_number': 2, 'header': 'Amount Awarded'}]),
({'heading': ("1 grant has a <span style=\"background-color: #E7EBE8\">Funding Org:Identifier</span> that does "
"not draw from a recognised register."),
({'heading': ("33% of grants have a <span style=\"background-color: #E7EBE8\">Funding Org:Identifier</span> that "
"does not draw from a recognised register."),
'message': ("Using external identifiers (such as a charity or company number) helps "
"people using your data to match it up against other data - for example "
"to see who else has given grants to the same recipient, even if they’re "
Expand All @@ -370,8 +371,8 @@
"then you can ignore this notice.")},
['grants/0/fundingOrganization/0/id'],
[{'sheet': 'grants', 'letter': 'V', 'row_number': 2, 'header': 'Funding Org:Identifier'}]),
({'heading': ("1 grant has a <span style=\"background-color: #E7EBE8\">Recipient Org:Identifier</span> that does "
"not draw from a recognised register."),
({'heading': ("33% of grants have a <span style=\"background-color: #E7EBE8\">Recipient Org:Identifier</span> that "
"does not draw from a recognised register."),
'message': ("Using external identifiers (such as a charity or company number) helps "
"people using your data to match it up against other data - for example "
"to see who else has given grants to the same recipient, even if they’re "
Expand All @@ -380,14 +381,14 @@
"then you can ignore this notice.")},
['grants/1/recipientOrganization/0/id'],
[{'sheet': 'grants', 'letter': 'J', 'row_number': 3, 'header': 'Recipient Org:Identifier'}]),
({'heading': ("1 grant has a value provided in the "
({'heading': ("33% of grants have a value provided in the "
"<span style=\"background-color: #E7EBE8\">Recipient Org: Charity Number</span> column "
"that doesn’t look like a charity number"),
'message': ("Common causes of this are missing leading digits, typos or incorrect "
"values being entered into this field.")},
['grants/0/recipientOrganization/0/charityNumber'],
[{'sheet': 'grants', 'letter': 'M', 'row_number': 2, 'header': 'Recipient Org:Charity Number'}]),
({'heading': ("1 grant has a value provided in the "
({'heading': ("33% of grants have a value provided in the "
"<span style=\"background-color: #E7EBE8\">Recipient Org: Company Number</span> column "
"that doesn’t look like a company number"),
'message': ("Common causes of this are missing leading digits, typos or incorrect "
Expand All @@ -406,8 +407,8 @@
]

USEFULNESS_CHECKS_RESULTS = [
({'heading': ("1 grant has a <span style=\"background-color: #E7EBE8\">Recipient Org:Identifier</span> that starts "
"'360G-'"),
({'heading': ("33% of grants have a <span style=\"background-color: #E7EBE8\">Recipient Org:Identifier</span> that "
"starts '360G-'"),
'message': ("If the grant is to a recipient organisation that has an external "
"identifier (such as a charity or company number), then this should "
"be used instead. Using external identifiers helps people using your "
Expand All @@ -417,14 +418,14 @@
"ignore this notice.")},
['grants/0/recipientOrganization/0/id'],
[{'sheet': 'grants', 'letter': 'J', 'row_number': 2, 'header': 'Recipient Org:Identifier'}]),
({'heading': ("1 grant has a <span style=\"background-color: #E7EBE8\">Funding Org:Identifier</span> that starts "
"'360G-'"),
({'heading': ("33% of grants have a <span style=\"background-color: #E7EBE8\">Funding Org:Identifier</span> that "
"starts '360G-'"),
'message': ("If the grant is from a funding organisation that has an external identifier "
"(such as a charity or company number), then this should be used instead. "
"If no other identifier can be used, then you can ignore this notice.")},
['grants/1/fundingOrganization/0/id'],
[{'sheet': 'grants', 'letter': 'V', 'row_number': 3, 'header': 'Funding Org:Identifier'}]),
({'heading': ("1 grant does not have either a "
({'heading': ("33% of grants do not have either a "
"<span style=\"background-color: #E7EBE8\">Recipient Org:Company Number</span> or a "
"<span style=\"background-color: #E7EBE8\">Recipient Org:Charity Number</span>"),
'message': ("Providing one or both of these, if possible, makes it easier for users "
Expand All @@ -433,15 +434,15 @@
"Company or UK Charity numbers, then you can ignore this notice.")},
['grants/2/recipientOrganization/0/id'],
[{'sheet': 'grants', 'letter': 'J', 'row_number': 4, 'header': 'Recipient Org:Identifier'}]),
({'heading': "1 grant does not have <span style=\"background-color: #E7EBE8\">Last Modified</span> information",
({'heading': "33% of grants do not have <span style=\"background-color: #E7EBE8\">Last Modified</span> information",
'message': "<span style=\"background-color: #E7EBE8\">Last Modified</span> shows the date and time when "
"information about a grant was last updated in your file. Including this information allows data "
"users to see when changes have been made and reconcile differences between versions "
"of your data. Please note: this is the date when the data was modified in "
"your 360Giving file, rather than in any of your internal systems."},
['grants/1/id'],
[{'sheet': 'grants', 'letter': 'A', 'row_number': 3, 'header': 'Identifier'}]),
({'heading': "2 grants do not have <span style=\"background-color: #E7EBE8\">Data Source</span> information",
({'heading': "67% of grants do not have <span style=\"background-color: #E7EBE8\">Data Source</span> information",
'message': "<span style=\"background-color: #E7EBE8\">Data Source</span> informs users about where information "
"came from and is an important part of establishing trust in your data. This information should "
"be a web link pointing to the source of this data, which may be an original "
Expand Down
2 changes: 1 addition & 1 deletion cove_360/tests_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def test_error_modal(server_url, browser, httpserver, source_filename):
modal_additional_checks = browser.find_element_by_css_selector('.additional-checks-1')
assert "in" in modal_additional_checks.get_attribute("class").split()
modal_additional_checks_text = modal_additional_checks.text
assert "4 grants do not have recipient organisation location information" in modal_additional_checks_text
assert "100% of grants do not have recipient organisation location information" in modal_additional_checks_text
assert "grants/0/recipientOrganization/0/id" in modal_additional_checks_text
table_rows = browser.find_elements_by_css_selector('.additional-checks-1 tbody tr')
assert len(table_rows) == 4
Expand Down

0 comments on commit 0723d95

Please sign in to comment.