mineproductivity.analytics¶
Purpose¶
Statistical and analytical processing built on top of KPI and event data — trend analysis, correlation, and descriptive analytics.
Scope¶
What belongs here:
- Analytical model interfaces and pipeline contracts.
- Descriptive/statistical analysis built strictly on kpis and events outputs.
What must never belong here:
- Optimization or prescriptive logic (see optimization, decision).
- Direct connector or I/O access — analytics consumes projections, not raw sources.
Responsibilities¶
- Implements the
analyticssubsystem as defined in the Reference Implementation Blueprint v1.0. - Implements the full module list from design spec §6: the Analytics Foundation (entities,
value objects, metadata, enums, exception hierarchy), Metric Pipelines & Aggregation,
Statistical Primitives, Rolling Analytics, Trend Analysis, Baseline Analysis,
Benchmark Analysis, Data Quality & Missing Data Handling, all three interface-only
extension points -- the Forecasting Framework, the Anomaly Detection Framework, and the
Outlier Detection Framework -- all three Execution Modes (batch, streaming,
incremental) slices, and the Registry & Plugin Framework (§32–§33).
ForecastingModel,AnomalyDetector, andOutlierDetectoreach ship zero concrete subclasses by design (ADR-0006) -- choosing a forecasting, anomaly-detection, or outlier-detection algorithm is a modeling decision outside this package's charter, left for a future, independently-versioned plugin.BatchAnalyticsRunneris a thin, named wrapper overAnalyticsPipeline.run;StreamingAnalyticsSessionsubscribes to anevents.EventBusand incrementally updates one or moreIncrementalAccumulators per tracked payload field, onethreading.Lockper accumulator key serializing concurrent updates to that key;IncrementalAccumulatorimplements Welford's online algorithm for O(1)-update, O(1)-memory streaming mean/variance/min/max (percentilesis always empty in itsStatisticalSummary-- a genuine, disclosed limitation of O(1)-memory streaming computation, not an oversight).REGISTRY/register(_registry.py) specializeregistry.Registryexactly askpis._registrydoes one layer down, add-only keyed byAnalyticsMetadata.code;LinearTrendModel,RollingBaselineModel, andBandBenchmarkModelare all@register-decorated and discoverable viaREGISTRYat import time.AggregationEngine.reduce()is fully implemented: it groups a plain numericTimeSeriesby scope field(s) and reusesdescribe()verbatim per group, derivingsum/mean/medianfrom the returnedStatisticalSummary(see its own docstring for the full explanation). Every module described in design spec §6 is now implemented.
Contents¶
__init__.py— public API surface (53 symbols)._registry.py—REGISTRY,register(plugin registration, §32–§33).abstractions.py—AnalyticsModel(ABC),AnalyticsContext.metadata.py—AnalyticsMetadata,AnalyticsCategory.result.py—AnalyticsResultand every concrete result/flag type.timeseries.py—TimeSeries,TimeSeriesPoint.windowing.py—RollingSpec.pipeline.py—AnalyticsPipeline,PipelineStage(ABC),ModelStage.aggregation.py—AggregationEngine,GroupBySpec.statistics.py—describe,percentile,histogram,distribution,confidence_interval.rolling.py—rolling_mean,rolling_std,rolling_apply.trend.py—TrendModel(ABC),LinearTrendModel.baseline.py—BaselineModel(ABC),RollingBaselineModel.benchmarking.py—BenchmarkModel(ABC),BandBenchmarkModel.quality.py—DataQualityScorer,MissingDataPolicy(enum),DataQualityStage.forecasting.py—ForecastingModel(ABC, interface only -- zero concrete subclasses).anomaly.py—AnomalyDetector(ABC, interface only -- zero concrete subclasses).outliers.py—OutlierDetector(ABC, interface only -- zero concrete subclasses).batch.py—BatchAnalyticsRunner.streaming.py—StreamingAnalyticsSession.incremental.py—IncrementalAccumulator.exceptions.py— the package's exception hierarchy.README.md— this file.
Dependencies¶
Depends on: core, ontology, events, registry, plugins, kpis. (connectors is a permitted import under the platform-wide layering rule but is not exercised — analytics operates on already-computed KPIResults, never a vendor-specific wire format.)
Depended on by: decision, digital_twin, simulation, optimization, agents, visualization
Future Work¶
Every module in design spec §6 is now implemented; no further src/mineproductivity/analytics/
implementation work is outstanding. Concrete forecasting, anomaly-detection, and
outlier-detection algorithms remain deliberately unimplemented (ADR-0006) -- each is an
independently-versioned plugin decision for a future package, not a gap in this one. The
worked examples under examples/analytics/ and the benchmark reports under
benchmark/reports/analytics/ are outside this package's own source/test/README boundary and
were treated as out of scope for this milestone.
References¶
- Master Architecture Handbook v1.0
- Reference Implementation Blueprint v1.0