Spaces:
Sleeping
Sleeping
Victor Rivera commited on
Commit ·
1aeeb14
1
Parent(s): a1eea4e
Anadir los querys en el sidebar
Browse files12345678910111267891011121314151617181314151617181920212223242526272841 unmodified lines70717266676873747572737475767776777879808182838485868788899091929394799596818283848586979899100101102881031049091929394105106107108109961101119899100101102112113114115116104117118106107108109110119120121122123112124125114115116117126127128129119130131121122123124132133134135126136137128138139import streamlit as stimport pandas as pdimport sqlite3from dataBaseSetup import create_connection
# Funciones de conexión a la base de datosdef create_connection(): conn = sqlite3.connect('bike_store.db') return conn
# Funciones de consultadef get_stocks_by_category_store(category_name, store_name): conn = create_connection() sql = ''' SELECT categories.category_name, stores.store_name, SUM(stocks.quantity) as total_stock FROM stocks JOIN products ON stocks.product_id = products.product_id JOIN categories ON products.category_id = categories.category_id JOIN stores ON stocks.store_id = stores.store_id WHERE categories.category_name = ? AND stores.store_name = ? GROUP BY categories.category_name, stores.store_name; ''' df = pd.read_sql_query(sql, conn, params=(category_name, store_name)) conn.close() return df conn = create_connection() sql = ''' SELECT categories.category_name, stores.store_name, SUM(stocks.quantity) as total_stock FROM stocks JOIN products ON stocks.product_id = products.product_id JOIN categories ON products.category_id = categories.category_id JOIN stores ON stocks.store_id = stores.store_id WHERE categories.category_name = ? AND stores.store_name = ? GROUP BY categories.category_name, stores.store_name; ''' df = pd.read_sql_query(sql, conn, params=(category_name, store_name)) conn.close() return df
def get_order_items_by_category_store(category_name, store_name): conn = create_connection()41 unmodified lines return df
# STREAMLIT
import streamlit as st
def app(): st.title("Bike Store Management System")
# Query 1: Stocks by Category and Store st.sidebar.header("Query 1: Get Stocks") category_name_1 = st.text_input("Category Name for Stocks", key='1') store_name_1 = st.text_input("Store Name for Stocks", key='2') if st.sidebar.button("Execute Query 1", key='3'): df = get_stocks_by_category_store(category_name_1, store_name_1) # Opciones de consulta en la barra lateral query_options = [ "Query 1: Get Stocks", "Query 2: Get Order Items", "Query 3: Total Sales in Santa Cruz Bikes", "Query 4: Total Sales in Baldwin Bikes", "Query 5: Total Sales in Rowlett Bikes", "Query 6: Staff with the Highest Number of Orders", "Query 7: Staff with the Lowest Number of Orders" ] selected_query = st.sidebar.radio("Seleccione una consulta para ejecutar", query_options)
# Mostrar inputs y ejecutar la consulta basada en la selección if selected_query == "Query 1: Get Stocks": st.write("### Query 1: Stocks by Category and Store") category_name_1 = st.text_input("Category Name for Stocks", key='1') store_name_1 = st.text_input("Store Name for Stocks", key='2') if st.button("Execute Query 1", key='3'): df = get_stocks_by_category_store(category_name_1, store_name_1) st.write(df) st.write(df)
# Query 2: Order Items by Category and Store st.sidebar.header("Query 2: Get Order Items") category_name_2 = st.text_input("Category Name for Order Items", key='4') store_name_2 = st.text_input("Store Name for Order Items", key='5') if st.sidebar.button("Execute Query 2", key='6'): df = get_order_items_by_category_store(category_name_2, store_name_2) elif selected_query == "Query 2: Get Order Items": st.write("### Query 2: Order Items by Category and Store") category_name_2 = st.text_input("Category Name for Order Items", key='4') store_name_2 = st.text_input("Store Name for Order Items", key='5') if st.button("Execute Query 2", key='6'): df = get_order_items_by_category_store(category_name_2, store_name_2) st.write(df) st.write(df)
# Query 3: Total Sales in Santa Cruz Bikes st.sidebar.header("Query 3: Total Sales in Santa Cruz Bikes") year_month_3 = st.text_input("Year-Month (YYYY-MM) for Santa Cruz Bikes", key='7') if st.sidebar.button("Execute Query 3", key='8'): df = get_total_sales_by_store_year_month("Santa Cruz Bikes", year_month_3) elif selected_query == "Query 3: Total Sales in Santa Cruz Bikes": st.write("### Query 3: Total Sales in Santa Cruz Bikes") year_month_3 = st.text_input("Year-Month (YYYY-MM) for Santa Cruz Bikes", key='7') if st.button("Execute Query 3", key='8'): df = get_total_sales_by_store_year_month("Santa Cruz Bikes", year_month_3) st.write(df) st.write(df)
# Query 4: Total Sales in Baldwin Bikes st.sidebar.header("Query 4: Total Sales in Baldwin Bikes") year_month_4 = st.text_input("Year-Month (YYYY-MM) for Baldwin Bikes", key='9') if st.sidebar.button("Execute Query 4", key='10'): df = get_total_sales_by_store_year_month("Baldwin Bikes", year_month_4) elif selected_query == "Query 4: Total Sales in Baldwin Bikes": st.write("### Query 4: Total Sales in Baldwin Bikes") year_month_4 = st.text_input("Year-Month (YYYY-MM) for Baldwin Bikes", key='9') if st.button("Execute Query 4", key='10'): df = get_total_sales_by_store_year_month("Baldwin Bikes", year_month_4) st.write(df) st.write(df)
# Query 5: Total Sales in Rowlett Bikes st.sidebar.header("Query 5: Total Sales in Rowlett Bikes") year_month_5 = st.text_input("Year-Month (YYYY-MM) for Rowlett Bikes", key='11') if st.sidebar.button("Execute Query 5", key='12'): df = get_total_sales_by_store_year_month("Rowlett Bikes", year_month_5) elif selected_query == "Query 5: Total Sales in Rowlett Bikes": st.write("### Query 5: Total Sales in Rowlett Bikes") year_month_5 = st.text_input("Year-Month (YYYY-MM) for Rowlett Bikes", key='11') if st.button("Execute Query 5", key='12'): df = get_total_sales_by_store_year_month("Rowlett Bikes", year_month_5) st.write(df) st.write(df)
# Query 6: Staff with the Highest Number of Orders st.sidebar.header("Query 6: Staff with the Highest Number of Orders") if st.sidebar.button("Execute Query 6", key='13'): df = get_staff_order_counts(desc=True) elif selected_query == "Query 6: Staff with the Highest Number of Orders": st.write("### Query 6: Staff with the Highest Number of Orders") if st.button("Execute Query 6", key='13'): df = get_staff_order_counts(desc=True) st.write(df) st.write(df)
# Query 7: Staff with the Lowest Number of Orders st.sidebar.header("Query 7: Staff with the Lowest Number of Orders") if st.sidebar.button("Execute Query 7", key='14'): df = get_staff_order_counts(desc=False) elif selected_query == "Query 7: Staff with the Lowest Number of Orders": st.write("### Query 7: Staff with the Lowest Number of Orders") if st.button("Execute Query 7", key='14'): df = get_staff_order_counts(desc=False) st.write(df) st.write(df)
if __name__ == '__main__':if __name__ == "__main__": app()app.py+69-59