예제 #1
0
def grow():
    df = data_auto()
    df['trade_year'] = df['tradeTime'].astype(str).str[0:4]
    df_year = df.groupby('trade_year').totalPrice.mean()
    fig = px.line(df_year, x=df_year.index, y=df_year.values)
    fig_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
    return fig_json
예제 #2
0
def distribution_structure():
    df = data_auto()
    fig = px.box(df,
                 x='buildingStructure',
                 y="totalPrice",
                 color='buildingStructure')
    fig_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
    return fig_json
예제 #3
0
def distribution_renovation():
    df = data_auto()
    fig = px.box(df,
                 x='renovationCondition',
                 y="totalPrice",
                 color='renovationCondition')
    fig_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
    return fig_json
예제 #4
0
def contime():
    df = data_auto()
    fig = px.box(df,
                 x='constructionTime',
                 y="totalPrice",
                 color='constructionTime')
    fig_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
    return fig_json
예제 #5
0
def typebuildtwo():
    df = data_auto()
    for dst in df['district'].unique():
        fig = px.pie(df,
                     values=df[df['district'] ==
                               dst]['buildingType'].value_counts().values,
                     names=df[df['district'] == dst]
                     ['buildingType'].value_counts().index,
                     color_discrete_sequence=px.colors.sequential.RdBu,
                     title=dst)
        fig_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
        return fig_json
예제 #6
0
def typebuild():
    #jumlah bangunan per district
    df = data_auto()
    diistrict = []
    jml_diistrict = []
    for i in df['district'].unique():
        diistrict.append(i)
        jml_diistrict.append(len(df[df['district'] == i]['buildingType']))
    btdis = pd.DataFrame({'district': diistrict, 'nofBuilding': jml_diistrict})
    btdis.sort_values(by='nofBuilding', inplace=True)
    fig = px.bar(btdis,
                 x='district',
                 y='nofBuilding',
                 height=400,
                 color='district')
    fig_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
    return fig_json
예제 #7
0
def district():
    df = data_auto()
    c_district = []
    jml_cid = []
    for i in df['district'].unique():
        c_district.append(i)
        jml_cid.append(len(df[df['district'] == i]['Cid'].unique()))
    dfdist = pd.DataFrame({'district': c_district, 'nofRegions': jml_cid})
    #sort
    dfdist.sort_values(by=['nofRegions'], inplace=True)
    #graph
    fig = px.bar(dfdist,
                 x='district',
                 y='nofRegions',
                 height=400,
                 color='district')
    fig_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
    return fig_json
