Exemplo n.º 1
0
def data_sources():
    """ 
    Return a list of data sources
    """
    mancers = None
    if request.args.get('geo_type'):
        mancers = get_data_sources(request.args.get('geo_type'))
    else:
        mancers = get_data_sources()
    resp = make_response(json.dumps(mancers, cls=GeoTypeEncoder))
    resp.headers['Content-Type'] = 'application/json'
    return resp
Exemplo n.º 2
0
def data_sources():
    """ 
    Return a list of data sources
    """
    mancers = None
    if request.args.get('geo_type'):
        mancers = get_data_sources(request.args.get('geo_type'))
    else:
        mancers = get_data_sources()
    resp = make_response(json.dumps(mancers, cls=GeoTypeEncoder))
    resp.headers['Content-Type'] = 'application/json'
    return resp
Exemplo n.º 3
0
def select_geo():
    if not session.get('file'):
        return redirect(url_for('views.index'))
    context = {}
    if request.method == 'POST':
        inp = StringIO(session['file'])
        reader = UnicodeCSVReader(inp)
        header = reader.next()
        fields = {}
        valid = True
        geotype_val = None
        if not request.form:
            valid = False
            context['errors'] = [
                'Select a field that contains a geography type'
            ]
        else:
            geotypes = []
            indexes = []
            for k, v in request.form.items():
                if k.startswith("geotype"):
                    geotypes.append(v)
                    indexes.append(k.split('_')[1])
            if len(indexes) > 2:
                valid = False
                context['errors'] = [
                    'We can only merge geographic information from 2 columns'
                ]
            else:
                fields_key = ';'.join([header[int(i)] for i in indexes])
                geotype_val = ';'.join([g for g in geotypes])
                if not check_combos(geotype_val):
                    valid = False
                    types = [t.title() for t in geotype_val.split(';')]
                    context['errors'] = [
                        'The geographic combination of {0} and {1} does not work'
                        .format(*types)
                    ]
                else:
                    fields[fields_key] = {
                        'geo_type': geotype_val,
                        'column_index': ';'.join(indexes)
                    }

            # found_geo_type = get_geo_types(geo_type)[0]['info']
            # sample_list = session['sample_data'][index][2]
            # valid, message = found_geo_type.validate(sample_list)
            # context['errors'] = [message]
        if valid:
            try:
                geo_type = SENSICAL_TYPES[geotype_val]
            except KeyError:
                geo_type = geotype_val
            mancer_data, errors = get_data_sources(geo_type=geo_type)
            session['fields'] = fields
            session['mancer_data'] = mancer_data
            for error in errors:
                flash(error)
            return redirect(url_for('views.select_tables'))
    return render_template('select_geo.html', **context)
Exemplo n.º 4
0
def select_geo():
    if not session.get('file'):
        return redirect(url_for('views.index'))
    context = {}
    if request.method == 'POST':
        inp = StringIO(session['file'])
        reader = UnicodeCSVReader(inp)
        header = reader.next()
        fields = {}
        geo_type = None
        valid = True
        if not request.form:
            valid = False
            context['errors'] = ['Select a field that contains a geography type']
        if valid:
            for k,v in request.form.items():
                if k.startswith("geotype"):
                    geo_type = v
                    index = int(k.split('_')[1])
                    fields[header[index]] = {
                        'geo_type': v,
                        'column_index': index
                    }
            mancer_data = get_data_sources(geo_type)
            session.update({'fields': fields, 'mancer_data': mancer_data})
            return redirect(url_for('views.select_tables'))
    return render_template('select_geo.html', **context)
Exemplo n.º 5
0
def select_geo():
    if not session.get('file'):
        return redirect(url_for('views.index'))
    context = {}
    if request.method == 'POST':
        inp = StringIO(session['file'])
        reader = UnicodeCSVReader(inp)
        header = reader.next()
        fields = {}
        geo_type = None
        valid = True
        if not request.form:
            valid = False
            context['errors'] = [
                'Select a field that contains a geography type'
            ]
        if valid:
            for k, v in request.form.items():
                if k.startswith("geotype"):
                    geo_type = v
                    index = int(k.split('_')[1])
                    fields[header[index]] = {
                        'geo_type': v,
                        'column_index': index
                    }
            mancer_data = get_data_sources(geo_type)
            session.update({'fields': fields, 'mancer_data': mancer_data})
            return redirect(url_for('views.select_tables'))
    return render_template('select_geo.html', **context)
