diff --git a/README.md b/README.md index 10dbdedd6091..190eb9bdf9ef 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,16 @@ -# Welcome to Streamlit! +# Material Stock Manager -Edit `/streamlit_app.py` to customize this app to your heart's desire. :heart: +This Streamlit app allows you to track materials in stock. Materials are chosen +from a small predefined list: -If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community -forums](https://discuss.streamlit.io). +* Piedra Caliza +* Durmientes de Madera +* Malla de Acero + +You can: + +1. Add a material from the list with an initial quantity. +2. Increase or decrease the quantity of an existing material. +3. View a table and bar chart showing the current stock levels. + +Run the app with `streamlit run streamlit_app.py`. diff --git a/streamlit_app.py b/streamlit_app.py index ac305b93bffd..bc5ea429b005 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -1,38 +1,44 @@ -from collections import namedtuple -import altair as alt -import math -import pandas as pd import streamlit as st +import pandas as pd -""" -# Welcome to Streamlit! - -Edit `/streamlit_app.py` to customize this app to your heart's desire :heart: - -If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community -forums](https://discuss.streamlit.io). - -In the meantime, below is an example of what you can do with just a few lines of code: -""" - - -with st.echo(code_location='below'): - total_points = st.slider("Number of points in spiral", 1, 5000, 2000) - num_turns = st.slider("Number of turns in spiral", 1, 100, 9) - - Point = namedtuple('Point', 'x y') - data = [] - - points_per_turn = total_points / num_turns - - for curr_point_num in range(total_points): - curr_turn, i = divmod(curr_point_num, points_per_turn) - angle = (curr_turn + 1) * 2 * math.pi * i / points_per_turn - radius = curr_point_num / total_points - x = radius * math.cos(angle) - y = radius * math.sin(angle) - data.append(Point(x, y)) - - st.altair_chart(alt.Chart(pd.DataFrame(data), height=500, width=500) - .mark_circle(color='#0068c9', opacity=0.5) - .encode(x='x:Q', y='y:Q')) +st.title("Material Stock Manager") + +# Initialize session state for materials +if 'materials' not in st.session_state: + st.session_state.materials = {} + +MATERIAL_OPTIONS = [ + "Piedra Caliza", + "Durmientes de Madera", + "Malla de Acero", +] + +st.header("Add a new material") +with st.form("add_material"): + name = st.selectbox("Material", MATERIAL_OPTIONS) + qty = st.number_input("Initial quantity", min_value=0, step=1, value=0) + submitted = st.form_submit_button("Add/Update") + if submitted: + current = st.session_state.materials.get(name, 0) + st.session_state.materials[name] = current + int(qty) + +if st.session_state.materials: + st.header("Adjust stock") + with st.form("adjust_stock"): + material = st.selectbox("Select material", list(st.session_state.materials.keys())) + delta = st.number_input("Add/Subtract quantity", value=0, step=1, format="%d") + adjust = st.form_submit_button("Apply") + if adjust: + st.session_state.materials[material] += int(delta) + if st.session_state.materials[material] < 0: + st.session_state.materials[material] = 0 + + st.header("Current stock") + df = pd.DataFrame({ + 'Material': list(st.session_state.materials.keys()), + 'Quantity': list(st.session_state.materials.values()) + }) + st.dataframe(df.set_index('Material')) + st.bar_chart(df.set_index('Material')) +else: + st.info("No materials in stock. Add materials above.")