How dev-festival/insy7970-sensor-data works
Purpose and Runtime
INSY Sensor Data is a Python 3.13 service for collecting Waites vibration/temperature data, preserving raw evidence, producing daily sensor snapshots and trends, and exposing those artifacts through a CLI and FastAPI. The package is managed with uv; local filesystem storage is the active persistence boundary. Maximo maintenance integration and clustering are scaffolded but not yet active capabilities.
Primary entry points: main.py, src/insy_sensor_data/cli.py, and src/insy_sensor_data/api/main.py.
Dual Application Surfaces
The Typer CLI is the canonical automation interface for fetch, validation, raw lifecycle, snapshot/trend builds, health, and serving the API. FastAPI is the canonical service interface, intended to reuse the same core modules rather than duplicate pipeline logic.
• CLI orchestration: src/insy_sensor_data/cli.py
• API app factory: src/insy_sensor_data/api/main.py
• Runtime configuration: src/insy_sensor_data/config.py
Waites Ingestion Boundary
Waites is the first external integration. Fetching supports deterministic fixture-backed mock data and opt-in live API requests authenticated from environment configuration. The client/fetch layer writes endpoint responses as raw evidence rather than treating remote payloads as directly processed data.
• HTTP/source client: src/insy_sensor_data/waites/client.py
• Fetch orchestration: src/insy_sensor_data/waites/fetch.py
• Mock source fixtures: src/insy_sensor_data/waites/fixtures.py
Live access depends on WAITES_BASE_URL and WAITES_ACCESS_TOKEN; tests remain mock-first and do not require plant-network, DB2, or ODBC access.
Raw Evidence and Validation Gate
Raw Waites runs are organized by date under data/raw/waites/date=YYYY-MM-DD/. Each run includes endpoint artifacts and manifests with byte counts and SHA-256 checksums; secrets are excluded. The lifecycle supports verification, gzip compression, and dry-run-first pruning. Shape validation writes validation.json beside raw data and forms a hard gate for API-source snapshot processing.
• Raw lifecycle operations: src/insy_sensor_data/raw_lifecycle.py
• Payload validation: src/insy_sensor_data/waites/validate.py
• Artifact/manifest handling: src/insy_sensor_data/artifacts.py
Processing: References, Snapshots, and Trends
Processed Waites reference data is stored separately from raw evidence. Snapshot construction converts a validated daily source run into daily, sensor-oriented outputs under data/processed/snapshots/. Trend construction reads a date range of snapshots and emits trend-ready results under data/processed/trends/; API trends only consume snapshots explicitly marked with API source metadata.
• Snapshot build stage: src/insy_sensor_data/snapshots/build.py
• Trend build stage: src/insy_sensor_data/snapshots/trends.py
• Storage abstraction and paths: src/insy_sensor_data/storage.py
Read-Service and Static UI
The API is a read/visibility boundary over generated artifacts: health, available dates, raw Waites runs, individual snapshots, and date-ranged trends. It also serves a small static browser shell; it is not the ingestion control plane.
• API routes: src/insy_sensor_data/api/routes/waites.py, src/insy_sensor_data/api/routes/snapshots.py, src/insy_sensor_data/api/routes/trends.py
• Date discovery and health: src/insy_sensor_data/api/routes/dates.py, src/insy_sensor_data/api/routes/health.py
• Static client: src/insy_sensor_data/api/static/index.html
Future Integration Boundaries
The repository reserves modules for correlating sensor outputs with maintenance history and for clustering/analysis, likely downstream of normalized snapshots and joins. Their presence defines intended extension points, not current runtime workflows.
• Sensor/maintenance joins: src/insy_sensor_data/joins.py
• Maximo boundary: src/insy_sensor_data/maximo/__init__.py
• Clustering boundary: src/insy_sensor_data/clustering/__init__.py
Main entry points: cli.py Typer CLI · snapshots.py API routes · fetch.py Fetch orchestration · main.py FastAPI app factory
Components 20
Application Surfaces
- Typer CLI · Canonical control plane for pipeline operations and API serving.
src/insy_sensor_data/cli.py - Runtime configuration · Supplies environment-backed live Waites settings.
src/insy_sensor_data/config.py
Waites Ingestion
- Waites client · Uses fixtures by default or opt-in authenticated live requests.
src/insy_sensor_data/waites/client.py - Mock fixtures
src/insy_sensor_data/waites/fixtures.py - Fetch orchestration · Captures endpoint responses as evidence.
src/insy_sensor_data/waites/fetch.py
Evidence & Processing
- Artifacts & manifests · Records byte counts and SHA-256 checksums without secrets.
src/insy_sensor_data/artifacts.py - Raw Waites evidence · Date-partitioned endpoint artifacts and manifests.
- Raw lifecycle · Verifies, compresses, and dry-run prunes raw runs.
src/insy_sensor_data/raw_lifecycle.py - Payload validation · Writes validation.json and gates API-source snapshot processing.
src/insy_sensor_data/waites/validate.py - Storage abstraction · Owns processed-data paths and artifact access.
src/insy_sensor_data/storage.py - Daily snapshots · Builds sensor-oriented daily outputs from validated runs.
src/insy_sensor_data/snapshots/build.py - Snapshot artifacts · Daily sensor outputs.
- Trend builder · Reads date-ranged snapshots, restricted to API-marked sources.
src/insy_sensor_data/snapshots/trends.py - Trend artifacts · Trend-ready date-range results.
Read Service
- FastAPI app factory · Read-only visibility boundary over generated artifacts.
src/insy_sensor_data/api/main.py - API routes · Exposes health, dates, raw runs, snapshots, and trends.
src/insy_sensor_data/api/routes/snapshots.py - Static browser shell
src/insy_sensor_data/api/static/index.html
Future Boundaries
Reserved extension points, not active workflows.
- Sensor-maintenance joins · Planned downstream join over normalized snapshots.
src/insy_sensor_data/joins.py - Maximo boundary
src/insy_sensor_data/maximo/__init__.py - Clustering boundary
src/insy_sensor_data/clustering/__init__.py
Connections 28
- Typer CLI → Fetch orchestration: runs
- Typer CLI → Raw lifecycle: operates
- Typer CLI → Payload validation: runs
- Typer CLI → Daily snapshots: builds
- Typer CLI → Trend builder: builds
- Typer CLI → FastAPI app factory: serves
- Runtime configuration → Waites client: live credentials
- Mock fixtures → Waites client: mock source
- Waites client → Fetch orchestration: retrieves payloads
- Fetch orchestration → Artifacts & manifests: creates manifests
- Fetch orchestration → Raw Waites evidence: writes responses
- Artifacts & manifests → Raw Waites evidence: records alongside
- Raw lifecycle → Raw Waites evidence: verifies and manages
- Raw Waites evidence → Payload validation: validates shapes
- Payload validation → Daily snapshots: validated API runs
- Storage abstraction → Snapshot artifacts: accesses
- Storage abstraction → Trend artifacts: accesses
- Daily snapshots → Snapshot artifacts: writes daily outputs
- Snapshot artifacts → Trend builder: reads date range
- Trend builder → Trend artifacts: writes results
- FastAPI app factory → API routes: mounts
- FastAPI app factory → Static browser shell: serves
- API routes → Raw Waites evidence: lists runs
- API routes → Snapshot artifacts: reads snapshots and dates
- API routes → Trend artifacts: reads trends
- Snapshot artifacts → Sensor-maintenance joins: future input
- Maximo boundary → Sensor-maintenance joins: future maintenance history
- Snapshot artifacts → Clustering boundary: future input