Spaces:
Sleeping
Sleeping
Victor Rivera
commited on
Commit
路
1aeeb14
1
Parent(s):
a1eea4e
Anadir los querys en el sidebar
Browse files
app.py
CHANGED
|
@@ -1,21 +1,28 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
from dataBaseSetup import create_connection
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def get_stocks_by_category_store(category_name, store_name):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
def get_order_items_by_category_store(category_name, store_name):
|
| 21 |
conn = create_connection()
|
|
@@ -63,67 +70,70 @@ def get_staff_order_counts(desc=True):
|
|
| 63 |
return df
|
| 64 |
|
| 65 |
# STREAMLIT
|
| 66 |
-
|
| 67 |
-
import streamlit as st
|
| 68 |
-
|
| 69 |
def app():
|
| 70 |
st.title("Bike Store Management System")
|
| 71 |
|
| 72 |
-
#
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
st.write("### Query 1: Stocks by Category and Store")
|
| 79 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
st.sidebar.header("Query 2: Get Order Items")
|
| 83 |
-
category_name_2 = st.text_input("Category Name for Order Items", key='4')
|
| 84 |
-
store_name_2 = st.text_input("Store Name for Order Items", key='5')
|
| 85 |
-
if st.sidebar.button("Execute Query 2", key='6'):
|
| 86 |
-
df = get_order_items_by_category_store(category_name_2, store_name_2)
|
| 87 |
st.write("### Query 2: Order Items by Category and Store")
|
| 88 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
| 91 |
-
st.sidebar.header("Query 3: Total Sales in Santa Cruz Bikes")
|
| 92 |
-
year_month_3 = st.text_input("Year-Month (YYYY-MM) for Santa Cruz Bikes", key='7')
|
| 93 |
-
if st.sidebar.button("Execute Query 3", key='8'):
|
| 94 |
-
df = get_total_sales_by_store_year_month("Santa Cruz Bikes", year_month_3)
|
| 95 |
st.write("### Query 3: Total Sales in Santa Cruz Bikes")
|
| 96 |
-
st.
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
|
| 99 |
-
st.sidebar.header("Query 4: Total Sales in Baldwin Bikes")
|
| 100 |
-
year_month_4 = st.text_input("Year-Month (YYYY-MM) for Baldwin Bikes", key='9')
|
| 101 |
-
if st.sidebar.button("Execute Query 4", key='10'):
|
| 102 |
-
df = get_total_sales_by_store_year_month("Baldwin Bikes", year_month_4)
|
| 103 |
st.write("### Query 4: Total Sales in Baldwin Bikes")
|
| 104 |
-
st.
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
|
| 107 |
-
st.sidebar.header("Query 5: Total Sales in Rowlett Bikes")
|
| 108 |
-
year_month_5 = st.text_input("Year-Month (YYYY-MM) for Rowlett Bikes", key='11')
|
| 109 |
-
if st.sidebar.button("Execute Query 5", key='12'):
|
| 110 |
-
df = get_total_sales_by_store_year_month("Rowlett Bikes", year_month_5)
|
| 111 |
st.write("### Query 5: Total Sales in Rowlett Bikes")
|
| 112 |
-
st.
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
-
|
| 115 |
-
st.sidebar.header("Query 6: Staff with the Highest Number of Orders")
|
| 116 |
-
if st.sidebar.button("Execute Query 6", key='13'):
|
| 117 |
-
df = get_staff_order_counts(desc=True)
|
| 118 |
st.write("### Query 6: Staff with the Highest Number of Orders")
|
| 119 |
-
st.
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
| 122 |
-
st.sidebar.header("Query 7: Staff with the Lowest Number of Orders")
|
| 123 |
-
if st.sidebar.button("Execute Query 7", key='14'):
|
| 124 |
-
df = get_staff_order_counts(desc=False)
|
| 125 |
st.write("### Query 7: Staff with the Lowest Number of Orders")
|
| 126 |
-
st.
|
|
|
|
|
|
|
| 127 |
|
| 128 |
-
if __name__ ==
|
| 129 |
app()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
import sqlite3
|
| 4 |
from dataBaseSetup import create_connection
|
| 5 |
|
| 6 |
+
# Funciones de conexi贸n a la base de datos
|
| 7 |
+
def create_connection():
|
| 8 |
+
conn = sqlite3.connect('bike_store.db')
|
| 9 |
+
return conn
|
| 10 |
+
|
| 11 |
+
# Funciones de consulta
|
| 12 |
def get_stocks_by_category_store(category_name, store_name):
|
| 13 |
+
conn = create_connection()
|
| 14 |
+
sql = '''
|
| 15 |
+
SELECT categories.category_name, stores.store_name, SUM(stocks.quantity) as total_stock
|
| 16 |
+
FROM stocks
|
| 17 |
+
JOIN products ON stocks.product_id = products.product_id
|
| 18 |
+
JOIN categories ON products.category_id = categories.category_id
|
| 19 |
+
JOIN stores ON stocks.store_id = stores.store_id
|
| 20 |
+
WHERE categories.category_name = ? AND stores.store_name = ?
|
| 21 |
+
GROUP BY categories.category_name, stores.store_name;
|
| 22 |
+
'''
|
| 23 |
+
df = pd.read_sql_query(sql, conn, params=(category_name, store_name))
|
| 24 |
+
conn.close()
|
| 25 |
+
return df
|
| 26 |
|
| 27 |
def get_order_items_by_category_store(category_name, store_name):
|
| 28 |
conn = create_connection()
|
|
|
|
| 70 |
return df
|
| 71 |
|
| 72 |
# STREAMLIT
|
|
|
|
|
|
|
|
|
|
| 73 |
def app():
|
| 74 |
st.title("Bike Store Management System")
|
| 75 |
|
| 76 |
+
# Opciones de consulta en la barra lateral
|
| 77 |
+
query_options = [
|
| 78 |
+
"Query 1: Get Stocks",
|
| 79 |
+
"Query 2: Get Order Items",
|
| 80 |
+
"Query 3: Total Sales in Santa Cruz Bikes",
|
| 81 |
+
"Query 4: Total Sales in Baldwin Bikes",
|
| 82 |
+
"Query 5: Total Sales in Rowlett Bikes",
|
| 83 |
+
"Query 6: Staff with the Highest Number of Orders",
|
| 84 |
+
"Query 7: Staff with the Lowest Number of Orders"
|
| 85 |
+
]
|
| 86 |
+
selected_query = st.sidebar.radio("Seleccione una consulta para ejecutar", query_options)
|
| 87 |
+
|
| 88 |
+
# Mostrar inputs y ejecutar la consulta basada en la selecci贸n
|
| 89 |
+
if selected_query == "Query 1: Get Stocks":
|
| 90 |
st.write("### Query 1: Stocks by Category and Store")
|
| 91 |
+
category_name_1 = st.text_input("Category Name for Stocks", key='1')
|
| 92 |
+
store_name_1 = st.text_input("Store Name for Stocks", key='2')
|
| 93 |
+
if st.button("Execute Query 1", key='3'):
|
| 94 |
+
df = get_stocks_by_category_store(category_name_1, store_name_1)
|
| 95 |
+
st.write(df)
|
| 96 |
|
| 97 |
+
elif selected_query == "Query 2: Get Order Items":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
st.write("### Query 2: Order Items by Category and Store")
|
| 99 |
+
category_name_2 = st.text_input("Category Name for Order Items", key='4')
|
| 100 |
+
store_name_2 = st.text_input("Store Name for Order Items", key='5')
|
| 101 |
+
if st.button("Execute Query 2", key='6'):
|
| 102 |
+
df = get_order_items_by_category_store(category_name_2, store_name_2)
|
| 103 |
+
st.write(df)
|
| 104 |
|
| 105 |
+
elif selected_query == "Query 3: Total Sales in Santa Cruz Bikes":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
st.write("### Query 3: Total Sales in Santa Cruz Bikes")
|
| 107 |
+
year_month_3 = st.text_input("Year-Month (YYYY-MM) for Santa Cruz Bikes", key='7')
|
| 108 |
+
if st.button("Execute Query 3", key='8'):
|
| 109 |
+
df = get_total_sales_by_store_year_month("Santa Cruz Bikes", year_month_3)
|
| 110 |
+
st.write(df)
|
| 111 |
|
| 112 |
+
elif selected_query == "Query 4: Total Sales in Baldwin Bikes":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
st.write("### Query 4: Total Sales in Baldwin Bikes")
|
| 114 |
+
year_month_4 = st.text_input("Year-Month (YYYY-MM) for Baldwin Bikes", key='9')
|
| 115 |
+
if st.button("Execute Query 4", key='10'):
|
| 116 |
+
df = get_total_sales_by_store_year_month("Baldwin Bikes", year_month_4)
|
| 117 |
+
st.write(df)
|
| 118 |
|
| 119 |
+
elif selected_query == "Query 5: Total Sales in Rowlett Bikes":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
st.write("### Query 5: Total Sales in Rowlett Bikes")
|
| 121 |
+
year_month_5 = st.text_input("Year-Month (YYYY-MM) for Rowlett Bikes", key='11')
|
| 122 |
+
if st.button("Execute Query 5", key='12'):
|
| 123 |
+
df = get_total_sales_by_store_year_month("Rowlett Bikes", year_month_5)
|
| 124 |
+
st.write(df)
|
| 125 |
|
| 126 |
+
elif selected_query == "Query 6: Staff with the Highest Number of Orders":
|
|
|
|
|
|
|
|
|
|
| 127 |
st.write("### Query 6: Staff with the Highest Number of Orders")
|
| 128 |
+
if st.button("Execute Query 6", key='13'):
|
| 129 |
+
df = get_staff_order_counts(desc=True)
|
| 130 |
+
st.write(df)
|
| 131 |
|
| 132 |
+
elif selected_query == "Query 7: Staff with the Lowest Number of Orders":
|
|
|
|
|
|
|
|
|
|
| 133 |
st.write("### Query 7: Staff with the Lowest Number of Orders")
|
| 134 |
+
if st.button("Execute Query 7", key='14'):
|
| 135 |
+
df = get_staff_order_counts(desc=False)
|
| 136 |
+
st.write(df)
|
| 137 |
|
| 138 |
+
if __name__ == "__main__":
|
| 139 |
app()
|