No description
Find a file
Markus Walther a5c6661308 .
2026-04-14 17:54:16 +02:00
.github multi-quarter and mulri-month added 2025-12-03 15:16:40 +01:00
.vscode initial commit 2025-11-10 00:00:05 +01:00
js . 2026-04-14 17:54:16 +02:00
.gitignore + gitignore 2025-11-10 00:44:17 +01:00
Auschussauswertung_Version27032026.html . 2026-04-14 17:54:16 +02:00
ausschuss_arbeitsschritte.xls initial commit 2025-11-10 00:00:05 +01:00
mainprobe4.py multi-quarter and mulri-month added 2025-12-03 15:16:40 +01:00
pyproject.toml callability, instructions 2025-11-10 01:38:38 +01:00
README.md multi-quarter and mulri-month added 2025-12-03 15:16:40 +01:00
reject_type_colors.json fixed date errors in datetime parsing 2025-11-10 01:01:05 +01:00
uv.lock initial commit 2025-11-10 00:00:05 +01:00

Ausschussauswertung (Manufacturing Reject Analysis)

A Python tool for analyzing and visualizing manufacturing reject/defect data. Generates comprehensive monthly stacked bar charts showing reject percentages by type, batch, and product color with quarterly summaries and statistical analysis.

Features

Visualization Capabilities

  • 100% Stacked Bar Charts: Shows reject percentages across batches, production colors, and time periods
  • Quarterly Summaries: Automatic quarterly boundaries with detailed statistics
  • Summary Bars: Average, variance, and trend analysis
  • Persistent Color Mapping: Consistent colors for reject types across multiple runs
  • Dynamic Layout: Automatically adjusts spacing to prevent textbox overlaps
  • Month Dividers: Dotted black lines between month changes for easier reading
  • Color Splitting: Generate separate diagrams for each production color with --split-by-color
  • Y-Axis Scaling: Flexible scaling options:
    • Fixed 0-100% scale (default)
    • Per-diagram auto-scale with 10% padding (--per-diagram-y-scale)
    • Global scale across all diagrams (--global-y-scale)
    • Manual maximum (--max-y VALUE)
  • German Titles: Diagram titles automatically reflect product, color, and time period in German

Statistical Analysis

  • Quarterly Statistics: For each reject type shows:
    • Total percentage in quarter
    • Change from previous quarter (Δ symbol)
    • Variance across batches (σ symbol)
    • Production total (Produktion) in textbox header
  • Summary Bars:
    • Quartalsdurchschnitt (red): Average per quarter
    • Durchschnittsdelta (dark blue): Quarter-over-quarter change (can be negative)
    • Durchschnittssigma (purple): Standard deviation within quarter
    • Gesamtdurchschnitt (red): Overall average
    • Gesamtsigma (dark orange): Overall standard deviation
  • Overall Summary Box: Highlights top reject types with their averages, sigma values, and total production quantity
  • Diverging Charts: Delta bars with mixed positive/negative values stack properly - positive values above zero line, negative values below
  • Disappeared Types: Types that existed in previous quarter but not current are shown with 0%, correct negative delta, and σ--

Data Processing

  • Filters out non-defect types (samples, test specimens)
  • Handles missing/invalid dates gracefully
  • Supports multiple product groups (generates separate charts)
  • Time-series sorting with chronological progression

Requirements

  • Python 3.13+
  • Dependencies (see pyproject.toml):
    • pandas >= 2.3.3
    • matplotlib >= 3.10.7
    • numpy >= 2.3.4
    • xlrd >= 2.0.2 (for .xls file support)

Installation

uv is a fast Python package installer and resolver. It's the recommended way to run this project.

Installing uv

Windows (PowerShell):

powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

Linux/macOS:

curl -LsSf https://astral.sh/uv/install.sh | sh

After installation, restart your terminal or run:

  • Windows: refreshenv (if using Chocolatey) or restart PowerShell
  • Linux/macOS: source $HOME/.cargo/env

First Time Setup (New Clone/Archive)

  1. Extract the archive or clone the repository:
git clone <repository-url>
cd Ausschussauswertung
  1. Run the analysis with uv (it will automatically install dependencies):
uv run mainprobe4.py

That's it! uv will automatically:

  • Detect the Python version requirement from pyproject.toml
  • Create a virtual environment (if needed)
  • Install all dependencies
  • Run the script

Subsequent Runs

After the first run, simply use:

uv run mainprobe4.py

Alternative: Traditional pip Installation

If you prefer using pip:

pip install -e .

Then run:

python mainprobe4.py

System-Wide Installation

To install the program so it can be called from anywhere on your system:

Windows (PowerShell):

# Install using uv
uv tool install .

# Now you can run from anywhere:
ausschussauswertung --help
ausschussauswertung --excel C:\path\to\data.xls

Linux/macOS:

