Exemple #1
0
def Query():

    Name = None
    Country = ''
    capital = ''
    df = pd.read_csv(
        path.join(path.dirname(__file__), 'static\\Data\\capitals.csv'))
    df = df.set_index('Country')

    form = QueryFormStructure(request.form)

    if (request.method == 'POST'):
        name = form.name.data
        Country = name
        if (name in df.index):
            capital = df.loc[name, 'Capital']
        else:
            capital = name + ', no such country'
        form.name.data = ''

    df = pd.read_csv(
        path.join(path.dirname(__file__), 'static\\Data\\users.csv'))

    raw_data_table = df.to_html(classes='table table-hover')

    return render_template(
        'Query.html',
        form=form,
        name=capital,
        Country=Country,
        raw_data_table=raw_data_table,
        title='Query by the user',
        year=datetime.now().year,
        message='This page will use the web forms to get user input')
def Query():

    AverageWage_table = ''
    fig_image = ''
    df_avg = Get_NormalizedAverageWageDataset()

    form = QueryFormStructure(request.form)

    #set default values for time to avoid errors
    #form.start_date.data = df_avg.TIME.min()
    #form.end_date.data = df_avg.TIME.max()

    #Set the list of countries to choose from
    form.countries.choices = get_countries_choices()

    if (request.method == 'POST'):

        ##query user parameters
        countries = form.countries.data
        start_date = form.start_date.data
        end_date = form.end_date.data

        fig = plt.figure()

        for country in countries:
            #Filter only the requested countries
            df_avg_countries = df_avg.loc[country]
            # Filter only the requested Dates
            df_avg_dates = df_avg_countries.loc[lambda df:
                                                (df['TIME'] >= start_date) &
                                                (df['TIME'] <= end_date)]
            # adds plot object for requested country in countries
            plt.plot('TIME', 'Value', data=df_avg_dates, label=country)

        #gives color legend
        plt.legend(loc='best')
        fig_image = plot_to_img(fig)

    return render_template(
        'query.html',
        form=form,
        raw_data_table=AverageWage_table,
        fig_image=fig_image,
        title='User Data Query',
        year=datetime.now().year,
        message='Please enter the parameters you choose to analyze the database'
    )
Exemple #3
0
def Query():
        
        form = QueryFormStructure(request.form) #פקודה האומרת לתוכנה לקבל מהמשתמש נתונים
        chart = '' #מגדיר טבלה ריקה

        df = pd.read_csv(path.join(path.dirname(__file__), 'static/data/Cscore.csv')) # קורא את הקובץ עם הציון
        form.Countries.choices = get_country_choices() #מגדיר לתוכנה אפשרויות למשתנים
        country_list = form.Countries.data #נותן את הרשימה למשתמש

        
        if (request.method == 'POST'):
            df = df[['Country', 'Score']] #מוריד את כל שאר העמודות
            #df = df.set_index('Country') #נותן אינדקס לעמודה

            for country in country_list:
                Countries = form.Countries.data
                df2 = df[df['Country'].isin (Countries)]
                df2 = df2.set_index('Country')
                #df[country] = df2['Score']


            #יוצר גרף
            fig = plt.figure()
            ax = fig.add_subplot(111)
            df2.plot(ax = ax , kind = 'bar')
            chart = plot_to_img(fig)


        
        #מחזיר למשתמש גרף
        return render_template(
        'query.html', 
         form = form,
         chart = chart,
         title='Query by the user',
         year=datetime.now().year,
         message='This page will use the web forms to get user input'
                    )
def Query():
    geolocator = Nominatim(user_agent="final data science project")

    airbnbMap = 'static/pics/airbnbMap.PNG'
    crimeMap = 'static/pics/crimeRatesMap.PNG'
    partyMap = 'static/pics/partyMap.PNG'

    Name = None
    Country = ''
    capital = ''
    dr = pd.read_csv(
        path.join(path.dirname(__file__), 'static/Data/nyc-rolling-sales.csv'))
    rollingSalesAdresses = dr['ADDRESS']

    def findLongLat(address):
        adress = geolocator.geocode(address)
        return [adress.latitude, adress.longitude]

    def removeComma(string):
        if string.find(',') < 0:
            return string
        else:
            return string[0:string.find(',')]

    def findRollingSales(address):
        numSales = 0
        for x in range(0, rollingSalesAdresses.size):
            if removeComma(str(rollingSalesAdresses[x])).replace(
                    ' ', '').lower() == address.replace(' ', '').lower():
                numSales = numSales + 1
        return numSales

    raw_data_table = dr.to_html(classes='table table-hover',
                                max_rows=10,
                                max_cols=5)

    form = QueryFormStructure(request.form)

    #_________________________________________
    if (request.method == 'POST'):
        name = form.name.data
        Country = name
        if (findRollingSales(name) > 0):
            capital = str(findRollingSales(name))
            raw_data_table = ""
        else:
            capital = str(findRollingSales(name))
        form.name.data = ''

        ydata = findLongLat(name + " NYC")[1]
        xdata = findLongLat(name + " NYC")[0]

        airbnbMap = plt.imread(path.join(path.dirname(__file__), airbnbMap))

        fig7 = plt.figure()
        qAirbnb = fig7.add_subplot(111)
        qAirbnb.imshow(airbnbMap,
                       extent=[
                           40.499790000000004, 40.913059999999994,
                           -74.24441999999999, -73.71299
                       ])
        qAirbnb.scatter(xdata, ydata, 10, color='red')
        airbnbMap = plot_to_img(fig7)

        crimeMap = plt.imread(path.join(path.dirname(__file__), crimeMap))

        fig8 = plt.figure()
        qCrime = fig8.add_subplot(111)
        qCrime.imshow(crimeMap,
                      extent=[
                          40.499790000000004, 40.913059999999994,
                          -74.24441999999999, -73.71299
                      ])
        qCrime.scatter(xdata, ydata, 10, color='red')
        crimeMap = plot_to_img(fig8)

        partyMap = plt.imread(path.join(path.dirname(__file__), partyMap))

        fig9 = plt.figure()
        qParty = fig9.add_subplot(111)
        qParty.imshow(partyMap,
                      extent=[
                          40.499790000000004, 40.913059999999994,
                          -74.24441999999999, -73.71299
                      ])
        qParty.scatter(xdata, ydata, 10, color='red')
        partyMap = plot_to_img(fig9)

    return render_template(
        'Query.html',
        qAirbnb=airbnbMap,
        qCrime=crimeMap,
        qParty=partyMap,
        form=form,
        name=capital,
        Country=Country,
        raw_data_table=raw_data_table,
        title='Query:',
        year=datetime.now().year,
        message=
        'Type in an address in new york to see how many rolling sales were in that address during 2016 and the long and lat coordinates'
    )