コード例 #1
0
def create_stats():
    ##############################################################
    # LINE PLOT
    ###############################################################
    line_df = get_views.get_view_by_name('ventas_diarias')

    line_fig = px.line(line_df, 
        x = 'fecha_compra', 
        y = 'promedio_ventas', 
        hover_data=['volumen_ventas'])

    line_fig.update_layout(
         height=500
    )

    ###############################################################
    # BAR PLOT
    ###############################################################
    bar_df = get_views.get_view_by_name('venta_ciudad_tienda').head(10)

    bar_fig = px.bar(bar_df
           , y = 'ciudad_tienda', x = 'tienda_x_ciudad'
           , color = 'canal'
           , hover_data=['canal']
           , barmode = 'stack'
           , orientation = 'h'
          )
    bar_fig.update_layout(
        autosize=True,
        #width=1000,
        height=500,
        legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
        yaxis={'categoryorder':'total ascending'}
    )
    #################################################################################
    # Here the layout for the plots to use.
    #################################################################################
    stats =  [
                    dbc.Col(
                        dbc.Card(
                            dcc.Graph(figure=bar_fig, id="bar"),body=True, color="dark"
                            ),
                            width={"size": 5, "offset": 2},
                            ),
                    dbc.Col(
                        dbc.Card(
                            dcc.Graph(figure=line_fig, id="line"),body=True, color="dark"
                            ),
                            width=5
                        )
                ]
            


    return stats
コード例 #2
0
 def set_cities_options(chosen_state):
     clean2 = get_views.get_view_by_name('canal_edad_tipo_ciudad_cluster')
     dff = clean2[clean2['ciudad_tienda'] == chosen_state]
     return [{
         'label': c,
         'value': c
     } for c in sorted(dff['cluster_id'].unique())]
コード例 #3
0
 def update_graph(selected_ciudad, selected_cluster):
     clean = get_views.get_view_by_name('canal_edad_tipo_ciudad_cluster')
     df = clean[clean['ciudad_tienda'] == selected_ciudad]
     df10 = df['cluster_id'].unique()
     if selected_cluster is None:
         df2 = get_views.get_view_by_name('canal_edad_tipo_ciudad_cluster')
         dff = df2[(df2['ciudad_tienda'] == selected_ciudad)]
         fig = px.sunburst(dff,
                           path=['canal', 'edad', 'tipo_articulo'],
                           values='volumen_pesos',
                           color='canal',
                           title="Total sales  for the city of: {}".format(
                               selected_ciudad))
         fig.update_traces(textinfo='label+percent entry')
         fig.update_layout(margin=dict(t=0, l=0, r=0, b=0))
     else:
         if selected_cluster in list(df10):
             df2 = get_views.get_view_by_name(
                 'canal_edad_tipo_ciudad_cluster')
             dff = df2[(df2['ciudad_tienda'] == selected_ciudad)
                       & df2['cluster_id'].isin([selected_cluster])]
             fig = px.sunburst(
                 dff,
                 path=['canal', 'edad', 'tipo_articulo'],
                 values='volumen_pesos',
                 color='canal',
                 title="Total sales  for the city of: {}".format(
                     selected_ciudad))
             fig.update_traces(textinfo='label+percent entry')
             fig.update_layout(margin=dict(t=0, l=0, r=0, b=0))
         else:
             df2 = get_views.get_view_by_name(
                 'canal_edad_tipo_ciudad_cluster')
             dff = df2[(df2['ciudad_tienda'] == selected_ciudad)]
             fig = px.sunburst(
                 dff,
                 path=['canal', 'edad', 'tipo_articulo'],
                 values='volumen_pesos',
                 color='canal',
                 title="Total sales  for the city of: {}".format(
                     selected_ciudad))
             fig.update_traces(textinfo='label+percent entry')
             fig.update_layout(margin=dict(t=0, l=0, r=0, b=0))
     return fig
コード例 #4
0
    def map_cities(ciudad):
        line_df = get_views.get_view_by_name('ventas_diarias_ciudad')
        line_df["ciudad_tienda"] = line_df["ciudad_tienda"].apply(
            lambda x: x.capitalize())
        line_df = line_df[line_df["ciudad_tienda"] == ciudad]
        fig6 = px.line(line_df,
                       x='fecha_compra',
                       y='volumen_ventas',
                       hover_data=['promedio_ventas'])

        return open('maps/' + ciudad + '_map.html', 'r').read(), fig6