# Install using uv
uv tool install .

# Now you can run from anywhere:
ausschussauswertung --help
ausschussauswertung --excel /path/to/data.xls

Using pip

Windows (PowerShell):

# Install in user space (recommended)
pip install --user .

# Add Python Scripts directory to PATH if not already done:
# For Python 3.12: C:\Users\<YourUsername>\AppData\Roaming\Python\Python312\Scripts
# For Python 3.13: C:\Users\<YourUsername>\AppData\Roaming\Python\Python313\Scripts

# Or install system-wide (requires admin):
pip install .

# Run from anywhere:
ausschussauswertung --help

Linux/macOS:

# Install in user space (recommended)
pip install --user .

# Make sure ~/.local/bin is in your PATH
export PATH="$HOME/.local/bin:$PATH"

# Add the above line to ~/.bashrc or ~/.zshrc to make it permanent

# Or install system-wide (requires sudo):
sudo pip install .

# Run from anywhere:
ausschussauswertung --help

Note: For system-wide installation, the project includes a script entry point in pyproject.toml:

[project.scripts]
ausschussauswertung = "mainprobe4:main"

This is already configured and allows you to run mainprobe4 as a command after installation.

Uninstalling

Using uv:

uv tool uninstall ausschussauswertung

Using pip:

pip uninstall ausschussauswertung

Usage

With default settings:

uv run mainprobe4.py

With custom Excel file:

uv run mainprobe4.py --excel path/to/your/data.xls

Excluding specific reject types:

uv run mainprobe4.py --exclude "Rückstellmuster" "Prüfkörperentnahme" "Muster"

Combining options:

uv run mainprobe4.py --excel data.xls --exclude "Rückstellmuster"

Generate diagram for specific time period:

# All data (default)
uv run mainprobe4.py --total

# Specific quarter (e.g., Q2 2025)
uv run mainprobe4.py --quarter 2_25

# Specific month (e.g., November 2024)
uv run mainprobe4.py --month 11_24

# All quarters found in data
uv run mainprobe4.py --all-quarters

# All months found in data
uv run mainprobe4.py --all-months

# Combine multiple time periods (all options can be combined)
uv run mainprobe4.py --total --all-quarters --all-months
uv run mainprobe4.py --quarter 2_25 4_25 --month 11_24

# Multiple quarters or months in one diagram
uv run mainprobe4.py --multi-quarter 1_24-3_24
uv run mainprobe4.py --multi-month 6_24-9_24 5_25-8_25  # Two diagrams with ranges

# Split diagrams by production color
uv run mainprobe4.py --split-by-color
uv run mainprobe4.py --month 11_24 --split-by-color

# Control y-axis scaling
# Default: fixed 0-100% scale
uv run mainprobe4.py --per-diagram-y-scale  # Independent scaling per diagram
uv run mainprobe4.py --global-y-scale       # Same scale for all diagrams
uv run mainprobe4.py --max-y 30  # Fixed maximum at 30%

# Filter by specific products
uv run mainprobe4.py --products "Ivotion Base" "Telio CAD"

# Organize output into product folders
uv run mainprobe4.py --use-folders
uv run mainprobe4.py --products "Ivotion Base" --use-folders --all-quarters

View all available options:

uv run mainprobe4.py --help

Command Line Arguments

Argument Description Default
--excel FILE Path to Excel file (.xls format) ausschuss_arbeitsschritte.xls
--exclude TYPE [TYPE ...] Reject types to exclude (space-separated) Rückstellmuster Prüfkörperentnahme
--no-exclude Do not exclude any reject types (overrides --exclude defaults) -
--total Generate diagram for all data Default if no time option specified
--quarter Q_YY [Q_YY ...] Generate diagram for specific quarter(s) (format: Q_YY, e.g., "2_25" for Q2 2025). Can specify multiple. -
--month M_YY [M_YY ...] Generate diagram for specific month(s) (format: M_YY, e.g., "11_24" for Nov 2024). Can specify multiple. -
--all-quarters Generate diagrams for all quarters found in the data -
--all-months Generate diagrams for all months found in the data -
--multi-quarter Q_YY-Q_YY [...] Generate diagram(s) for quarter range(s) (format: Q_YY-Q_YY, e.g., "1_24-3_24" for Q1-Q3 2024). Can specify multiple ranges. -
--multi-month M_YY-M_YY [...] Generate diagram(s) for month range(s) (format: M_YY-M_YY, e.g., "6_24-9_24" for Jun-Sep 2024). Can specify multiple ranges. -

