def build_str_gender_age_prc_sens_queries(audience_conf): if 'filtros' not in audience_conf: return '' filter_genero = audience_conf['filtros'].get('genero') filter_age = audience_conf['filtros'].get('idade') query = '' # We filter by gender only if it's available and it's not 2, that is, both genders if filter_genero and len(filter_genero) < 2: query += ' AND prsn_gender_code in {gendercode}' \ .format(gendercode=listdecode2str(gender_func, audience_conf['filtros']['genero'])) # We filter by age only if it's available and it's not 6, that is, all age ranges available if filter_age and len(filter_age) < 6: query += ' AND prsn_age_range_code in {agecode}' \ .format(agecode=numlist2str(audience_conf['filtros']['idade'])) if audience_conf['filtros'].get('sensibilidadePreco') != "0": query += ' AND prsn_price_sens_code in {pricecode}' \ .format(pricecode=listdecode2str(sens_func, [audience_conf['filtros']['sensibilidadePreco']])) # Important: Here we assume that sensibilidadePreco = 0 is the same as no filter at all regarding price sensibility #We filter if client agreed to receive push notifications if audience_conf['filtros'].get('metodo_envio') in [0, 1]: query += ' AND prsn_push_optin_flag = {0}'.format( audience_conf['filtros'].get('metodo_envio')) return query
def select_regions(state_region): # We filter by region only if it's available and it's not 27, that is, all regions with no exclusion if not state_region: return '' elif len(state_region) >= 27: return '' return " AND prsn_address_state_prov_code in {regions}".format( regions=listdecode2str(state_func, state_region))