예제 #8
0
def population():
    df = data_auto()
    uniqueA = []
    uniqueB = []
    uniqueC = []
    uniqueD = []
    uniqueE = []
    uniqueF = []
    uniqueG = []
    uniqueH = []
    uniqueI = []
    uniqueJ = []
    uniqueK = []
    uniqueL = []
    uniqueM = []

    for a in df[df['district'] == 'A']['Cid'].unique():
        uniqueA.append(a)
    for b in df[df['district'] == 'B']['Cid'].unique():
        uniqueB.append(b)
    for c in df[df['district'] == 'C']['Cid'].unique():
        uniqueC.append(c)
    for d in df[df['district'] == 'D']['Cid'].unique():
        uniqueD.append(d)
    for e in df[df['district'] == 'E']['Cid'].unique():
        uniqueE.append(e)
    for f in df[df['district'] == 'F']['Cid'].unique():
        uniqueF.append(f)
    for g in df[df['district'] == 'G']['Cid'].unique():
        uniqueG.append(g)
    for h in df[df['district'] == 'H']['Cid'].unique():
        uniqueH.append(h)
    for i in df[df['district'] == 'I']['Cid'].unique():
        uniqueI.append(i)
    for j in df[df['district'] == 'J']['Cid'].unique():
        uniqueJ.append(j)
    for k in df[df['district'] == 'K']['Cid'].unique():
        uniqueK.append(k)
    for l in df[df['district'] == 'L']['Cid'].unique():
        uniqueL.append(l)
    for m in df[df['district'] == 'M']['Cid'].unique():
        uniqueM.append(m)

    populasiA = []
    populasiB = []
    populasiC = []
    populasiD = []
    populasiE = []
    populasiF = []
    populasiG = []
    populasiH = []
    populasiI = []
    populasiJ = []
    populasiK = []
    populasiL = []
    populasiM = []

    for a in uniqueA:
        x = df[df['Cid'] == a]['communityAverage'].values[:1][0]
        populasiA.append(x)

    for b in uniqueB:
        x = df[df['Cid'] == b]['communityAverage'].values[:1][0]
        populasiB.append(x)

    for c in uniqueC:
        x = df[df['Cid'] == c]['communityAverage'].values[:1][0]
        populasiC.append(x)

    for d in uniqueD:
        x = df[df['Cid'] == d]['communityAverage'].values[:1][0]
        populasiD.append(x)

    for e in uniqueE:
        x = df[df['Cid'] == e]['communityAverage'].values[:1][0]
        populasiE.append(x)

    for f in uniqueF:
        x = df[df['Cid'] == f]['communityAverage'].values[:1][0]
        populasiF.append(x)

    for g in uniqueG:
        x = df[df['Cid'] == g]['communityAverage'].values[:1][0]
        populasiG.append(x)

    for h in uniqueH:
        x = df[df['Cid'] == h]['communityAverage'].values[:1][0]
        populasiH.append(x)

    for i in uniqueI:
        x = df[df['Cid'] == i]['communityAverage'].values[:1][0]
        populasiI.append(x)

    for j in uniqueJ:
        x = df[df['Cid'] == j]['communityAverage'].values[:1][0]
        populasiJ.append(x)

    for k in uniqueK:
        x = df[df['Cid'] == k]['communityAverage'].values[:1][0]
        populasiK.append(x)

    for l in uniqueL:
        x = df[df['Cid'] == l]['communityAverage'].values[:1][0]
        populasiL.append(x)

    for m in uniqueM:
        x = df[df['Cid'] == m]['communityAverage'].values[:1][0]
        populasiM.append(x)

    totpopulasiA = 0
    totpopulasiB = 0
    totpopulasiC = 0
    totpopulasiD = 0
    totpopulasiE = 0
    totpopulasiF = 0
    totpopulasiG = 0
    totpopulasiH = 0
    totpopulasiI = 0
    totpopulasiJ = 0
    totpopulasiK = 0
    totpopulasiL = 0
    totpopulasiM = 0

    for i in populasiA:
        totpopulasiA = totpopulasiA + i

    for i in populasiB:
        totpopulasiB = totpopulasiB + i

    for i in populasiC:
        totpopulasiC = totpopulasiC + i

    for i in populasiD:
        totpopulasiD = totpopulasiD + i

    for i in populasiE:
        totpopulasiE = totpopulasiE + i

    for i in populasiF:
        totpopulasiF = totpopulasiF + i

    for i in populasiG:
        totpopulasiG = totpopulasiG + i

    for i in populasiH:
        totpopulasiH = totpopulasiH + i

    for i in populasiI:
        totpopulasiI = totpopulasiI + i

    for i in populasiJ:
        totpopulasiJ = totpopulasiJ + i

    for i in populasiK:
        totpopulasiK = totpopulasiK + i

    for i in populasiL:
        totpopulasiL = totpopulasiL + i

    for i in populasiM:
        totpopulasiM = totpopulasiM + i

    populasii = pd.DataFrame({
        'distrik':
        ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'],
        'totpopulasi': [
            totpopulasiA, totpopulasiB, totpopulasiC, totpopulasiD,
            totpopulasiE, totpopulasiF, totpopulasiG, totpopulasiH,
            totpopulasiI, totpopulasiJ, totpopulasiK, totpopulasiL,
            totpopulasiM
        ]
    })
    populasii.sort_values(by=['totpopulasi'], inplace=True)
    fig = px.bar(populasii,
                 x='distrik',
                 y='totpopulasi',
                 height=400,
                 title='Populasi per Distrik',
                 color='distrik')
    fig_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
    return fig_json
예제 #9
0
def elevato():
    df = data_auto()
    fig = px.box(df, x='elevator', y="totalPrice", color='elevator')
    fig_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
    return fig_json
예제 #10
0
def distribution_district():
    df = data_auto()
    fig = px.box(df, x="district", y="totalPrice", color='district')
    fig_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
    return fig_json