コード例 #5
0
def create_map():
    '''
    This functions creates the map off Colombia where the company has stores.
    params:
        none
    returns:
        creates an html for Colombia where each city has information about
        customers purchase frecuency
    '''
	
	df_for_map = get_views.get_view_by_name('tiendas_frecuencia')
	df_for_map["Radio_for_map"]=((df_for_map["valor_neto"])/df_for_map["valor_neto"].mean())*10+5

	# Create the map:
	m_prueba = folium.Map(location=[6.461508, -75.000000],max_zoom=18, zoom_start=6, tiles="cartodbpositron")

	circle="""
	<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
		width='25' height='25' viewBox='0 0 120 120'>
	<circle cx='60' cy='60' r='50'
			fill={} />
	</svg>
	"""

	group1=folium.FeatureGroup(name=circle.format('#FF0000')+"<FONT SIZE=2>Freq. [1,1.25]</font>  ")
	m_prueba.add_child(group1)

	group2=folium.FeatureGroup(name=circle.format('#FF7070')+"<FONT SIZE=2>Freq. [1.25,1.35]</font>", show=False)
	m_prueba.add_child(group2)

	group3=folium.FeatureGroup(name=circle.format('#FF6B22')+"<FONT SIZE=2>Freq. [1.35,1.5]</font>" , show=False)
	m_prueba.add_child(group3)

	group4=folium.FeatureGroup(name=circle.format('#0FFB0E')+"<FONT SIZE=2>Freq. [1.5,1.8]</font>", show=False)
	m_prueba.add_child(group4)

	group5=folium.FeatureGroup(name=circle.format('#019F00')+"<FONT SIZE=2>Freq. > 1.8</font>", show=False)
	m_prueba.add_child(group5)

	for i in range(df_for_map.shape[0]):
		
		sales=round(df_for_map.loc[i,"valor_neto"]/1000000,1)
		sales=f"${sales}M"
		
		html_ = """
		<h2 style="margin-bottom:-10"; align="center">{}</h2>""".format(df_for_map.loc[i,'punto_venta']) + """ <br>
		<b>Total ventas (1 año):</b> {}""".format(sales) + """ <br/>
		<b>Frec. de venta (1 año):</b> {}""".format(round(df_for_map.loc[i,'frequency'],4)) + """ <br/>
		<b>Centro comercial:</b> {}""".format(df_for_map.loc[i,'centro_comercial']) + """ <br/>
		<b>Canal:</b> {}""".format(df_for_map.loc[i,'canal']) + """ <br/>
		<b>Codigo tienda:</b> {}""".format(df_for_map.loc[i,'codigo_tienda']) + """ <br/>
		<b>IDGEO:</b> {}""".format(df_for_map.loc[i,'id_geo'])

		iframe = branca.element.IFrame(html=html_, width=300, height=250)
		popup = folium.Popup(iframe, max_width=305, parse_html=True)

		if (df_for_map.loc[i,"frequency"] > 1) & (df_for_map.loc[i,"frequency"] <= 1.25):
			folium.CircleMarker(radius=df_for_map.loc[i,"Radio_for_map"], 
						location=[df_for_map.loc[i,"latitude"],df_for_map.loc[i,"longitude"]],
						popup=popup,
								color="black",fill=True,fill_color="#FF0000",weight=1,
								fill_opacity=0.7,
						tooltip=f"<FONT SIZE=4><b>Ventas</b>:{sales}</font>").add_to(group1)
		
		elif (df_for_map.loc[i,"frequency"] > 1.25) & (df_for_map.loc[i,"frequency"] <= 1.35):
			folium.CircleMarker(radius=df_for_map.loc[i,"Radio_for_map"], 
						location=[df_for_map.loc[i,"latitude"],df_for_map.loc[i,"longitude"]],
						popup=popup,color="black",fill=True,fill_color="#FF7070",weight=1,
								fill_opacity=0.7,
						tooltip=f"<FONT SIZE=4><b>Ventas</b>:{sales}</font>").add_to(group2)
			
		elif (df_for_map.loc[i,"frequency"] > 1.35) & (df_for_map.loc[i,"frequency"] <= 1.5):
			folium.CircleMarker(radius=df_for_map.loc[i,"Radio_for_map"], 
						location=[df_for_map.loc[i,"latitude"],df_for_map.loc[i,"longitude"]],
						popup=popup,color="black",fill=True,fill_color="#FF6B22",weight=1,
								fill_opacity=0.8,
						tooltip=f"<FONT SIZE=4><b>Ventas</b>:{sales}</font>").add_to(group3)
		
		elif (df_for_map.loc[i,"frequency"] > 1.5) & (df_for_map.loc[i,"frequency"] <= 1.8):
			folium.CircleMarker(radius=df_for_map.loc[i,"Radio_for_map"], 
						location=[df_for_map.loc[i,"latitude"],df_for_map.loc[i,"longitude"]],
						popup=popup,color="black",fill=True,fill_color="#8EFF94",weight=1,
								fill_opacity=0.8,
						tooltip=f"<FONT SIZE=4><b>Ventas</b>:{sales}</font>").add_to(group4)
		else:
			folium.CircleMarker(radius=df_for_map.loc[i,"Radio_for_map"], 
						location=[df_for_map.loc[i,"latitude"],df_for_map.loc[i,"longitude"]],
						popup=popup,color="black",fill=True,fill_color="#2B9A00",weight=1,
								fill_opacity=0.8,
						tooltip=f"<FONT SIZE=4><b>Ventas</b>:{sales}</font>").add_to(group5)
			
	folium.LayerControl(collapsed=False).add_to(m_prueba)
	m_prueba.save('maps/Colombia_map.html')
	##############################
	# Map Layout
	##############################
	map = html.Div(
	    [
			html.H5("Sales frequency and amount per store"),
			html.P("Full Country"),
	        # Place the main graph component here:
	        html.Iframe(srcDoc = open('maps/Colombia_map.html','r').read()
	        	, id="COL_map",width='100%',height=526)
	    ],
	    #className="ds4a-body",
	)

	return map