Note: Time period options can be combined. For example, you can use --total --all-quarters --month 11_24 to generate a total overview, all quarterly diagrams, and a specific month diagram in one run. Use --multi-quarter or --multi-month to span multiple consecutive periods in a single diagram. | --split-by-color | Generate separate diagrams for each production color | - | | --products PRODUCT [PRODUCT ...] | Generate diagrams only for specified products (space-separated) | All products | | --use-folders | Organize output into separate folders per product | - | | --per-diagram-y-scale | Scale each diagram independently with 10% padding | - | | --global-y-scale | Use consistent y-axis scaling across all diagrams | - | | --max-y VALUE | Set manual maximum for y-axis (e.g., 30 for 30%) | - | | -h, --help | Show help message and exit | - |

Alternative (Using Python Directly)

If you installed with pip:

python mainprobe4.py

Input Data Format

Your Excel file should contain these columns:

  • batchnumber: Batch identifier
  • creationdate: Date of production/defect occurrence
  • productioncolor: Production color/marking identifier
  • rejecttypedesc: Description of the reject/defect type
  • quantity: Number of rejects of this type
  • sum_batch_qty: Total quantity in the batch
  • productionarticlegroup: (Optional) Product group for splitting charts

Excluding Non-Defect Types

Some entries may not represent actual defects (e.g., samples for testing). You can exclude these using the --exclude command line argument:

Using command line (recommended):

uv run mainprobe4.py --exclude "Rückstellmuster" "Prüfkörperentnahme" "TestType"

Default excluded types:

  • Rückstellmuster (Retention samples)
  • Prüfkörperentnahme (Test specimen extraction)

To exclude no types:

uv run mainprobe4.py --no-exclude

Or use empty --exclude:

uv run mainprobe4.py --exclude

Alternatively, modify the code:

  1. Open mainprobe4.py
  2. Find the default= parameter in the --exclude argument definition
  3. Modify the list as needed

Output Files

The tool generates:

  • PNG Charts: One per product group (or single file if no groups)
    • Format depends on time period option:
      • Total (default): ausschuss_stacked_monthly_{productgroup}_total.png
      • Quarter: ausschuss_stacked_monthly_{productgroup}_quarter{Q_YY}.png
        • Example: ausschuss_stacked_monthly_Ivotion_Base_quarter2_25.png (Q2 2025)
      • Month: ausschuss_stacked_monthly_{productgroup}_month{M_YY}.png
        • Example: ausschuss_stacked_monthly_Ivotion_Base_month11_24.png (Nov 2024)
      • Quarter Range: ausschuss_stacked_monthly_{productgroup}_quarters{Q_YY-Q_YY}.png
        • Example: ausschuss_stacked_monthly_Ivotion_Base_quarters1_24-3_24.png (Q1-Q3 2024)
      • Month Range: ausschuss_stacked_monthly_{productgroup}_months{M_YY-M_YY}.png
        • Example: ausschuss_stacked_monthly_Ivotion_Base_months6_24-9_24.png (Jun-Sep 2024)
    • With --use-folders: Files organized into product-specific subdirectories
      • Example: Ivotion_Base/ausschuss_stacked_monthly_Ivotion_Base_quarter2_25.png
    • With --split-by-color: Color suffix is added before period suffix
      • Example: ausschuss_stacked_monthly_Telio_CAD_B55_M1_B55_A3_month11_24.png
    • If no product groups: ausschuss_stacked_monthly_total.png, ausschuss_stacked_monthly_quarter2_25.png, etc.
  • Color Map: reject_type_colors.json (maintains consistent colors across runs)

Understanding the Charts

Chart Elements

  1. Stacked Bars: Each bar represents a batch/color combination for a specific month

    • X-axis format: productioncolor | batchnumber | YYYY-MM
    • Includes batch size below each bar
    • Y-axis: Percentage of rejects (auto-scaled with 10% padding, or fixed with --max-y)
    • Bar segments: Different reject types (stacked)
    • Month dividers: Dotted black vertical lines between month changes
  2. Quarterly Textboxes (white background):

    • Shows top 5 reject types for the quarter
    • Format: Type X.X%, ΔChange, σ±Variance
    • Example: "Rückstellmuster 2.3%, Δ+0.4, σ±0.3"
      • 2.3% = Total percentage in quarter
      • Δ+0.4 = Increased by 0.4% from last quarter
      • σ±0.3 = Standard deviation of ±0.3%
  3. Summary Bars (at quarter ends and overall):

    • Quartalsdurchschnitt (red label): Average for the quarter
    • Durchschnittsdelta (dark blue label): Change from previous quarter
      • Can show negative values (bars extend below y=0 for decreases)
      • Y-axis automatically adjusts with 10% buffer
    • Durchschnittssigma (purple label): Standard deviation within the quarter
    • Gesamtdurchschnitt (red label): Overall average
    • Gesamtsigma (dark orange label): Overall standard deviation
  4. Overall Summary Box (light yellow background):

    • Positioned above the overall summary bars
    • Shows top reject types across entire analysis period
    • Format: Type X.X%, σ±Sigma
  5. Visual Separators:

    • Red dashed lines: Between quarters
    • Gray dotted lines: Before quarterly summary bars
    • Blue solid line: Before overall average
    • Purple dotted line: Before overall sigma
    • Black dotted lines: Between month changes
    • Black horizontal line at y=0: Shown when delta bars have negative values
  6. Legend: Positioned at bottom-right to avoid overlap with quarterly textboxes

  7. Title: German title showing:

    • Product name and color (if using --split-by-color)
    • Time period: "Quartal Q/YYYY", "MonthName YYYY", "Quartale Q/YYYY - Q/YYYY", "MonthName YYYY - MonthName YYYY", or "Gesamtübersicht"
    • Subtitle: "Monatlich gruppiert, gestapelt nach Ausschusstyp"
    • Range diagrams (from --multi-quarter or --multi-month) show all data within the specified range with quarterly statistics

Reading the Statistics

  • Δ (Delta): Change indicator

    • Δ+0.4: Increased by 0.4 percentage points
    • Δ-0.2: Decreased by 0.2 percentage points
    • Δ--: First quarter (no previous data)
  • σ (Sigma): Standard deviation indicator

    • σ±0.3: Standard deviation of 0.3%
    • Low values = consistent across batches
    • High values = high variability between batches
    • Appears in quarterly textboxes (variability within quarter)
    • Also shown in "Durchschnittssigma" bars and overall summary

Configuration

Customizing the Analysis

Edit parameters in the plot_stacked_by_type_monthly() call in main():

plot_stacked_by_type_monthly(
    df_sub,
    max_types_in_summary=5,      # Number of top types to show in textboxes
    min_quarter_width=3,         # Minimum width for quarters (in bars, reduced from 5)
    exclude_types=exclude_types, # Types to exclude from analysis
    max_y_value=global_max_y,    # Manual y-axis maximum (None for auto)
    period_type="month",         # "total", "quarter", or "month"
    period_value=pd.Period("2024-11"),  # Period object for title
    product_name="Ivotion Base", # Product name for title
    color_name="MULTI_A1",       # Color name for title (None if not split)
    # ... other parameters
)

Color Persistence

The reject_type_colors.json file stores color assignments for reject types to ensure consistency across multiple analysis runs:

How it works:

  • Each reject type is automatically assigned a unique color on first encounter
  • Colors are saved in HEX format (e.g., #1F77B4)
  • The mapping persists across runs, so the same reject type always gets the same color
  • This is crucial for comparing charts over time - you can rely on colors to identify types

Automatic color assignment:

  • Colors are drawn from matplotlib's tab20, tab20b, and tab20c colormaps
  • If more colors are needed, additional colors are generated from the HSV color space
  • Assignment is deterministic (alphabetically sorted reject types get colors in order)

Manual customization: You can manually edit reject_type_colors.json to assign specific colors to reject types:

{
  "Porös": "#FF0000",
  "Lunker/Blasen": "#00FF00",
  "Farbausschuss": "#0000FF"
}

Finding color codes:

Resetting colors:

  • Delete reject_type_colors.json to reset all color assignments
  • Next run will generate new automatic assignments

Troubleshooting

Common Issues

"Fehlende Spalten im DataFrame"

  • Ensure your Excel file has all required columns
  • Check column names match exactly (case-sensitive)

Invalid dates warning

  • Some rows have invalid or missing creationdate values
  • These rows are sorted to the end but still included in charts

Charts look cramped

  • Increase min_quarter_width parameter
  • Reduce number of batches by filtering data
  • Split analysis by product groups

Colors changed unexpectedly

  • Delete reject_type_colors.json to reset
  • Or manually edit the JSON file to set specific colors (HEX format)

"ausschussauswertung: command not found" after installation

On Windows:

  • The Scripts folder may not be in your PATH
  • Add to PATH: C:\Users\<YourUsername>\AppData\Roaming\Python\Python313\Scripts
  • Or run using: python -m mainprobe4 instead

On Linux/macOS:

  • Add to PATH: export PATH="$HOME/.local/bin:$PATH"
  • Add the above line to ~/.bashrc or ~/.zshrc to make it permanent
  • Or run using: python -m mainprobe4 instead

Running as module (alternative)

If the command doesn't work, you can always run it as a Python module:

python -m mainprobe4 --help
python -m mainprobe4 --excel data.xls

File Structure

.
├── mainprobe4.py                    # Main analysis script
├── reject_type_colors.json          # Persistent color mappings
├── ausschuss_arbeitsschritte.xls    # Input data (your file)
├── ausschuss_stacked_monthly_*.png  # Output charts
├── pyproject.toml                   # Project dependencies
└── README.md                        # This file

License

This project is for internal use. All rights reserved.

Support

For questions or issues, please contact the development team or refer to the .github/copilot-instructions.md for technical details.