diff --git a/coordinator/ProcessorSurveysWRT.py b/coordinator/ProcessorSurveysWRT.py index 12018382db477443b658351a9bfe1a5c780fea31..54446e4b281b71550d5a92e0bd5afe74930b6273 100644 --- a/coordinator/ProcessorSurveysWRT.py +++ b/coordinator/ProcessorSurveysWRT.py @@ -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: