detectkit 0.67.2__tar.gz → 0.69.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {detectkit-0.67.2/detectkit.egg-info → detectkit-0.69.0}/PKG-INFO +9 -1
- {detectkit-0.67.2 → detectkit-0.69.0}/README.md +4 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/__init__.py +1 -1
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/orchestrator/_replay.py +22 -1
- detectkit-0.69.0/detectkit/autotune/alert_sim.py +92 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/autotuner.py +16 -1
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/config_emitter.py +17 -0
- detectkit-0.69.0/detectkit/autotune/key_select.py +187 -0
- detectkit-0.69.0/detectkit/autotune/profile_engine.py +290 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/result.py +1 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/runner.py +21 -3
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/settings.py +7 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/_output.py +5 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/rules/autotune.md +17 -1
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/rules/cli.md +73 -8
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/rules/detectors.md +37 -1
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/skills/dtk-autotune/SKILL.md +6 -1
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/skills/dtk-tune/SKILL.md +7 -1
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/autotune.py +16 -1
- detectkit-0.69.0/detectkit/cli/commands/serve.py +69 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/ui.py +2 -1
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/main.py +167 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/config/metric_config.py +26 -0
- detectkit-0.69.0/detectkit/control/__init__.py +44 -0
- detectkit-0.69.0/detectkit/control/actions.py +442 -0
- detectkit-0.69.0/detectkit/control/actor.py +34 -0
- detectkit-0.69.0/detectkit/control/advise.py +171 -0
- detectkit-0.69.0/detectkit/control/commands.py +115 -0
- detectkit-0.69.0/detectkit/control/confirm.py +91 -0
- detectkit-0.69.0/detectkit/control/drafts.py +173 -0
- detectkit-0.69.0/detectkit/control/errors.py +45 -0
- detectkit-0.69.0/detectkit/control/health.py +134 -0
- {detectkit-0.67.2/detectkit/ui → detectkit-0.69.0/detectkit/control}/jobs.py +44 -3
- {detectkit-0.67.2/detectkit/ui → detectkit-0.69.0/detectkit/control}/metric_files.py +11 -0
- {detectkit-0.67.2/detectkit/ui → detectkit-0.69.0/detectkit/control}/overview.py +29 -1
- detectkit-0.69.0/detectkit/control/project.py +230 -0
- detectkit-0.69.0/detectkit/control/proposals.py +349 -0
- detectkit-0.67.2/detectkit/mcp/tools.py → detectkit-0.69.0/detectkit/control/queries.py +285 -89
- detectkit-0.69.0/detectkit/control/registry.py +90 -0
- detectkit-0.69.0/detectkit/control/roles.py +96 -0
- {detectkit-0.67.2/detectkit/mcp → detectkit-0.69.0/detectkit/control}/serialize.py +6 -6
- detectkit-0.69.0/detectkit/control/yaml_patch.py +148 -0
- detectkit-0.69.0/detectkit/database/internal_tables/_platform.py +137 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/manager.py +2 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/tables.py +101 -0
- detectkit-0.69.0/detectkit/detectors/statistical/_baseline.py +271 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/statistical/_windowed.py +140 -26
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/mcp/__init__.py +5 -6
- detectkit-0.69.0/detectkit/mcp/context.py +143 -0
- detectkit-0.69.0/detectkit/mcp/descriptions.py +117 -0
- detectkit-0.69.0/detectkit/mcp/server.py +161 -0
- detectkit-0.69.0/detectkit/mcp/tools.py +56 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/reporting/builder.py +5 -2
- detectkit-0.69.0/detectkit/serve/__init__.py +20 -0
- detectkit-0.69.0/detectkit/serve/api_v1.py +335 -0
- detectkit-0.69.0/detectkit/serve/app.py +186 -0
- detectkit-0.69.0/detectkit/serve/errors.py +11 -0
- detectkit-0.69.0/detectkit/serve/forge.py +284 -0
- detectkit-0.69.0/detectkit/serve/mcp_app.py +723 -0
- detectkit-0.69.0/detectkit/serve/platform.py +263 -0
- detectkit-0.69.0/detectkit/serve/projects.py +85 -0
- detectkit-0.69.0/detectkit/serve/server.py +54 -0
- detectkit-0.69.0/detectkit/serve/settings.py +112 -0
- detectkit-0.69.0/detectkit/serve/write_tools.py +705 -0
- detectkit-0.69.0/detectkit/tuning/assets/tune.js +187 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/tuning/config_writer.py +66 -30
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/tuning/payload.py +17 -2
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/tuning/server.py +2 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/ui/__init__.py +5 -9
- detectkit-0.69.0/detectkit/ui/assets/ui.js +564 -0
- detectkit-0.69.0/detectkit/ui/server.py +503 -0
- {detectkit-0.67.2 → detectkit-0.69.0/detectkit.egg-info}/PKG-INFO +9 -1
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit.egg-info/SOURCES.txt +37 -4
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit.egg-info/requires.txt +5 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/pyproject.toml +5 -0
- detectkit-0.67.2/detectkit/mcp/context.py +0 -330
- detectkit-0.67.2/detectkit/mcp/server.py +0 -263
- detectkit-0.67.2/detectkit/tuning/assets/tune.js +0 -187
- detectkit-0.67.2/detectkit/ui/assets/ui.js +0 -557
- detectkit-0.67.2/detectkit/ui/server.py +0 -1215
- {detectkit-0.67.2 → detectkit-0.69.0}/LICENSE +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/MANIFEST.in +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/base.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/branding.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/discord.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/email.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/factory.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/googlechat.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/mattermost.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/ntfy.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/slack.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/teams.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/telegram.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/channels/webhook.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/orchestrator/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/orchestrator/_base.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/orchestrator/_cooldown.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/orchestrator/_decision.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/orchestrator/_dispatch.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/orchestrator/_recovery.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/orchestrator/_types.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/alerting/orchestrator/orchestrator.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/_base.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/_types.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/axis_spec.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/crossval.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/detector_select.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/distribution.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/grid_search.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/labels.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/scoring.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/seasonality_search.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/autotune/window_select.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/CLAUDE.section.md +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/rules/alerting.md +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/rules/metrics.md +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/rules/overview.md +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/rules/project.md +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/skills/dtk-feedback/SKILL.md +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/skills/dtk-new-metric/SKILL.md +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/assets/claude/skills/dtk-setup-project/SKILL.md +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/clean.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/init.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/init_claude.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/mcp.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/osi.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/run.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/test_alert.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/tune.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/cli/commands/unlock.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/config/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/config/metric_io.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/config/profile.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/config/project_config.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/config/validator.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/core/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/core/interval.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/core/models.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/_sql_manager.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/bigquery_manager.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/clickhouse_manager.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/duckdb_manager.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/_alert_states.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/_autotune_runs.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/_base.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/_datapoints.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/_detections.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/_maintenance.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/_metrics.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/_schema.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/internal_tables/_tasks.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/manager.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/mysql_manager.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/postgres_manager.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/snowflake_manager.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/database/source_manager.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/base.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/factory.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/seasonality.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/statistical/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/statistical/autoreg.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/statistical/iqr.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/statistical/mad.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/statistical/manual_bounds.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/detectors/statistical/zscore.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/loaders/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/loaders/errors.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/loaders/metric_loader.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/loaders/query_template.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/mcp/errors.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/orchestration/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/orchestration/error_dispatch.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/orchestration/task_manager/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/orchestration/task_manager/_alert_step.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/orchestration/task_manager/_base.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/orchestration/task_manager/_detect_step.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/orchestration/task_manager/_load_step.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/orchestration/task_manager/_types.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/orchestration/task_manager/manager.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/reporting/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/reporting/assets/report.js +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/reporting/html_report.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/semantic/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/semantic/errors.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/semantic/exporter.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/semantic/importer.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/semantic/osi_model.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/semantic/query_gen.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/tuning/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/tuning/html.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/ui/html.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/utils/__init__.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/utils/datetime_utils.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/utils/env_interpolation.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/utils/json_utils.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit/utils/stats.py +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit.egg-info/dependency_links.txt +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit.egg-info/entry_points.txt +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/detectkit.egg-info/top_level.txt +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/requirements.txt +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/setup.cfg +0 -0
- {detectkit-0.67.2 → detectkit-0.69.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: detectkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.69.0
|
|
4
4
|
Summary: Metric monitoring with automatic anomaly detection
|
|
5
5
|
Author: detectkit team
|
|
6
6
|
License: MIT
|
|
@@ -62,6 +62,9 @@ Provides-Extra: osi
|
|
|
62
62
|
Requires-Dist: sqlglot>=20.0; extra == "osi"
|
|
63
63
|
Provides-Extra: mcp
|
|
64
64
|
Requires-Dist: mcp<2,>=1.27; extra == "mcp"
|
|
65
|
+
Provides-Extra: serve
|
|
66
|
+
Requires-Dist: mcp<2,>=1.27; extra == "serve"
|
|
67
|
+
Requires-Dist: uvicorn>=0.31.1; extra == "serve"
|
|
65
68
|
Provides-Extra: all
|
|
66
69
|
Requires-Dist: clickhouse-driver>=0.2.0; extra == "all"
|
|
67
70
|
Requires-Dist: psycopg2-binary>=2.9.0; extra == "all"
|
|
@@ -73,6 +76,7 @@ Requires-Dist: prophet>=1.1.0; extra == "all"
|
|
|
73
76
|
Requires-Dist: timesfm>=0.1.0; extra == "all"
|
|
74
77
|
Requires-Dist: sqlglot>=20.0; extra == "all"
|
|
75
78
|
Requires-Dist: mcp<2,>=1.27; extra == "all"
|
|
79
|
+
Requires-Dist: uvicorn>=0.31.1; extra == "all"
|
|
76
80
|
Provides-Extra: dev
|
|
77
81
|
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
78
82
|
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
@@ -220,6 +224,9 @@ for r in results:
|
|
|
220
224
|
Code, Claude Desktop, any MCP client) can query a project's metric configs,
|
|
221
225
|
loaded data, detector results, replayed alert history and autotune runs
|
|
222
226
|
directly — no write access to the pipeline.
|
|
227
|
+
- **[Hosted platform](docs/guides/hosted-platform.md)** (`dtk serve`) — the same
|
|
228
|
+
read-only tools over HTTP for a whole team: several projects behind a company MCP
|
|
229
|
+
gateway, with a container image.
|
|
223
230
|
- **[GitHub Action](docs/guides/github-action.md)** — a composite action that
|
|
224
231
|
runs `dtk run`/`autotune`/`clean` as a CI check or scheduled job and gates
|
|
225
232
|
on detectkit's own exit-code contract, with the `--json` run summary wired
|
|
@@ -234,6 +241,7 @@ for r in results:
|
|
|
234
241
|
- [Alerting Guide](docs/guides/alerting.md) — channels, mentions, cooldown, recovery
|
|
235
242
|
- [Reading Alerts](docs/guides/reading-alerts.md) — what a received alert means (for stakeholders)
|
|
236
243
|
- [MCP Guide](docs/guides/mcp.md) — read-only AI-assistant access with `dtk mcp`
|
|
244
|
+
- [Hosted Platform Guide](docs/guides/hosted-platform.md) — `dtk serve` behind an MCP gateway
|
|
237
245
|
- [GitHub Action Guide](docs/guides/github-action.md) — run the pipeline in CI
|
|
238
246
|
- [CLI Reference](docs/reference/cli.md) — command-line documentation
|
|
239
247
|
- [Examples](docs/examples/) — real-world monitoring scenarios
|
|
@@ -130,6 +130,9 @@ for r in results:
|
|
|
130
130
|
Code, Claude Desktop, any MCP client) can query a project's metric configs,
|
|
131
131
|
loaded data, detector results, replayed alert history and autotune runs
|
|
132
132
|
directly — no write access to the pipeline.
|
|
133
|
+
- **[Hosted platform](docs/guides/hosted-platform.md)** (`dtk serve`) — the same
|
|
134
|
+
read-only tools over HTTP for a whole team: several projects behind a company MCP
|
|
135
|
+
gateway, with a container image.
|
|
133
136
|
- **[GitHub Action](docs/guides/github-action.md)** — a composite action that
|
|
134
137
|
runs `dtk run`/`autotune`/`clean` as a CI check or scheduled job and gates
|
|
135
138
|
on detectkit's own exit-code contract, with the `--json` run summary wired
|
|
@@ -144,6 +147,7 @@ for r in results:
|
|
|
144
147
|
- [Alerting Guide](docs/guides/alerting.md) — channels, mentions, cooldown, recovery
|
|
145
148
|
- [Reading Alerts](docs/guides/reading-alerts.md) — what a received alert means (for stakeholders)
|
|
146
149
|
- [MCP Guide](docs/guides/mcp.md) — read-only AI-assistant access with `dtk mcp`
|
|
150
|
+
- [Hosted Platform Guide](docs/guides/hosted-platform.md) — `dtk serve` behind an MCP gateway
|
|
147
151
|
- [GitHub Action Guide](docs/guides/github-action.md) — run the pipeline in CI
|
|
148
152
|
- [CLI Reference](docs/reference/cli.md) — command-line documentation
|
|
149
153
|
- [Examples](docs/examples/) — real-world monitoring scenarios
|
|
@@ -4,7 +4,7 @@ detectk - Anomaly Detection for Time-Series Metrics
|
|
|
4
4
|
A Python library for data analysts and engineers to monitor metrics with automatic anomaly detection.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
-
__version__ = "0.
|
|
7
|
+
__version__ = "0.69.0"
|
|
8
8
|
|
|
9
9
|
from detectkit.core.interval import Interval
|
|
10
10
|
from detectkit.core.models import ColumnDefinition, TableModel
|
|
@@ -20,6 +20,7 @@ from collections import deque
|
|
|
20
20
|
from collections.abc import Sequence
|
|
21
21
|
from dataclasses import dataclass
|
|
22
22
|
from datetime import datetime, timedelta
|
|
23
|
+
from typing import Any
|
|
23
24
|
|
|
24
25
|
import numpy as np
|
|
25
26
|
|
|
@@ -51,6 +52,8 @@ class _ReplayMixin(_OrchestratorBase):
|
|
|
51
52
|
value_at: dict[np.datetime64, float | None],
|
|
52
53
|
start: datetime,
|
|
53
54
|
end: datetime,
|
|
55
|
+
*,
|
|
56
|
+
track_resolution: bool = False,
|
|
54
57
|
) -> list[ReplayedEvent]:
|
|
55
58
|
"""Reconstruct alert/recovery/no-data events over ``[start, end]``.
|
|
56
59
|
|
|
@@ -68,6 +71,12 @@ class _ReplayMixin(_OrchestratorBase):
|
|
|
68
71
|
missing / NaN datapoint (drives the no-data check).
|
|
69
72
|
start: first grid boundary to evaluate (inclusive).
|
|
70
73
|
end: last grid boundary to evaluate (inclusive).
|
|
74
|
+
track_resolution: also emit a ``"resolved"`` event at the grid point
|
|
75
|
+
where the open anomaly alert would recover, whether or not
|
|
76
|
+
``notify_on_recovery`` is set. It never feeds back into the
|
|
77
|
+
simulated state (cooldown, recovery), so every other event is
|
|
78
|
+
unchanged. Its ``alert_data`` is the alert it resolves. Used to
|
|
79
|
+
measure how long alerts stay open (``control/health.py``).
|
|
71
80
|
|
|
72
81
|
Returns:
|
|
73
82
|
The fired events in chronological order.
|
|
@@ -76,6 +85,8 @@ class _ReplayMixin(_OrchestratorBase):
|
|
|
76
85
|
|
|
77
86
|
sim_last_alert: np.datetime64 | None = None
|
|
78
87
|
sim_last_recovery: np.datetime64 | None = None
|
|
88
|
+
last_alert_data: Any = None
|
|
89
|
+
last_resolved: np.datetime64 | None = None
|
|
79
90
|
events: list[ReplayedEvent] = []
|
|
80
91
|
|
|
81
92
|
# The causal view grows monotonically as the grid advances, so it is
|
|
@@ -144,7 +155,17 @@ class _ReplayMixin(_OrchestratorBase):
|
|
|
144
155
|
)
|
|
145
156
|
events.append(ReplayedEvent("anomaly", t, ad))
|
|
146
157
|
sim_last_alert = t
|
|
147
|
-
|
|
158
|
+
last_alert_data = ad
|
|
159
|
+
continue
|
|
160
|
+
if (
|
|
161
|
+
track_resolution
|
|
162
|
+
and sim_last_alert is not None
|
|
163
|
+
and (last_resolved is None or last_resolved < sim_last_alert)
|
|
164
|
+
and self._replay_recovered(causal, ts_desc, sim_last_alert)
|
|
165
|
+
):
|
|
166
|
+
events.append(ReplayedEvent("resolved", t, last_alert_data))
|
|
167
|
+
last_resolved = t
|
|
168
|
+
if (
|
|
148
169
|
self.alert_config
|
|
149
170
|
and getattr(self.alert_config, "notify_on_recovery", False)
|
|
150
171
|
and sim_last_alert is not None
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""A pure alert-rule simulation over point flags, for the profile engine's backtest.
|
|
2
|
+
|
|
3
|
+
It mirrors the pipeline's decision closely enough to count alerts, not to render
|
|
4
|
+
them. A streak of ``consecutive`` flagged points fires. So does, with the
|
|
5
|
+
fraction rule, a flagged latest point whose trailing ``window`` holds at least
|
|
6
|
+
``share`` flagged points; missing slots count in the denominator. One alert stays
|
|
7
|
+
open until recovery: a clean latest point and, with the fraction rule, the window
|
|
8
|
+
share below half the threshold. Cooldown is not modeled; with recovery-gated
|
|
9
|
+
alerts it rarely changes a count.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
|
|
16
|
+
import numpy as np
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class AlertRule:
|
|
21
|
+
consecutive: int = 3
|
|
22
|
+
window: int | None = None
|
|
23
|
+
share: float | None = None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True)
|
|
27
|
+
class SimAlert:
|
|
28
|
+
onset: int
|
|
29
|
+
fire: int
|
|
30
|
+
end: int # exclusive; len(flags) while still open
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def simulate_alerts(flags: np.ndarray, rule: AlertRule) -> list[SimAlert]:
|
|
34
|
+
f = np.asarray(flags, dtype=bool)
|
|
35
|
+
n = len(f)
|
|
36
|
+
csum = np.concatenate([[0], np.cumsum(f)])
|
|
37
|
+
k = max(1, rule.consecutive)
|
|
38
|
+
alerts: list[SimAlert] = []
|
|
39
|
+
open_at: tuple[int, int] | None = None
|
|
40
|
+
for i in range(n):
|
|
41
|
+
hits = 0
|
|
42
|
+
lo = 0
|
|
43
|
+
if rule.window:
|
|
44
|
+
lo = max(0, i - rule.window + 1)
|
|
45
|
+
hits = int(csum[i + 1] - csum[lo])
|
|
46
|
+
if open_at is None:
|
|
47
|
+
streak = i + 1 >= k and int(csum[i + 1] - csum[i + 1 - k]) == k
|
|
48
|
+
share = bool(rule.window and rule.share and f[i] and hits >= rule.share * rule.window)
|
|
49
|
+
if streak or share:
|
|
50
|
+
if streak:
|
|
51
|
+
onset = i
|
|
52
|
+
while onset > 0 and f[onset - 1]:
|
|
53
|
+
onset -= 1
|
|
54
|
+
else:
|
|
55
|
+
onset = lo + int(np.argmax(f[lo : i + 1]))
|
|
56
|
+
open_at = (onset, i)
|
|
57
|
+
else:
|
|
58
|
+
clean = not f[i]
|
|
59
|
+
if rule.window and rule.share:
|
|
60
|
+
clean = clean and hits < rule.share * rule.window / 2
|
|
61
|
+
if clean:
|
|
62
|
+
alerts.append(SimAlert(open_at[0], open_at[1], i))
|
|
63
|
+
open_at = None
|
|
64
|
+
if open_at is not None:
|
|
65
|
+
alerts.append(SimAlert(open_at[0], open_at[1], n))
|
|
66
|
+
return alerts
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def incident_segments(y_true: np.ndarray) -> list[tuple[int, int]]:
|
|
70
|
+
out: list[tuple[int, int]] = []
|
|
71
|
+
start = None
|
|
72
|
+
for i, v in enumerate(np.asarray(y_true, dtype=bool)):
|
|
73
|
+
if v and start is None:
|
|
74
|
+
start = i
|
|
75
|
+
elif not v and start is not None:
|
|
76
|
+
out.append((start, i))
|
|
77
|
+
start = None
|
|
78
|
+
if start is not None:
|
|
79
|
+
out.append((start, len(y_true)))
|
|
80
|
+
return out
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def alert_event_f1(alerts: list[SimAlert], y_true: np.ndarray) -> float:
|
|
84
|
+
"""Incidents caught by an overlapping alert vs alerts that overlap no incident."""
|
|
85
|
+
segs = incident_segments(y_true)
|
|
86
|
+
if not segs:
|
|
87
|
+
return 0.0
|
|
88
|
+
caught = sum(any(a.onset < e and a.end > s for a in alerts) for s, e in segs)
|
|
89
|
+
false = sum(not any(a.onset < e and a.end > s for s, e in segs) for a in alerts)
|
|
90
|
+
recall = caught / len(segs)
|
|
91
|
+
precision = (len(alerts) - false) / len(alerts) if alerts else 0.0
|
|
92
|
+
return 2 * recall * precision / (recall + precision) if recall + precision else 0.0
|
|
@@ -295,7 +295,22 @@ def run_autotune_engine(
|
|
|
295
295
|
settings: TuneSettings,
|
|
296
296
|
on_stage: Callable[[str, str], None] | None = None,
|
|
297
297
|
) -> AutoTuneResult:
|
|
298
|
-
"""
|
|
298
|
+
"""Run the configured engine (the command↔engine entry point).
|
|
299
|
+
|
|
300
|
+
``settings.engine == "profile"`` runs :mod:`detectkit.autotune.profile_engine`;
|
|
301
|
+
anything else builds an :class:`AutoTuner` (the cross-validated search).
|
|
302
|
+
"""
|
|
303
|
+
if settings.engine == "profile":
|
|
304
|
+
from detectkit.autotune.profile_engine import run_profile_engine # noqa: PLC0415
|
|
305
|
+
|
|
306
|
+
return run_profile_engine(
|
|
307
|
+
metric_name=metric_name,
|
|
308
|
+
data=data,
|
|
309
|
+
ground_truth=ground_truth,
|
|
310
|
+
interval_seconds=interval_seconds,
|
|
311
|
+
settings=settings,
|
|
312
|
+
on_stage=on_stage,
|
|
313
|
+
)
|
|
299
314
|
tuner = AutoTuner(
|
|
300
315
|
metric_name=metric_name,
|
|
301
316
|
data=data,
|
|
@@ -146,6 +146,23 @@ def _build_comments(result: AutoTuneResult, source_label: str, run_id: str) -> s
|
|
|
146
146
|
f"{summary.get('positive_grid_points', 0)} labeled grid point(s)"
|
|
147
147
|
)
|
|
148
148
|
folds = " ".join(f"{f:.2f}" for f in result.cv_per_fold) or "—"
|
|
149
|
+
if result.engine == "profile":
|
|
150
|
+
lines.append(
|
|
151
|
+
"# Engine : profile (RFC 0003) — label-free keys, baseline seasonality, "
|
|
152
|
+
"threshold calibrated to an alert budget"
|
|
153
|
+
)
|
|
154
|
+
lines.append("#")
|
|
155
|
+
for entry in result.decision_log:
|
|
156
|
+
stage, message = entry.get("stage", ""), entry.get("message", "")
|
|
157
|
+
if stage in ("profile", "recipe", "backtest") or (
|
|
158
|
+
stage in ("keys", "calibrate")
|
|
159
|
+
and message.startswith(("chosen", "skipped", "pinned", "no ", "only "))
|
|
160
|
+
):
|
|
161
|
+
lines.append(f"# {stage.upper():<12}: {message}")
|
|
162
|
+
lines.append("#")
|
|
163
|
+
lines.append(f"# Reproduce: dtk autotune --select {result.metric_name} --engine profile")
|
|
164
|
+
lines.append(_RULE)
|
|
165
|
+
return "\n".join(lines)
|
|
149
166
|
if result.mode == "supervised":
|
|
150
167
|
obj_label, objective = "Scoring metric", result.scoring_metric
|
|
151
168
|
else:
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Label-free seasonal key selection for the ``profile`` engine (RFC 0003).
|
|
2
|
+
|
|
3
|
+
A key (``hour``, ``day_of_week``, a custom query column) is kept only when knowing
|
|
4
|
+
it predicts held-out values better. The history becomes a causal one-week level
|
|
5
|
+
plus a deviation, in the profile's transformed space. A model is a list of
|
|
6
|
+
additive components, each a key conjunction, whose estimate at a point is the
|
|
7
|
+
median of past same-combination deviations within a sample-sufficient lookback,
|
|
8
|
+
or 0 when that combination is too rare. The greedy search adds a key as a new
|
|
9
|
+
component or merges it into the last one, the same move set as the old search.
|
|
10
|
+
A move is kept only when it cuts the robust scale of what's left, on the second
|
|
11
|
+
half of the history, by ``ACCEPT_GAIN``.
|
|
12
|
+
|
|
13
|
+
No labels and no cross-validation window are involved, which is what made the
|
|
14
|
+
old search reject real keys (Case C-002).
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from dataclasses import dataclass, field
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
import numpy as np
|
|
23
|
+
|
|
24
|
+
from detectkit.detectors.seasonality import parse_seasonality_data
|
|
25
|
+
from detectkit.detectors.statistical._baseline import ComboIndex, apply_transform, combo_codes
|
|
26
|
+
|
|
27
|
+
MIN_SAMPLES_PER_COMBO = 8
|
|
28
|
+
ACCEPT_GAIN = 0.05
|
|
29
|
+
# ...and by at least this share of the no-key scale, so a late key can't win on a
|
|
30
|
+
# tiny residual by fitting day-level noise (a decoy correlated with a real key by
|
|
31
|
+
# chance over a short history).
|
|
32
|
+
ABS_GAIN = 0.01
|
|
33
|
+
MIN_LOOKBACK_DAYS = 14
|
|
34
|
+
MAX_LOOKBACK_DAYS = 56
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def value_transform(values: np.ndarray) -> str | None:
|
|
38
|
+
"""``sqrt`` for small counts, ``log`` for non-negative values, else ``None``."""
|
|
39
|
+
finite = values[np.isfinite(values)]
|
|
40
|
+
if finite.size == 0 or np.any(finite < 0):
|
|
41
|
+
return None
|
|
42
|
+
integer = bool(np.all(np.abs(finite - np.round(finite)) < 1e-9))
|
|
43
|
+
if integer and float(np.median(finite)) < 30:
|
|
44
|
+
return "sqrt"
|
|
45
|
+
return "log"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def lookback_points(cardinality: int, per_day: int) -> int:
|
|
49
|
+
"""About ``MIN_SAMPLES_PER_COMBO`` samples per combination, within 2–8 weeks."""
|
|
50
|
+
want = int(MIN_SAMPLES_PER_COMBO * max(1, cardinality) * 1.5)
|
|
51
|
+
return int(np.clip(want, MIN_LOOKBACK_DAYS * per_day, MAX_LOOKBACK_DAYS * per_day))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _trailing_level(z: np.ndarray, width: int) -> np.ndarray:
|
|
55
|
+
out = np.full(len(z), np.nan)
|
|
56
|
+
floor = max(8, width // 4)
|
|
57
|
+
for t in range(len(z)):
|
|
58
|
+
w = z[max(0, t - width) : t]
|
|
59
|
+
w = w[np.isfinite(w)]
|
|
60
|
+
if w.size >= floor:
|
|
61
|
+
out[t] = float(np.median(w))
|
|
62
|
+
return out
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _component_estimates(r: np.ndarray, codes: np.ndarray, lookback: int) -> np.ndarray:
|
|
66
|
+
index = ComboIndex(codes)
|
|
67
|
+
est = np.zeros(len(r))
|
|
68
|
+
for t in range(len(r)):
|
|
69
|
+
vals = r[index.past(t, lookback)]
|
|
70
|
+
vals = vals[np.isfinite(vals)]
|
|
71
|
+
if vals.size >= MIN_SAMPLES_PER_COMBO:
|
|
72
|
+
est[t] = float(np.median(vals))
|
|
73
|
+
return est
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _robust_scale(r: np.ndarray) -> float:
|
|
77
|
+
r = r[np.isfinite(r)]
|
|
78
|
+
if r.size < 50:
|
|
79
|
+
return float("inf")
|
|
80
|
+
return float(1.4826 * np.median(np.abs(r - np.median(r))))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _same_partition(a: np.ndarray, b: np.ndarray) -> bool:
|
|
84
|
+
"""Whether two keys split the points identically (e.g. UTC hour vs local hour)."""
|
|
85
|
+
ok = (a >= 0) & (b >= 0)
|
|
86
|
+
if not ok.any():
|
|
87
|
+
return False
|
|
88
|
+
pairs = len(set(zip(a[ok].tolist(), b[ok].tolist(), strict=True)))
|
|
89
|
+
return pairs == len(np.unique(a[ok])) == len(np.unique(b[ok]))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@dataclass
|
|
93
|
+
class KeySelection:
|
|
94
|
+
components: list[list[str]]
|
|
95
|
+
lookback: int # points: the largest component's sufficiency-sized lookback
|
|
96
|
+
log: list[str] = field(default_factory=list)
|
|
97
|
+
skipped: dict[str, str] = field(default_factory=dict) # key -> why it wasn't a candidate
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def select_keys(
|
|
101
|
+
data: dict[str, Any],
|
|
102
|
+
*,
|
|
103
|
+
candidates: list[str],
|
|
104
|
+
transform: str | None,
|
|
105
|
+
per_day: int,
|
|
106
|
+
) -> KeySelection:
|
|
107
|
+
values = np.asarray(data["value"], dtype=float)
|
|
108
|
+
n = len(values)
|
|
109
|
+
season = parse_seasonality_data(data["seasonality_data"], candidates) if candidates else {}
|
|
110
|
+
codes = {k: combo_codes(season, [k], n)[0] for k in candidates if k in season}
|
|
111
|
+
skipped: dict[str, str] = {}
|
|
112
|
+
usable: list[str] = []
|
|
113
|
+
for k in candidates:
|
|
114
|
+
if k not in codes or not (codes[k] >= 0).any():
|
|
115
|
+
skipped[k] = "no values in the loaded datapoints"
|
|
116
|
+
continue
|
|
117
|
+
twin = next((u for u in usable if _same_partition(codes[u], codes[k])), None)
|
|
118
|
+
if twin is not None:
|
|
119
|
+
skipped[k] = f"splits the series exactly like {twin}"
|
|
120
|
+
continue
|
|
121
|
+
if len(np.unique(codes[k][codes[k] >= 0])) < 2:
|
|
122
|
+
skipped[k] = "a single value"
|
|
123
|
+
continue
|
|
124
|
+
usable.append(k)
|
|
125
|
+
|
|
126
|
+
z = apply_transform(values, transform)
|
|
127
|
+
x = z - _trailing_level(z, 7 * per_day)
|
|
128
|
+
start = n // 2
|
|
129
|
+
cache: dict[tuple, np.ndarray] = {}
|
|
130
|
+
|
|
131
|
+
def comp_codes(comp: list[str]) -> np.ndarray:
|
|
132
|
+
key = tuple(comp)
|
|
133
|
+
if key not in cache:
|
|
134
|
+
cache[key] = combo_codes(season, comp, n)[0]
|
|
135
|
+
return cache[key]
|
|
136
|
+
|
|
137
|
+
mid = (start + n) // 2
|
|
138
|
+
|
|
139
|
+
def score(comps: list[list[str]]) -> tuple[float, float, float]:
|
|
140
|
+
"""Residual scale on the held-out half, and on each of its two quarters."""
|
|
141
|
+
r = x.copy()
|
|
142
|
+
for comp in comps:
|
|
143
|
+
c = comp_codes(comp)
|
|
144
|
+
card = len(np.unique(c[c >= 0]))
|
|
145
|
+
r = r - _component_estimates(r, c, lookback_points(card, per_day))
|
|
146
|
+
return _robust_scale(r[start:]), _robust_scale(r[start:mid]), _robust_scale(r[mid:])
|
|
147
|
+
|
|
148
|
+
def better(new: tuple[float, float, float], old: tuple[float, float, float]) -> bool:
|
|
149
|
+
# a real key helps overall by ACCEPT_GAIN *and* in both quarters, so a key
|
|
150
|
+
# that only fits one stretch of noise (a decoy) is rejected
|
|
151
|
+
return (
|
|
152
|
+
new[0] <= old[0] * (1 - ACCEPT_GAIN)
|
|
153
|
+
and old[0] - new[0] >= floor
|
|
154
|
+
and new[1] < old[1]
|
|
155
|
+
and new[2] < old[2]
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
comps: list[list[str]] = []
|
|
159
|
+
base = score(comps)
|
|
160
|
+
floor = ABS_GAIN * base[0]
|
|
161
|
+
log = [f"no keys: residual scale {base[0]:.4f}"]
|
|
162
|
+
while True:
|
|
163
|
+
used = {k for c in comps for k in c}
|
|
164
|
+
moves = [comps + [[k]] for k in usable if k not in used]
|
|
165
|
+
if comps:
|
|
166
|
+
moves += [comps[:-1] + [comps[-1] + [k]] for k in usable if k not in used]
|
|
167
|
+
best, best_m = base, None
|
|
168
|
+
for m in moves:
|
|
169
|
+
sc = score(m)
|
|
170
|
+
log.append(
|
|
171
|
+
f"{' + '.join('×'.join(c) for c in m)}: {sc[0]:.4f} "
|
|
172
|
+
f"(quarters {sc[1]:.4f} / {sc[2]:.4f})"
|
|
173
|
+
)
|
|
174
|
+
if sc[0] < best[0] and better(sc, base):
|
|
175
|
+
best, best_m = sc, m
|
|
176
|
+
if best_m is None:
|
|
177
|
+
break
|
|
178
|
+
log.append(
|
|
179
|
+
f"kept {' + '.join('×'.join(c) for c in best_m)} ({1 - best[0] / base[0]:.0%} better)"
|
|
180
|
+
)
|
|
181
|
+
comps, base = best_m, best
|
|
182
|
+
|
|
183
|
+
lookback = 0
|
|
184
|
+
for comp in comps:
|
|
185
|
+
c = comp_codes(comp)
|
|
186
|
+
lookback = max(lookback, lookback_points(len(np.unique(c[c >= 0])), per_day))
|
|
187
|
+
return KeySelection(comps, lookback, log, skipped)
|