예제 #11
0
def index():
    df = data_auto()

    dfA = df[df['district'] == 'A']
    dfB = df[df['district'] == 'B']
    dfC = df[df['district'] == 'C']
    dfD = df[df['district'] == 'D']
    dfE = df[df['district'] == 'E']
    dfF = df[df['district'] == 'F']
    dfG = df[df['district'] == 'G']
    dfH = df[df['district'] == 'H']
    dfI = df[df['district'] == 'I']
    dfJ = df[df['district'] == 'J']
    dfK = df[df['district'] == 'K']
    dfL = df[df['district'] == 'L']
    dfM = df[df['district'] == 'M']

    list_lat_long = []
    for index, value in dfA.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_long.append(temp)

    list_lat_longB = []
    for index, value in dfB.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longB.append(temp)

    list_lat_longC = []
    for index, value in dfC.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longC.append(temp)

    list_lat_longD = []
    for index, value in dfD.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longD.append(temp)

    list_lat_longE = []
    for index, value in dfE.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longE.append(temp)

    list_lat_longF = []
    for index, value in dfF.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longF.append(temp)

    list_lat_longG = []
    for index, value in dfG.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longG.append(temp)

    list_lat_longH = []
    for index, value in dfH.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longH.append(temp)

    list_lat_longI = []
    for index, value in dfI.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longI.append(temp)

    list_lat_longJ = []
    for index, value in dfJ.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longJ.append(temp)

    list_lat_longK = []
    for index, value in dfK.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longK.append(temp)

    list_lat_longL = []
    for index, value in dfL.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longL.append(temp)

    list_lat_longM = []
    for index, value in dfM.iterrows():
        temp = [value['Lat'], value['Lng']]
        list_lat_longM.append(temp)

    mapp = folium.Map(
        location=[39.9042, 116.4074],
        zoom_start=12,
    )
    itr = 100
    for item in range(itr):
        folium.Marker(location=list_lat_long[item],
                      popup=str(dfA['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfA['district'].values[item]) + '<hr></hr>' +
                      str(dfA['Cid'].values[item]) + '<hr></hr>' +
                      str(dfA['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfA['url'].values[item]),
                      icon=folium.Icon(color='red', icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longB[item],
                      popup=str(dfB['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfB['district'].values[item]) + '<hr></hr>' +
                      str(dfB['Cid'].values[item]) + '<hr></hr>' +
                      str(dfB['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfB['url'].values[item]),
                      icon=folium.Icon(color='blue', icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(len(list_lat_longC)):
        folium.Marker(location=list_lat_longC[item],
                      popup=str(dfC['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfC['district'].values[item]) + '<hr></hr>' +
                      str(dfC['Cid'].values[item]) + '<hr></hr>' +
                      str(dfC['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfC['url'].values[item]),
                      icon=folium.Icon(color='green', icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longD[item],
                      popup=str(dfD['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfD['district'].values[item]) + '<hr></hr>' +
                      str(dfD['Cid'].values[item]) + '<hr></hr>' +
                      str(dfD['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfD['url'].values[item]),
                      icon=folium.Icon(color='purple',
                                       icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longE[item],
                      popup=str(dfE['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfE['district'].values[item]) + '<hr></hr>' +
                      str(dfE['Cid'].values[item]) + '<hr></hr>' +
                      str(dfE['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfE['url'].values[item]),
                      icon=folium.Icon(color='orange',
                                       icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longF[item],
                      popup=str(dfF['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfF['district'].values[item]) + '<hr></hr>' +
                      str(dfF['Cid'].values[item]) + '<hr></hr>' +
                      str(dfF['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfF['url'].values[item]),
                      icon=folium.Icon(color='beige', icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longG[item],
                      popup=str(dfG['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfG['district'].values[item]) + '<hr></hr>' +
                      str(dfG['Cid'].values[item]) + '<hr></hr>' +
                      str(dfG['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfG['url'].values[item]),
                      icon=folium.Icon(color='darkpurple',
                                       icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longH[item],
                      popup=str(dfH['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfH['district'].values[item]) + '<hr></hr>' +
                      str(dfH['Cid'].values[item]) + '<hr></hr>' +
                      str(dfH['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfH['url'].values[item]),
                      icon=folium.Icon(color='cadetblue',
                                       icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longI[item],
                      popup=str(dfI['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfI['district'].values[item]) + '<hr></hr>' +
                      str(dfI['Cid'].values[item]) + '<hr></hr>' +
                      str(dfI['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfI['url'].values[item]),
                      icon=folium.Icon(color='darkblue',
                                       icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longJ[item],
                      popup=str(dfJ['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfJ['district'].values[item]) + '<hr></hr>' +
                      str(dfJ['Cid'].values[item]) + '<hr></hr>' +
                      str(dfJ['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfJ['url'].values[item]),
                      icon=folium.Icon(color='gray', icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longK[item],
                      popup=str(dfK['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfK['district'].values[item]) + '<hr></hr>' +
                      str(dfK['Cid'].values[item]) + '<hr></hr>' +
                      str(dfK['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfK['url'].values[item]),
                      icon=folium.Icon(color='black', icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longL[item],
                      popup=str(dfL['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfL['district'].values[item]) + '<hr></hr>' +
                      str(dfL['Cid'].values[item]) + '<hr></hr>' +
                      str(dfL['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfL['url'].values[item]),
                      icon=folium.Icon(color='pink', icon='home',
                                       prefix='fa')).add_to(mapp)

    for item in range(itr):
        folium.Marker(location=list_lat_longM[item],
                      popup=str(dfM['totalPrice'].values[item]) + '<hr></hr>' +
                      str(dfM['district'].values[item]) + '<hr></hr>' +
                      str(dfM['Cid'].values[item]) + '<hr></hr>' +
                      str(dfM['buildingType'].values[item]) + '<hr></hr>' +
                      str(dfM['url'].values[item]),
                      icon=folium.Icon(color='white', icon='home',
                                       prefix='fa')).add_to(mapp)
        return mapp._repr_html_()
예제 #12
0
def data():
    data = data_auto()
    return render_template('table_data.html', data=data)