def etl_web_data(ts):
    ''' Take the Typeform API and ETL it to a common
    standard we can do dashboard stats for.

    Returns a list of objects, each object being
    a survey.
    '''
    data = []
    json = call_web(ts)

    def tf(str):
        return current_app.config.get(str)

    for resp in json['responses']:
        answers_arr = resp['answers']

        obj = {'method': 'web'}
        if "English" in answers_arr[tf('LANG_EN')]:
            obj['lang'] = 'en'
        else:
            obj['lang'] = 'es'

        obj['source_id'] = 'WEB-' + resp['token']

        temp = resp['metadata']['date_submit']
        obj['date_submitted'] = date_to_db(temp)

        obj['get_done'] = fill_values(answers_arr, tf('GETDONE_EN'), tf('GETDONE_ES'))
        obj['rating'] = int(fill_values(answers_arr, tf('OPINION_EN'), tf('OPINION_ES')))

        obj['follow_up'] = fill_values(answers_arr, tf('FOLLOWUP_EN'), tf('FOLLOWUP_ES'))
        obj['contact'] = fill_values(answers_arr, tf('CONTACT_EN'), tf('CONTACT_ES'))
        obj['more_comments'] = fill_values(answers_arr, tf('COMMENTS_EN'), tf('COMMENTS_ES'))
        obj['role'] = ROLES[
            fill_values(
                answers_arr,
                tf('ROLE_EN'),
                tf('ROLE_ES'))]

        try:
            obj['permit_type'] = PERMIT_TYPE[
                fill_values(
                    answers_arr,
                    tf('TYPE_EN'),
                    tf('TYPE_ES'))]
        except KeyError:
            obj['permit_type'] = None

        data.append(obj)
    # print data
    return data
def etl_web_data(ts):
    ''' Take the Typeform API and ETL it to a common
    standard we can do dashboard stats for.

    Returns a list of objects, each object being
    a survey.
    '''
    data = []
    json = call_web(ts)

    def tf(str):
        return current_app.config.get(str)

    for resp in json['responses']:
        answers_arr = resp['answers']

        obj = {'method': 'web'}
        if "English" in answers_arr[tf('LANG_EN')]:
            obj['lang'] = 'en'
        else:
            obj['lang'] = 'es'

        obj['source_id'] = 'WEB-' + resp['token']

        temp = resp['metadata']['date_submit']
        obj['date_submitted'] = date_to_db(temp)

        obj['get_done'] = fill_values(answers_arr, tf('GETDONE_EN'),
                                      tf('GETDONE_ES'))
        obj['rating'] = int(
            fill_values(answers_arr, tf('OPINION_EN'), tf('OPINION_ES')))

        obj['follow_up'] = fill_values(answers_arr, tf('FOLLOWUP_EN'),
                                       tf('FOLLOWUP_ES'))
        obj['contact'] = fill_values(answers_arr, tf('CONTACT_EN'),
                                     tf('CONTACT_ES'))
        obj['more_comments'] = fill_values(answers_arr, tf('COMMENTS_EN'),
                                           tf('COMMENTS_ES'))
        obj['role'] = ROLES[fill_values(answers_arr, tf('ROLE_EN'),
                                        tf('ROLE_ES'))]

        try:
            obj['permit_type'] = PERMIT_TYPE[fill_values(
                answers_arr, tf('TYPE_EN'), tf('TYPE_ES'))]
        except KeyError:
            obj['permit_type'] = None

        data.append(obj)
    # print data
    return data
