Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/kishnahai0806/SteelWorks/llms.txt

Use this file to discover all available pages before exploring further.

SteelWorks is a single-page Streamlit dashboard that surfaces weekly manufacturing operations issue metrics stored in PostgreSQL. The page is laid out in a top-to-bottom flow: a title and caption at the top, followed by three filter controls (week selector, production-lines multiselect, and a group-by-line checkbox), then two data tables (Issue Summary and Affected Lots), each paired with a CSV download button. All data is scoped to the week and lines selected — changing a filter immediately re-runs every query and re-renders both tables.

Page configuration

The page is bootstrapped with a wide layout so both tables can expand across the full browser viewport:
st.set_page_config(page_title="Operations Issue Metrics", layout="wide")
st.title("Operations Issue Metrics")
st.caption("Filter by week and production line to review issue trends.")

Data flow

Every render cycle follows these steps in order:
1

Resolve DATABASE_URL

_resolve_database_url() calls load_dotenv() then reads DATABASE_URL from the environment. If the variable is empty the app renders an st.error and returns early.
2

Create and cache the service

_cached_service(database_url) is decorated with @st.cache_resource(show_spinner=False), so the OperationsRepository (SQLAlchemy engine) and OperationsMetricsService are constructed only once per process. Subsequent renders reuse the cached instance. The decorated function delegates to _build_service():
def _build_service(database_url: str) -> OperationsMetricsService:
    repository = OperationsRepository.from_database_url(database_url=database_url)
    return OperationsMetricsService(repository=repository)

@st.cache_resource(show_spinner=False)
def _cached_service(database_url: str) -> OperationsMetricsService:
    return _build_service(database_url=database_url)
3

Load filter options

service.get_available_weeks() returns calendar weeks ordered by start_date.
service.get_available_lines() returns only active lines (is_active = TRUE), ordered by line_name.
Results are converted into label-to-ID mappings used by the Streamlit widgets.
4

Render filter widgets

Three controls are rendered: a st.selectbox for the production week, a st.multiselect for production lines (all selected by default), and a st.checkbox for grouping the summary by line.
5

Build IssueFilterSelection

User selections are packaged into a frozen IssueFilterSelection dataclass before being passed to the service layer.
selection = IssueFilterSelection(
    calendar_week_id=week_label_to_id[selected_week_label],
    production_line_ids=[line_name_to_id[name] for name in selected_line_names],
)
6

Fetch data from the service

Two calls are made back-to-back:
issue_summary = service.get_issue_summary(selection=selection, group_by_line=group_by_line)
affected_lots = service.get_affected_lots(selection=selection)
7

Render tables and download buttons

Each dataset is displayed with st.dataframe(rows, hide_index=True, use_container_width=True). A row count and (for the summary) a total issue count are written below the table. An st.download_button for each CSV follows immediately after its table.

Error handling

The app has five guarded error paths, all of which halt rendering early:
ConditionStreamlit call
DATABASE_URL is missing or emptyst.error("DATABASE_URL is not set. Add it to \.env` before starting the app.”)`
Database connection or service init failsst.error(f"Unable to initialize database connection: {exc}")
Loading weeks or lines raises an exceptionst.error(f"Unable to load filter values: {exc}")
Weeks list is empty after successful loadst.warning("No weeks found in the database.")
Lines list is empty after successful loadst.warning("No active production lines found in the database.")
The first three are st.error (hard failures); empty-data conditions use st.warning to signal a data-population issue rather than a system fault.

Explore further

Filters

Week selector, production-lines multiselect, group-by-line checkbox, and how selections are translated into IssueFilterSelection objects.

Issue Summary

Issue counts per type — optionally broken down per production line — with total issue count and per-line toggle.

Affected Lots

Per-lot issue breakdown showing lot code, issue count, and comma-separated issue types for every affected production lot.

CSV Exports

One-click downloads for both tables, always reflecting the current week and line filter selection.

Build docs developers (and LLMs) love