Exemplo n.º 1
0
def graph2():
    global top_cities
    form = TenForm()
    weights = getitem(request.args, 'weights',
                      [-1, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 0.5, 1])
    print(weights)
    targets = [
        'gallup.median.income', 'gpd_obs', 'gdp_proj', 'digi_read',
        'digi_math', 'pisa_math', 'pisa_read', 'pisa_sci', 'top_mathers',
        'citi_score'
    ]

    df2 = pd.read_csv('static/Code_Worker_Quest.csv')

    # Set df index before calling norm_df
    df2 = df2.fillna(0)

    df2 = df2[df2['City.name'] != 0]
    # Call norm_df function from utilities
    dfline = utils.norm_df(df2, weights, targets)
    if request.method == 'POST' and form.validate():
        weights = []
        i = 0
        for field in form:
            if i != 0:
                weights.append(field.data)
            i = i + 1
        dfline = utils.norm_df(df2, weights, targets)
        #print(weights, "from form")

    dfline.set_index(['City.name'], inplace=True)
    dfline = dfline.sort_values('weight_score', axis=0, ascending=False)
    #print(df2[1:5].values)
    #, na_position='last')
    # Create new dataframe of five top cities
    top_cities = df2.iloc[:5, -11:]
    # top_cities = pd.DataFrame(df.iloc[:,[-11, -10,-9,-8,-7,-6,-5,-4,-3,-2,-1]])
    top_cities = top_cities.sort_values('weight_score',
                                        axis=0,
                                        ascending=False,
                                        na_position='last')
    #print(top_cities)

    if isinstance(weights, str) == True:
        print("oh no, a string")
        weights = [-1, 0.5, 0.5, 0.5, 1, 0.25, 0.25, 0.25, 0.25]

    return render_template('graph2.html',
                           form=form,
                           weights=weights,
                           tables=top_cities.to_html(classes='city'))
Exemplo n.º 2
0
def graph2():
    global top_cities
    form = TenForm()
    weights = getitem(request.args, 'weights', [-1,0.5,0.5,0.5,1,0.5,0.5,0.5,0.5,1])
    print(weights)
    targets = ['gallup.median.income', 'gpd_obs', 'gdp_proj', 'digi_read', 'digi_math', 'pisa_math', 'pisa_read', 'pisa_sci', 'top_mathers', 'citi_score']
    


    
    df2 = pd.read_csv('static/Code_Worker_Quest.csv')

    # Set df index before calling norm_df
    df2 = df2.fillna(0)

    df2 = df2[df2['City.name'] != 0]
    # Call norm_df function from utilities
    dfline = utils.norm_df(df2, weights, targets)
    if request.method == 'POST' and form.validate():
        weights = []
        i = 0
        for field in form:
            if i != 0:
                weights.append(field.data)
            i = i + 1
        dfline = utils.norm_df(df2, weights, targets)
        #print(weights, "from form")

    dfline.set_index(['City.name'], inplace = True)
    dfline = dfline.sort_values('weight_score', axis=0, ascending=False)
    #print(df2[1:5].values)
    #, na_position='last')
    # Create new dataframe of five top cities
    top_cities = df2.iloc[:5,-11:]
    # top_cities = pd.DataFrame(df.iloc[:,[-11, -10,-9,-8,-7,-6,-5,-4,-3,-2,-1]])
    top_cities = top_cities.sort_values('weight_score', axis=0, ascending=False, na_position='last')
    #print(top_cities)



    if isinstance(weights, str) == True:
        print("oh no, a string")
        weights = [-1,0.5,0.5,0.5,1,0.25,0.25,0.25,0.25]
    

    return render_template('graph2.html', form=form, weights=weights, tables=top_cities.to_html(classes='city'))