Exemplo n.º 6
0
def select_geo():
    if not session.get('file'):
        return redirect(url_for('views.index'))
    context = {}
    if request.method == 'POST':
        inp = StringIO(session['file'])
        reader = UnicodeCSVReader(inp)
        header = reader.next()
        fields = {}
        geo_type = None
        valid = True
        if not request.form:
            valid = False
            context['errors'] = ['Select a field that contains a geography type']
        else:
            for k,v in request.form.items():
                if k.startswith("geotype"):
                    geo_type = v
                    index = int(k.split('_')[1])
                    fields[header[index]] = {
                        'geo_type': v,
                        'column_index': index
                    }

            found_geo_type = get_geo_types(geo_type)[0]['info']
            sample_as_list = session['sample_data'][index][2].split(', ')
            valid = validate_geo_type(found_geo_type, sample_as_list)
            context['errors'] = ['The column you selected must be formatted like "%s" to match on %s geographies. Please pick another column or change the format of your data.' % (found_geo_type.formatting_example, found_geo_type.human_name)]
        if valid:
            mancer_data = get_data_sources(geo_type)
            session.update({'fields': fields, 'mancer_data': mancer_data})
            return redirect(url_for('views.select_tables'))
    return render_template('select_geo.html', **context)
Exemplo n.º 7
0
def select_geo():
    if not session.get('file'):
        return redirect(url_for('views.index'))
    context = {}
    if request.method == 'POST':
        inp = StringIO(session['file'])
        reader = UnicodeCSVReader(inp)
        header = reader.next()
        fields = {}
        valid = True
        geotype_val = None
        if not request.form:
            valid = False
            context['errors'] = ['Select a field that contains a geography type']
        else:
            geotypes = []
            indexes = []
            for k,v in request.form.items():
                if k.startswith("geotype"):
                    geotypes.append(v)
                    indexes.append(k.split('_')[1])
            if len(indexes) > 2:
                valid = False
                context['errors'] = ['We can only merge geographic information from 2 columns']
            else:
                fields_key = ';'.join([header[int(i)] for i in indexes])
                geotype_val = ';'.join([g for g in geotypes])
                if not check_combos(geotype_val):
                    valid = False
                    types = [t.title() for t in geotype_val.split(';')]
                    context['errors'] = ['The geographic combination of {0} and {1} does not work'.format(*types)]
                else:
                    fields[fields_key] = {
                        'geo_type': geotype_val,
                        'column_index': ';'.join(indexes)
                    }

            # found_geo_type = get_geo_types(geo_type)[0]['info']
            # sample_list = session['sample_data'][index][2]
            # valid, message = found_geo_type.validate(sample_list)
            # context['errors'] = [message]
        if valid:
            try:
                geo_type = SENSICAL_TYPES[geotype_val]
            except KeyError:
                geo_type = geotype_val
            mancer_data, errors = get_data_sources(geo_type=geo_type)
            session['fields'] = fields
            session['mancer_data'] = mancer_data
            for error in errors:
                flash(error)
            return redirect(url_for('views.select_tables'))
    return render_template('select_geo.html', **context)
Exemplo n.º 8
0
def select_geo():
    if not session.get('file'):
        return redirect(url_for('views.index'))
    context = {}
    if request.method == 'POST':
        inp = StringIO(session['file'])
        reader = UnicodeCSVReader(inp)
        header = reader.next()
        fields = {}
        geo_type = None
        valid = True
        if not request.form:
            valid = False
            context['errors'] = [
                'Select a field that contains a geography type'
            ]
        else:
            for k, v in request.form.items():
                if k.startswith("geotype"):
                    geo_type = v
                    index = int(k.split('_')[1])
                    fields[header[index]] = {
                        'geo_type': v,
                        'column_index': index
                    }

            found_geo_type = get_geo_types(geo_type)[0]['info']
            sample_as_list = session['sample_data'][index][2].split(', ')
            valid = validate_geo_type(found_geo_type, sample_as_list)
            context['errors'] = [
                'The column you selected must be formatted like "%s" to match on %s geographies. Please pick another column or change the format of your data.'
                %
                (found_geo_type.formatting_example, found_geo_type.human_name)
            ]
        if valid:
            mancer_data = get_data_sources(geo_type)
            session.update({'fields': fields, 'mancer_data': mancer_data})
            return redirect(url_for('views.select_tables'))
    return render_template('select_geo.html', **context)
Exemplo n.º 9
0
def data_sources():
    data_sources, errors = get_data_sources()
    for error in errors:
        flash(error)
    return render_template('data-sources.html', data_sources=data_sources)
Exemplo n.º 10
0
def data_sources():
    data_sources, errors = get_data_sources()
    for error in errors:
        flash(error)
    return render_template('data-sources.html', data_sources=data_sources)
Exemplo n.º 11
0
def data_sources():
    data_sources = get_data_sources()
    return render_template('data-sources.html', data_sources=data_sources)
Exemplo n.º 12
0
def data_sources():
    data_sources = get_data_sources()
    return render_template('data-sources.html', data_sources=data_sources)