Esempio n. 3
0
def etl_web_data(ts):
    ''' Take the Typeform API and ETL it to a common
    standard we can do dashboard stats for.

    Returns a list of objects, each object being
    a survey.
    '''
    data = []
    json = call_web(ts)

    for resp in json['responses']:
        answers_arr = resp['answers']

        obj = {'method': 'web'}
        if "English" in answers_arr[TF['LANG_EN']]:
            obj['lang'] = 'en'
        else:
            obj['lang'] = 'es'

        obj['source_id'] = 'WEB-' + resp['token']

        temp = resp['metadata']['date_submit']
        obj['date_submitted'] = date_to_db(temp)

        obj['get_done'] = fill_values(answers_arr, TF['GETDONE_EN'],
                                      TF['GETDONE_ES'])
        obj['rating'] = int(
            fill_values(answers_arr, TF['OPINION_EN'], TF['OPINION_ES']))
        obj['improvement'] = fill_values(answers_arr, TF['IMPROVE_EN'],
                                         TF['IMPROVE_ES'])
        obj['best_other'] = fill_values(answers_arr, TF['BEST_OTHER_EN'],
                                        TF['BEST_OTHER_ES'])
        obj['worst_other'] = fill_values(answers_arr, TF['WORST_OTHER_EN'],
                                         TF['WORST_OTHER_ES'])
        obj['follow_up'] = fill_values(answers_arr, TF['FOLLOWUP_EN'],
                                       TF['FOLLOWUP_ES'])
        obj['contact'] = fill_values(answers_arr, TF['CONTACT_EN'],
                                     TF['CONTACT_ES'])
        obj['more_comments'] = fill_values(answers_arr, TF['COMMENTS_EN'],
                                           TF['COMMENTS_ES'])
        obj['role'] = ROLES[fill_values(answers_arr, TF['ROLE_EN'],
                                        TF['ROLE_ES'])]
        try:
            obj['purpose'] = PURPOSE[fill_values(answers_arr, TF['PURP_EN'],
                                                 TF['PURP_ES'])]
        except KeyError:
            # None. Set to 6 which is "OTHER"
            obj['purpose'] = 6

        obj['purpose_other'] = fill_values(answers_arr, TF['PURP_OTHER_EN'],
                                           TF['PURP_OTHER_ES'])

        try:
            obj['best'] = BEST[fill_values(answers_arr, TF['BEST_EN'],
                                           TF['BEST_ES'])]
        except KeyError:
            obj['best'] = None

        try:
            obj['worst'] = WORST[fill_values(answers_arr, TF['WORST_EN'],
                                             TF['WORST_ES'])]
        except KeyError:
            obj['worst'] = None

        try:
            obj['route'] = ROUTES[fill_values(answers_arr, TF['ROUTE_EN'],
                                              TF['ROUTE_ES'])]
        except KeyError:
            obj['route'] = None

        data.append(obj)
    # print data
    return data
Esempio n. 4
0
def etl_web_data(ts):
    ''' Take the Typeform API and ETL it to a common
    standard we can do dashboard stats for.

    Returns a list of objects, each object being
    a survey.
    '''
    data = []
    json = call_web(ts)

    for resp in json['responses']:
        answers_arr = resp['answers']

        obj = {'method': 'web'}
        if "English" in answers_arr[TF['LANG_EN']]:
            obj['lang'] = 'en'
        else:
            obj['lang'] = 'es'

        obj['source_id'] = 'WEB-' + resp['id']

        temp = resp['metadata']['date_submit']
        obj['date_submitted'] = date_to_db(temp)

        obj['get_done'] = fill_values(answers_arr, TF['GETDONE_EN'], TF['GETDONE_ES'])
        obj['rating'] = int(fill_values(answers_arr, TF['OPINION_EN'], TF['OPINION_ES']))
        obj['improvement'] = fill_values(answers_arr, TF['IMPROVE_EN'], TF['IMPROVE_ES'])
        obj['best_other'] = fill_values(answers_arr, TF['BEST_OTHER_EN'], TF['BEST_OTHER_ES'])
        obj['worst_other'] = fill_values(
            answers_arr,
            TF['WORST_OTHER_EN'],
            TF['WORST_OTHER_ES'])
        obj['follow_up'] = fill_values(answers_arr, TF['FOLLOWUP_EN'], TF['FOLLOWUP_ES'])
        obj['contact'] = fill_values(answers_arr, TF['CONTACT_EN'], TF['CONTACT_ES'])
        obj['more_comments'] = fill_values(answers_arr, TF['COMMENTS_EN'], TF['COMMENTS_ES'])
        obj['role'] = ROLES[
            fill_values(
                answers_arr,
                TF['ROLE_EN'],
                TF['ROLE_ES'])]
        try:
            obj['purpose'] = PURPOSE[
                fill_values(
                    answers_arr,
                    TF['PURP_EN'],
                    TF['PURP_ES'])]
        except KeyError:
            # None. Set to 6 which is "OTHER"
            obj['purpose'] = 6

        obj['purpose_other'] = fill_values(
            answers_arr,
            TF['PURP_OTHER_EN'],
            TF['PURP_OTHER_ES'])

        try:
            obj['best'] = BEST[
                fill_values(
                    answers_arr,
                    TF['BEST_EN'],
                    TF['BEST_ES'])]
        except KeyError:
            obj['best'] = None

        try:
            obj['worst'] = WORST[
                fill_values(
                    answers_arr,
                    TF['WORST_EN'],
                    TF['WORST_ES'])]
        except KeyError:
            obj['worst'] = None

        try:
            obj['route'] = ROUTES[
                fill_values(
                    answers_arr,
                    TF['ROUTE_EN'],
                    TF['ROUTE_ES'])]
        except KeyError:
            obj['route'] = None

        data.append(obj)
    # print data
    return data