Exemplo n.º 3
0
def graph1():
    global dfworld
    form = NineForm()
    weights = getitem(request.args, 'weights',
                      list([-1, 0.5, 0.5, 0.5, 1, 0.25, 0.25, 0.25, 0.25]))
    if request.method == 'POST' and form.validate():
        weights = []
        i = 0
        for field in form:
            if i != 0:
                weights.append(field.data)
            i = i + 1
        print(weights, "from form")

    if isinstance(weights, str) == True:
        print("oh no, a string")
        weights = [-1, 0.5, 0.5, 0.5, 1, 0.25, 0.25, 0.25, 0.25]

    targets = [
        'income', 'gpd_obs', 'gdp_proj', 'digi_read', 'digi_math', 'pisa_math',
        'pisa_read', 'pisa_sci', 'top_mathers'
    ]
    factor_names = [
        'Gallup Median Wage', 'Observed GDP Growth',
        'Predicted GPD Growth (OPEC)', 'PISA Digital Literacy',
        'PISA Digital Math Ability', 'PISA Math scores', 'PISA Reading Scores',
        'PISA Science Scores', 'PISA Share of Top Math Performers'
    ]
    print(weights)
    print("length of weights", len(weights))
    #9 total weights for [income, gpd_obs, gdp_proj, digi_read, digi_math, pisa_math, pisa_read, pisa_sci, top_mathers]
    #session = requests.Session()
    #session.mount('http://', requests.adapters.HTTPAdapter(max_retries=3))

    # Raw data to Pandas dataframe
    df = pd.read_csv('static/Code_Worker_Quest.csv')

    df.set_index(['Country.Code'], inplace=True)
    df = df.fillna(0)
    df = df[df.index != '0']
    df = utils.norm_df(df, weights, targets)
    dfworld = df.sort_values('weight_score',
                             axis=0,
                             ascending=False,
                             na_position='last')
    top_countries = pd.DataFrame(df.groupby(df.index).first())
    top_countries = top_countries.sort_values('weight_score',
                                              axis=0,
                                              ascending=False,
                                              na_position='last')
    top_countries = top_countries.iloc[:10, [0, -1]]
    tchtml = top_countries.to_html(classes='country')
    return render_template('graph1.html',
                           form=form,
                           weights=weights,
                           tables=tchtml)
Exemplo n.º 4
0
def graph1():
    global dfworld
    form = NineForm()
    weights = getitem(request.args, 'weights', list([-1,0.5,0.5,0.5,1,0.25,0.25,0.25,0.25]))
    if request.method == 'POST' and form.validate():
        weights = []
        i = 0
        for field in form:
            if i != 0:
                weights.append(field.data)
            i = i + 1
        print(weights, "from form")

    if isinstance(weights, str) == True:
        print("oh no, a string")
        weights = [-1,0.5,0.5,0.5,1,0.25,0.25,0.25,0.25]

    targets = ['income', 'gpd_obs', 'gdp_proj', 'digi_read', 'digi_math', 'pisa_math', 'pisa_read', 'pisa_sci', 'top_mathers']
    factor_names = ['Gallup Median Wage', 'Observed GDP Growth', 'Predicted GPD Growth (OPEC)', 'PISA Digital Literacy', 'PISA Digital Math Ability', 'PISA Math scores', 'PISA Reading Scores', 'PISA Science Scores', 'PISA Share of Top Math Performers']
    print(weights)
    print("length of weights", len(weights))
    #9 total weights for [income, gpd_obs, gdp_proj, digi_read, digi_math, pisa_math, pisa_read, pisa_sci, top_mathers]
    #session = requests.Session()
    #session.mount('http://', requests.adapters.HTTPAdapter(max_retries=3))

    # Raw data to Pandas dataframe
    df = pd.read_csv('static/Code_Worker_Quest.csv')
    
    df.set_index(['Country.Code'], inplace = True)
    df = df.fillna(0)
    df = df[df.index != '0']
    df = utils.norm_df(df, weights, targets)
    dfworld = df.sort_values('weight_score', axis=0, ascending=False, na_position='last')
    top_countries = pd.DataFrame(df.groupby(df.index).first())
    top_countries = top_countries.sort_values('weight_score', axis=0, ascending=False, na_position='last')
    top_countries = top_countries.iloc[:10, [0, -1]]
    tchtml = top_countries.to_html(classes='country')
    return render_template('graph1.html', form=form, weights=weights, tables=tchtml)