FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit ee763475 authored by Dr T. Mona's avatar Dr T. Mona
Browse files

feat: converting countries short name to full name.

parent b5dcf0f0
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,27 @@ from ProcessorUtils import (
logger = logging.getLogger('Processor.Surveys.WRT')
add_filters_to_sublogger(logger)
# Downloads of the WRT based on the ODK form reports country descriptions as two letter codes.
# The reason is unclear, as viewing online shows full country names. To be
# consistent across all form types, this function is available for translating
# two letter codes to full string names.
# Only some have these have been checked explicitly against downloaded surveys.
# Assuming the code is based on ISO 3166-1 alpha-2
COUNTRY_ABBREVIATIONS_DICT = {
'AF' : 'Afghanistan',
'BD' : 'Bangladesh',
'BT' : 'Bhutan',
'ET' : 'Ethiopia',
'IN' : 'India',
'KE' : 'Kenya',
'NP' : 'Nepal',
'PK' : 'Pakistan',
'TZ' : 'Tanzania',
'UG' : 'Uganda',
'ZM' : 'Zambia',
'ZW' : 'Zimbabwe',
}
# Cases to convert WRT categories to expected short name category or value
cases_incident = {
'':'none',
......@@ -40,12 +61,12 @@ cases_severity = {
def get_from_WRT(form_credentials: dict, startDate: str, endDate: str):
'''Make the HTTP request, then checking the status code.'''
url = f"{form_credentials['url']}WheatRustAPI/api/Survey/GetAll"
#url = f"{form_credentials['url']}WheatRustAPI/api/Survey/GetByPublishedLevel"
#url = f"{form_credentials['url']}WheatRustAPI/api/Survey/GetAll"
url = f"{form_credentials['url']}WheatRustAPI/api/Survey/GetByPublishedLevel"
url += '?strStopDate=' + endDate
url += '&strStartDate=' + startDate
url += '&strArrayCountryID='+ form_credentials['countryID']
#url += '&strArrayPublishedLevel=Unpubl'
url += '&strArrayPublishedLevel=' + form_credentials['publishedLevel']
# set up http session
session = requests.Session()
......@@ -177,7 +198,7 @@ def get_WRT_form_as_csv(form_credentials: dict, jobPath: str, config: dict, stat
"ObservationID" : 'KEY',
"OriginalID" : 'None',
"Origin" : "Origin",
"Country" : 'surveyor_infromation-country',
"Country" : ('parse_cases',(('name_out','surveyor_infromation-country'),('cases', COUNTRY_ABBREVIATIONS_DICT))),
"Latitude" : 'survey_infromation-location-Latitude',
"Longitude" : 'survey_infromation-location-Longitude',
"FieldArea" : 'site_information-field_area',
......@@ -226,9 +247,9 @@ def get_WRT_form_as_csv(form_credentials: dict, jobPath: str, config: dict, stat
download_success = False
# define filenames
csv_filename = f"SurveyData_raw.csv"
csv_filename = f"SurveyData_raw_{form_credentials['form_name']}.csv"
csv_processed_filename = f"SurveyDataProcessed.csv"
csv_processed_filename = f"SurveyDataProcessed_{form_credentials['form_name']}.csv"
csv_processed_path = f"{output_path}/{csv_processed_filename}"
if download_success and not skip_download:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment