StarModel 邀请活动
← 返回 Skill 列表
extension
分类: 数据与分析无需 API Key

cpk-init

初始化项目(扫描CSV、分类列、配置追踪目标)

person作者: user_2009fc2chubcommunity

CPK Init - Project Initialization

Initialize a manufacturing CPK tracking project from CSV test data.

When to Use

  • Setting up CPK monitoring for a new production line or station
  • Analyzing manufacturing test data for the first time
  • Creating a .auto_cpk project configuration from existing CSV files

Prerequisites

  1. Install auto_cpk package:

    pip install -e /path/to/autoCPK
    

    Dependencies: pandas>=2.0, numpy>=1.24, scipy>=1.10, plotly>=5.15

  2. Prepare CSV data — Preferred manufacturing test CSV with multi-row header:

    • Row 1: Station type header
    • Row 2: Column names (Site, Product, SerialNumber, Channel ID, Station ID, Result, StartTime, EndTime, Item1..ItemN)
    • Row 3: UpLimit values (upper spec limits)
    • Row 4: LowLimit values (lower spec limits)
    • Row 5: Unit values (engineering units)
    • Row 6+: Measurement data rows

    Sentinel values: 999999999999 or -1.00E+12 in spec limits means no bound on that side.

    Non-standard CSVs are adapted during cpk-init. The built-in parser may propose a lightweight starting profile, but convergence should primarily come from the skill inspecting the sample, discussing ambiguous fields with the user, and supplying or refining a CsvSourceProfile.

How to Invoke

from auto_cpk.skills.cpk_init import run_init

result = run_init(
    data_folder="./data_demo",           # Directory containing CSV files
    config_path=".auto_cpk/config.json", # Where to save config
    db_path=".auto_cpk/auto_cpk.sqlite", # Where to create database
)

For non-interactive (AI agent) usage, provide a UserInput implementation:

from auto_cpk.skills.cpk_init import run_init, UserInput
from auto_cpk.core.models import MeasurementItem, ProjectConfig

class AgentInput:
    def choose_items(self, eligible):
        return eligible  # Track all eligible items

    def choose_group_by(self, metadata_columns):
        return ["Station ID", "Channel ID"]  # Default grouping

    def choose_period(self):
        return "weekly"

    def choose_sigma_mode(self):
        return "overall"

    def confirm(self, config):
        return True

result = run_init(
    data_folder="./data",
    user_input=AgentInput(),
)

If the CSV format is known but cannot be inferred safely, pass an explicit CsvSourceProfile to keep the adaptation converged in init:

from auto_cpk.core.models import CsvSourceProfile

profile = CsvSourceProfile(
    header_row_index=0,
    data_start_row_index=4,
    usl_row_index=1,
    lsl_row_index=2,
    unit_row_index=3,
    metadata_mode="named",
    metadata_columns=["SerialNumber", "Station ID", "Channel ID", "StartTime"],
    column_aliases={
        "SN": "SerialNumber",
        "StationID": "Station ID",
        "Start": "StartTime",
    },
)

result = run_init(data_folder="./data", source_profile=profile)

Output

Returns an InitResult with:

  • config: ProjectConfig object with all tracked targets
  • config_path: Path to saved JSON config (.auto_cpk/config.json)
  • db_path: Path to SQLite database (.auto_cpk/auto_cpk.sqlite)
  • source_profile: Inferred or supplied CSV parsing profile persisted into config
  • source_audit: Init-time data source acceptance report
  • eligible_items: All eligible measurement items found
  • tracked_count: Number of items being tracked

The saved config includes source_profile. Later cpk-track runs must consume that profile and must not rediscover or mutate CSV parsing logic.

Source Adaptation Boundary

All source-format adaptation belongs to cpk-init:

  • Infer, ask for, or LLM-generate a CsvSourceProfile for header row, data start row, USL/LSL/unit rows, metadata aliases, delimiter, encoding, and sentinel handling.
  • Persist the accepted profile to .auto_cpk/config.json.
  • Update auto_cpk/core/csv_parser.py only when the profile mechanism itself lacks a reusable capability. Prefer a small profile or narrow parser hook over adding a large rule tree.
  • Do not spread format discovery into cpk-track or cpk-analyze; execution stages only use the profile produced by init.

Dynamic Convergence Principle

The skill should not try to encode every supplier or station CSV variant as hard-coded rules. The intended loop is:

  1. Inspect a representative CSV sample and propose a minimal profile.
  2. If a field is ambiguous, ask the user or state the assumption.
  3. Run cpk-init acceptance checks.
  4. Refine the profile or make a narrow csv_parser.py capability patch only if validation shows a real gap.
  5. Stop when source audit passes and the accepted profile is saved.

The code is the acceptance gate; the LLM/user interaction is the adaptation engine. This keeps parsing convergence flexible without making the runtime pipeline brittle or over-constrained.

Source Acceptance Checklist

cpk-init must actively verify and report the source contract before saving:

  • All measurement items are discovered and have test value summaries (non_null_count, numeric_count, unique count, sample values).
  • Each item captures USL, LSL, and unit row data when present.
  • PASS/FAIL or non-numeric attribute columns are identified and excluded from CPK eligibility.
  • Grouping metadata columns expose value summaries, especially selected group_by columns such as Station ID and Channel ID.
  • StartTime exists and has parseable timestamps.
  • Selected CPK items have numeric test values and two-sided spec limits.

Hard acceptance failures are reserved for fields that would break later stages: missing or unparseable StartTime, selected group columns with no values, selected items with no numeric test values, selected CPK items missing USL/LSL, or no eligible two-sided continuous measurement columns.

Other problems are still surfaced in source_audit as diagnostics or item issues: missing units, single-sided specs, no-bound columns, attribute columns, or non-selected metadata columns with sparse values.

Column Classification Rules

The init skill automatically classifies each CSV column:

| Classification | Criteria | CPK Eligible? | |---------------|----------|---------------| | Metadata | First 8 columns (Site, Product, SerialNumber, etc.) | No | | Metadata | Named columns mapped by source profile aliases | No | | Attribute | Contains only PASS/FAIL values | No | | Continuous | Numeric data | Yes, if two-sided spec | | Single-sided | Only USL or only LSL defined | No | | No bound | Neither USL nor LSL defined | No |

Only continuous columns with two-sided specification limits are eligible for CPK calculation.

Configuration Parameters

| Parameter | Default | Description | |-----------|---------|-------------| | group_by | ["Station ID", "Channel ID"] | Columns to group data for within-subgroup Cp/Cpk | | period | "weekly" | Time window: daily/weekly/monthly/quarterly | | min_sample_count | 100 | Minimum data points per group for valid CPK | | sigma_basis | "overall" | overall for Pp/Ppk, within for Cp/Cpk |

Edge Cases

  • No eligible columns: If no two-sided continuous columns exist, init will raise an error
  • Sentinel spec values: 999999999999 or extreme negative values in spec limits are treated as "no bound"
  • PASS/FAIL columns: Automatically detected and excluded from CPK analysis
  • Empty data folder: Raises FileNotFoundError

Next Steps

After initialization, use cpk-track to import data and compute CPK, then cpk-analyze to generate reports and alerts.

CPK Domain Knowledge

Cpk (Process Capability Index) measures how well a stable manufacturing process fits within specification limits:

  • Cpk = min[(USL - mu)/(3sigma), (mu - LSL)/(3sigma)]
  • Cpk >= 1.33: Process is capable (industry standard baseline)
  • Cpk >= 1.67: Excellent capability (critical characteristics)
  • Cpk < 1.0: Process is not capable — corrective action needed

Prerequisites for valid Cpk:

  • Data must be continuous (not pass/fail)
  • Process must be in statistical control (stable)
  • Measurement system must be validated (MSA)
  • Sufficient sample size (100+ recommended)