コード例 #6
0
def create_map_cities():

    '''
    This functions creates the maps off all cities where the company has stores.
    params:
        none
    returns:
        creates an html for all the cities where each map has information about
        customers purchase frecuency 
    '''
	
    df_for_map = get_views.get_view_by_name('tiendas_frecuencia')
    df_for_map["Radio_for_map"]=((df_for_map["valor_neto"])/df_for_map["valor_neto"].mean())*10+5

    # Create dictionary with cities, location and zoom:

    locations_dict ={'ciudad': ['Medellín', 'Bogotá', 'Barrancabermeja', 'Cali', 'Santa Marta', 'Cartagena', 'Yopal',
                            'Chía', 'Armenia', 'Villavicencio', 'Ipiales', 'Pasto', 'Bucaramanga', 'Cúcuta',
                            'Tunja', 'Pitalito', 'Barranquilla', 'Valledupar', 'Popayán', 'Ibagué', 'Montería',
                            'Riohacha', 'Ocaña', 'Girardot', 'Rionegro', 'Neiva', 'San Andres', 'Apartadó',
                            'Yumbo', 'Manizales', 'La Ceja', 'Aguachica', 'Envigado', 'Pereira', 'Duitama',
                            'Sogamoso', 'Arauca', 'Sincelejo', 'Florencia', 'Cartago', 'Palmira'],
                    'location': [[6.2501125,-75.5803933], [4.683925, -74.087004], [7.064098, -73.856063],
                                [3.427341, -76.521280], [11.235145, -74.192268], [10.397664, -75.506810],
                                [5.333906, -72.395035], [4.877329, -74.034782], [4.540616, -75.674956],
                                [4.136571, -73.626914], [0.826007, -77.640272], [1.211466, -77.277567],
                                [7.107962, -73.113924], [7.902127, -72.506138], [5.550740, -73.349890], 
                                [1.852723, -76.048825], [10.992978, -74.806297], [10.469399, -73.251555], 
                                [2.457041, -76.592210], [4.434196, -75.197765], [8.749607, -75.879484], 
                                [11.537468, -72.912597], [8.247508, -73.356539], [4.302750, -74.801321], 
                                [6.147482, -75.375835], [2.932439, -75.282356], [12.561642, -81.717021], 
                                [7.883654, -76.625723], [3.582594, -76.489090], [5.061344, -75.5049307], 
                                [6.029851, -75.428421], [8.307962, -73.612180], [6.168872, -75.584505], 
                                [4.811958, -75.709814], [5.823173, -73.031070], [5.724299, -72.924044], 
                                [7.081708, -70.753947], [9.302024, -75.396304], [1.617380, -75.609830], 
                                [4.746874, -75.921079], [3.531945, -76.297079]],
                    'zoom': [12, 11, 14, 12, 14, 12, 14, 13, 13, 14, 14, 13, 13, 12, 14, 14, 13, 13, 13, 13,
                            14, 13, 14, 14, 13, 13, 13, 14, 14, 14, 14, 14, 14, 13, 14, 14, 14, 14, 14, 14, 14]
                    }


    # Create the map:
    locations_df = pd.DataFrame(locations_dict)
    
    for index, row in locations_df.iterrows():

        m_prueba = folium.Map(location=row[1],max_zoom=18, zoom_start=row[2])

        circle="""
        <svg version='1.1' xmlns='http://www.w3.org/2000/svg'
            width='25' height='25' viewBox='0 0 120 120'>
        <circle cx='60' cy='60' r='50'
                fill={} />
        </svg>
        """
        group1=folium.FeatureGroup(name=circle.format('#FF0000')+"<FONT SIZE=2>Freq. [1,1.25]</font>  ")
        m_prueba.add_child(group1)

        group2=folium.FeatureGroup(name=circle.format('#FF7070')+"<FONT SIZE=2>Freq. [1.25,1.35]</font>")
        m_prueba.add_child(group2)
        
        group3=folium.FeatureGroup(name=circle.format('#FF6B22')+"<FONT SIZE=2>Freq. [1.35,1.5]</font>" )
        m_prueba.add_child(group3)

        group4=folium.FeatureGroup(name=circle.format('#0FFB0E')+"<FONT SIZE=2>Freq. [1.5,1.8]</font>")
        m_prueba.add_child(group4)

        group5=folium.FeatureGroup(name=circle.format('#019F00')+"<FONT SIZE=2>Freq. > 1.8</font>")
        m_prueba.add_child(group5)

        for i in range(df_for_map.shape[0]):

            sales=round(df_for_map.loc[i,"valor_neto"]/1000000,1)
            sales=f"${sales}M"

            html_ = """
            <h2 style="margin-bottom:-10"; align="center">{}</h2>""".format(df_for_map.loc[i,'punto_venta']) + """ <br>
            <b>Total ventas (1 año):</b> {}""".format(sales) + """ <br/>
            <b>Frec. de venta (1 año):</b> {}""".format(round(df_for_map.loc[i,'frequency'],4)) + """ <br/>
            <b>Centro comercial:</b> {}""".format(df_for_map.loc[i,'centro_comercial']) + """ <br/>
            <b>Canal:</b> {}""".format(df_for_map.loc[i,'canal']) + """ <br/>
            <b>Codigo tienda:</b> {}""".format(df_for_map.loc[i,'codigo_tienda']) + """ <br/>
            <b>IDGEO:</b> {}""".format(df_for_map.loc[i,'id_geo'])

            iframe = branca.element.IFrame(html=html_, width=300, height=250)
            popup = folium.Popup(iframe, max_width=305, parse_html=True)
            
            if (df_for_map.loc[i,"frequency"] > 1) & (df_for_map.loc[i,"frequency"] <= 1.25):
                folium.CircleMarker(radius=df_for_map.loc[i,"Radio_for_map"], 
                            location=[df_for_map.loc[i,"latitude"],df_for_map.loc[i,"longitude"]],
                            popup=popup,
                                    color="black",fill=True,fill_color="#FF0000",weight=1,
                                    fill_opacity=0.7,
                            tooltip=f"<FONT SIZE=4><b>Ventas</b>:{sales}</font>").add_to(group1)

            elif (df_for_map.loc[i,"frequency"] > 1.25) & (df_for_map.loc[i,"frequency"] <= 1.35):
                folium.CircleMarker(radius=df_for_map.loc[i,"Radio_for_map"], 
                            location=[df_for_map.loc[i,"latitude"],df_for_map.loc[i,"longitude"]],
                            popup=popup,color="black",fill=True,fill_color="#FF7070",weight=1,
                                    fill_opacity=0.7,
                            tooltip=f"<FONT SIZE=4><b>Ventas</b>:{sales}</font>").add_to(group2)
            
            elif (df_for_map.loc[i,"frequency"] > 1.35) & (df_for_map.loc[i,"frequency"] <= 1.5):
                folium.CircleMarker(radius=df_for_map.loc[i,"Radio_for_map"], 
                            location=[df_for_map.loc[i,"latitude"],df_for_map.loc[i,"longitude"]],
                            popup=popup,color="black",fill=True,fill_color="#FF6B22",weight=1,
                                    fill_opacity=0.8,
                            tooltip=f"<FONT SIZE=4><b>Ventas</b>:{sales}</font>").add_to(group3)

            elif (df_for_map.loc[i,"frequency"] > 1.5) & (df_for_map.loc[i,"frequency"] <= 1.8):
                folium.CircleMarker(radius=df_for_map.loc[i,"Radio_for_map"], 
                            location=[df_for_map.loc[i,"latitude"],df_for_map.loc[i,"longitude"]],
                            popup=popup,color="black",fill=True,fill_color="#8EFF94",weight=1,
                                    fill_opacity=0.8,
                            tooltip=f"<FONT SIZE=4><b>Ventas</b>:{sales}</font>").add_to(group4)
            else:
                folium.CircleMarker(radius=df_for_map.loc[i,"Radio_for_map"], 
                            location=[df_for_map.loc[i,"latitude"],df_for_map.loc[i,"longitude"]],
                            popup=popup,color="black",fill=True,fill_color="#2B9A00",weight=1,
                                    fill_opacity=0.8,
                            tooltip=f"<FONT SIZE=4><b>Ventas</b>:{sales}</font>").add_to(group5)
                
        folium.LayerControl(collapsed=True).add_to(m_prueba)
        
        map_name = row[0]+'_map.html'

        m_prueba.save('maps/'+map_name)
コード例 #7
0
from data_fetch import get_views
from get_callbacks import return_callbacks

card_main = dbc.Card(
    [

        dbc.CardBody(
            [
                html.H4("Analysis of sales values by city and items offered by OFFCORSS", className="card-title"),

                html.P(
                    "choose the city to see the main items sold in each of the stores.",
                    className="card-text",
                ),
                dcc.Dropdown(id="ciudades-dpdn",placeholder='Ciudad...',
                 options=[{'label': i, 'value': i} for i in sorted(get_views.get_view_by_name('canal_edad_tipo_ciudad_cluster').drop(get_views.get_view_by_name('canal_edad_tipo_ciudad_cluster')[(get_views.get_view_by_name('canal_edad_tipo_ciudad_cluster')['ciudad_tienda'] == 'MEDELLIN') | (get_views.get_view_by_name('canal_edad_tipo_ciudad_cluster')['ciudad_tienda'] == 'BOGOTÁ') ].index)['ciudad_tienda'].unique())],
                 multi=False,
                 value='AGUACHICA',
                 clearable=False,
                 persistence=False,
                 persistence_type='memory',
                 style={'width': "60%",'color':'black'}),
                html.P(
                    "select the cluster you want to view",
                    className="card-text",
                ),
                dcc.Dropdown(id='cluster-dpdn',placeholder='cluster', options=[], multi=False,clearable=True,value=None,persistence=True,persistence_type='memory',style={'width': "60%",'color':'black'}),
                html.P(
                    "Choose several categories to observe the profits produced",
                    className="card-text",
                ),
コード例 #8
0
 def barp(selected_cluster, selected_ciudad, select):
     clean = get_views.get_view_by_name('canal_edad_tipo_ciudad_cluster')
     df = clean[clean['ciudad_tienda'] == selected_ciudad]
     df10 = df['cluster_id'].unique()
     if (selected_cluster is None and select
             == 'grupo_articulo') or (selected_cluster not in list(df10)
                                      and select == 'grupo_articulo'):
         dff = get_views.get_view_by_name(
             'ciudad_tienda_grupo_articulo_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         df_bar = df_bar.sort_values('volumen_pesos',
                                     ascending=False).head(10)
         fig5 = px.bar(
             df_bar,
             y='grupo_articulo',
             x="volumen_pesos",
             color='grupo_articulo',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster is None
           and select == 'canal') or (selected_cluster not in list(df10)
                                      and select == 'canal'):
         dff = get_views.get_view_by_name('ciudad_tienda_canal_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         df_bar = df_bar.sort_values('volumen_pesos', ascending=False)
         fig5 = px.bar(
             df_bar,
             y='canal',
             x="volumen_pesos",
             color='canal',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster is None
           and select == 'sublinea') or (selected_cluster not in list(df10)
                                         and select == 'sublinea'):
         dff = get_views.get_view_by_name('ciudad_tienda_sublinea_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         df_bar = df_bar.sort_values('volumen_pesos', ascending=False)
         fig5 = px.bar(
             df_bar,
             y='sublinea',
             x="volumen_pesos",
             color='sublinea',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster is None
           and select == 'saldo') or (selected_cluster not in list(df10)
                                      and select == 'saldo'):
         dff = get_views.get_view_by_name('ciudad_tienda_saldo_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         df_bar = df_bar.sort_values('volumen_pesos', ascending=False)
         fig5 = px.bar(
             df_bar,
             y='saldo',
             x="volumen_pesos",
             color='saldo',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster is None and select
           == 'tipo_tejido') or (selected_cluster not in list(df10)
                                 and select == 'tipo_tejido'):
         dff = get_views.get_view_by_name(
             'ciudad_tienda_tipo_tejido_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         df_bar = df_bar.sort_values('volumen_pesos', ascending=False)
         fig5 = px.bar(
             df_bar,
             y='tipo_tejido',
             x="volumen_pesos",
             color='tipo_tejido',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster is None and select
           == 'tipo_articulo') or (selected_cluster not in list(df10)
                                   and select == 'tipo_articulo'):
         dff = get_views.get_view_by_name(
             'ciudad_tienda_tipo_articulo_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         df_bar = df_bar.sort_values('volumen_pesos',
                                     ascending=False).head(10)
         fig5 = px.bar(
             df_bar,
             y='tipo_articulo',
             x="volumen_pesos",
             color='tipo_articulo',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster is None
           and select == 'mes_venta') or (selected_cluster not in list(df10)
                                          and select == 'mes_venta'):
         dff = get_views.get_view_by_name('ciudad_tienda_mes_venta_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         df_bar = df_bar.sort_values('volumen_pesos', ascending=False)
         fig5 = px.bar(
             df_bar,
             y='mes_venta',
             x="volumen_pesos",
             color='mes_venta',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster in list(df10) and select == 'grupo_articulo'):
         dff = get_views.get_view_by_name(
             'ciudad_tienda_grupo_articulo_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)
                      & dff['cluster_id'].isin([selected_cluster])]
         df_bar = df_bar.sort_values('volumen_pesos',
                                     ascending=False).head(10)
         fig5 = px.bar(
             df_bar,
             y='grupo_articulo',
             x="volumen_pesos",
             color='grupo_articulo',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster in list(df10) and select == 'canal'):
         dff = get_views.get_view_by_name('ciudad_tienda_canal_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)
                      & dff['cluster_id'].isin([selected_cluster])]
         df_bar = df_bar.sort_values('volumen_pesos', ascending=False)
         fig5 = px.bar(
             df_bar,
             y='canal',
             x="volumen_pesos",
             color='canal',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster in list(df10) and select == 'sublinea'):
         dff = get_views.get_view_by_name('ciudad_tienda_sublinea_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)
                      & dff['cluster_id'].isin([selected_cluster])]
         df_bar = df_bar.sort_values('volumen_pesos', ascending=False)
         fig5 = px.bar(
             df_bar,
             y='sublinea',
             x="volumen_pesos",
             color='sublinea',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster in list(df10) and select == 'saldo'):
         dff = get_views.get_view_by_name('ciudad_tienda_saldo_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)
                      & dff['cluster_id'].isin([selected_cluster])]
         df_bar = df_bar.sort_values('volumen_pesos', ascending=False)
         fig5 = px.bar(
             df_bar,
             y='saldo',
             x="volumen_pesos",
             color='saldo',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster in list(df10) and select == 'tipo_tejido'):
         dff = get_views.get_view_by_name(
             'ciudad_tienda_tipo_tejido_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)
                      & dff['cluster_id'].isin([selected_cluster])]
         df_bar = df_bar.sort_values('volumen_pesos', ascending=False)
         fig5 = px.bar(
             df_bar,
             y='tipo_tejido',
             x="volumen_pesos",
             color='tipo_tejido',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster in list(df10) and select == 'mes_venta'):
         dff = get_views.get_view_by_name('ciudad_tienda_mes_venta_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)
                      & dff['cluster_id'].isin([selected_cluster])]
         df_bar = df_bar.sort_values('volumen_pesos', ascending=False)
         fig5 = px.bar(
             df_bar,
             y='mes_venta',
             x="volumen_pesos",
             color='mes_venta',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     elif (selected_cluster in list(df10) and select == 'tipo_articulo'):
         dff = get_views.get_view_by_name(
             'ciudad_tienda_tipo_articulo_cluster')
         df_bar = dff[(dff['ciudad_tienda'] == selected_ciudad)
                      & dff['cluster_id'].isin([selected_cluster])]
         df_bar = df_bar.sort_values('volumen_pesos',
                                     ascending=False).head(10)
         fig5 = px.bar(
             df_bar,
             y='tipo_articulo',
             x="volumen_pesos",
             color='tipo_articulo',
             orientation="h",
             hover_name="ciudad_tienda",
             title="Sales generated according to: {}".format(select))
     else:
         print('no found')
     return fig5
コード例 #9
0
 def update(selected_cluster, selected_ciudad, choose):
     clean = get_views.get_view_by_name('canal_edad_tipo_ciudad_cluster')
     df = clean[clean['ciudad_tienda'] == selected_ciudad]
     df10 = df['cluster_id'].unique()
     if selected_cluster is None and choose == 'edad':
         dff = get_views.get_view_by_name('edad_count_avg_cluster')
         df_line = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         fig3 = px.scatter(
             df_line,
             x="fecha_compra",
             y='ventas_promedio',
             color=choose,
             hover_data=['cantidad_compras'],
             title="Trend of sales according to the annual course of : {}".
             format(choose))
     elif selected_cluster is None and choose == 'canal':
         dff = get_views.get_view_by_name('count_avg_cluster')
         df_line = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         fig3 = px.scatter(
             df_line,
             x="fecha_compra",
             y='ventas_promedio',
             color=choose,
             hover_data=['cantidad_compras'],
             title="Trend of sales according to the annual course of : {}".
             format(choose))
     elif selected_cluster in list(df10) and choose == 'edad':
         dff = get_views.get_view_by_name('edad_count_avg_cluster')
         df_line = dff[(dff['ciudad_tienda'] == selected_ciudad)
                       & dff['cluster_id'].isin([selected_cluster])]
         fig3 = px.scatter(
             df_line,
             x="fecha_compra",
             y='ventas_promedio',
             color=choose,
             hover_data=['cantidad_compras'],
             title="Trend of sales according to the annual course of : {}".
             format(choose))
     elif selected_cluster in list(df10) and choose == 'canal':
         dff = get_views.get_view_by_name('count_avg_cluster')
         df_line = dff[(dff['ciudad_tienda'] == selected_ciudad)
                       & dff['cluster_id'].isin([selected_cluster])]
         fig3 = px.scatter(
             df_line,
             x="fecha_compra",
             y='ventas_promedio',
             color=choose,
             hover_data=['cantidad_compras'],
             title="Trend of sales according to the annual course of : {}".
             format(choose))
     elif selected_cluster not in list(df10) and choose == 'canal':
         dff = get_views.get_view_by_name('count_avg_cluster')
         df_line = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         fig3 = px.scatter(
             df_line,
             x="fecha_compra",
             y='ventas_promedio',
             color=choose,
             hover_data=['cantidad_compras'],
             title="Trend of sales according to the annual course of : {}".
             format(choose))
     else:
         dff = get_views.get_view_by_name('edad_count_avg_cluster')
         df_line = dff[(dff['ciudad_tienda'] == selected_ciudad)]
         fig3 = px.scatter(
             df_line,
             x="fecha_compra",
             y='ventas_promedio',
             color=choose,
             hover_data=['cantidad_compras'],
             title="Trend of sales according to the annual course of : {}".
             format(choose))
     return fig3
コード例 #10
0
def create_map():
    #############################
    # Load paths
    #############################

    #############################
    # Load map data
    #############################

    df_for_map = get_views.get_view_by_name('tiendas_frecuencia')
    df_for_map["Radio_for_map"] = df_for_map["valor_neto"] / 37000000

    # Create the map:
    m_prueba = folium.Map(location=[5.543949, -73.917579],
                          max_zoom=18,
                          zoom_start=5)
    tooltip = 'Click me!'

    group1 = folium.FeatureGroup(name="Freq [1,1.25]")
    m_prueba.add_child(group1)
    group2 = folium.FeatureGroup(name="Freq [1.25,1.35]", show=False)
    m_prueba.add_child(group2)
    group3 = folium.FeatureGroup(name="Freq [1.35,1.5]", show=False)
    m_prueba.add_child(group3)
    group4 = folium.FeatureGroup(name="Freq [1.5,1.8]", show=False)
    m_prueba.add_child(group4)
    group5 = folium.FeatureGroup(name="Freq > 1.8", show=False)
    m_prueba.add_child(group5)

    for i in range(df_for_map.shape[0]):
        sales = df_for_map.loc[i, "valor_neto"]
        if (df_for_map.loc[i, "frequency"] >
                1) & (df_for_map.loc[i, "frequency"] <= 1.25):
            folium.CircleMarker(radius=df_for_map.loc[i, "Radio_for_map"],
                                location=[
                                    df_for_map.loc[i, "latitude"],
                                    df_for_map.loc[i, "longitude"]
                                ],
                                popup=df_for_map.loc[i, "centro_comercial"],
                                color="black",
                                fill=True,
                                fill_color="red",
                                weight=1,
                                fill_opacity=0.5,
                                tooltip=f"Sales:{sales}").add_to(group1)
        elif (df_for_map.loc[i, "frequency"] >
              1.25) & (df_for_map.loc[i, "frequency"] <= 1.35):
            folium.CircleMarker(radius=df_for_map.loc[i, "Radio_for_map"],
                                location=[
                                    df_for_map.loc[i, "latitude"],
                                    df_for_map.loc[i, "longitude"]
                                ],
                                popup=df_for_map.loc[i, "centro_comercial"],
                                color="black",
                                fill=True,
                                fill_color="blue",
                                weight=1,
                                fill_opacity=0.5,
                                tooltip=f"Sales:{sales}").add_to(group2)
        elif (df_for_map.loc[i, "frequency"] >
              1.35) & (df_for_map.loc[i, "frequency"] <= 1.5):
            folium.CircleMarker(radius=df_for_map.loc[i, "Radio_for_map"],
                                location=[
                                    df_for_map.loc[i, "latitude"],
                                    df_for_map.loc[i, "longitude"]
                                ],
                                popup=df_for_map.loc[i, "centro_comercial"],
                                color="black",
                                fill=True,
                                fill_color="coral",
                                weight=1,
                                fill_opacity=0.5,
                                tooltip=f"Sales:{sales}").add_to(group3)
        elif (df_for_map.loc[i, "frequency"] >
              1.5) & (df_for_map.loc[i, "frequency"] <= 1.8):
            folium.CircleMarker(radius=df_for_map.loc[i, "Radio_for_map"],
                                location=[
                                    df_for_map.loc[i, "latitude"],
                                    df_for_map.loc[i, "longitude"]
                                ],
                                popup=df_for_map.loc[i, "centro_comercial"],
                                color="black",
                                fill=True,
                                fill_color="green",
                                weight=1,
                                fill_opacity=0.5,
                                tooltip=f"Sales:{sales}").add_to(group4)
        else:
            folium.CircleMarker(radius=df_for_map.loc[i, "Radio_for_map"],
                                location=[
                                    df_for_map.loc[i, "latitude"],
                                    df_for_map.loc[i, "longitude"]
                                ],
                                popup=df_for_map.loc[i, "centro_comercial"],
                                color="black",
                                fill=True,
                                fill_color="purple",
                                weight=1,
                                fill_opacity=0.5,
                                tooltip=f"Sales:{sales}").add_to(group5)
    folium.TileLayer('cartodbpositron').add_to(m_prueba)
    folium.LayerControl(collapsed=False).add_to(m_prueba)
    m_prueba.save('Colombia_map.html')
    ##############################
    # Map Layout
    ##############################
    map = html.Div(
        [
            # Place the main graph component here:
            html.Iframe(srcDoc=open('Colombia_map.html', 'r').read(),
                        id="COL_map",
                        width='100%',
                        height=600)
        ],
        className="ds4a-body",
    )

    return map