driftdetect-core 0.1.0
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.
- package/dist/analyzers/ast-analyzer.d.ts +251 -0
- package/dist/analyzers/ast-analyzer.d.ts.map +1 -0
- package/dist/analyzers/ast-analyzer.js +548 -0
- package/dist/analyzers/ast-analyzer.js.map +1 -0
- package/dist/analyzers/flow-analyzer.d.ts +241 -0
- package/dist/analyzers/flow-analyzer.d.ts.map +1 -0
- package/dist/analyzers/flow-analyzer.js +1219 -0
- package/dist/analyzers/flow-analyzer.js.map +1 -0
- package/dist/analyzers/index.d.ts +18 -0
- package/dist/analyzers/index.d.ts.map +1 -0
- package/dist/analyzers/index.js +19 -0
- package/dist/analyzers/index.js.map +1 -0
- package/dist/analyzers/semantic-analyzer.d.ts +252 -0
- package/dist/analyzers/semantic-analyzer.d.ts.map +1 -0
- package/dist/analyzers/semantic-analyzer.js +1182 -0
- package/dist/analyzers/semantic-analyzer.js.map +1 -0
- package/dist/analyzers/type-analyzer.d.ts +289 -0
- package/dist/analyzers/type-analyzer.d.ts.map +1 -0
- package/dist/analyzers/type-analyzer.js +1269 -0
- package/dist/analyzers/type-analyzer.js.map +1 -0
- package/dist/analyzers/types.d.ts +537 -0
- package/dist/analyzers/types.d.ts.map +1 -0
- package/dist/analyzers/types.js +11 -0
- package/dist/analyzers/types.js.map +1 -0
- package/dist/config/config-loader.d.ts +166 -0
- package/dist/config/config-loader.d.ts.map +1 -0
- package/dist/config/config-loader.js +429 -0
- package/dist/config/config-loader.js.map +1 -0
- package/dist/config/config-validator.d.ts +204 -0
- package/dist/config/config-validator.d.ts.map +1 -0
- package/dist/config/config-validator.js +632 -0
- package/dist/config/config-validator.js.map +1 -0
- package/dist/config/defaults.d.ts +8 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +26 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +10 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +47 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +7 -0
- package/dist/config/types.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest/exporter.d.ts +21 -0
- package/dist/manifest/exporter.d.ts.map +1 -0
- package/dist/manifest/exporter.js +339 -0
- package/dist/manifest/exporter.js.map +1 -0
- package/dist/manifest/index.d.ts +14 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +15 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/manifest-store.d.ts +111 -0
- package/dist/manifest/manifest-store.d.ts.map +1 -0
- package/dist/manifest/manifest-store.js +418 -0
- package/dist/manifest/manifest-store.js.map +1 -0
- package/dist/manifest/types.d.ts +238 -0
- package/dist/manifest/types.d.ts.map +1 -0
- package/dist/manifest/types.js +11 -0
- package/dist/manifest/types.js.map +1 -0
- package/dist/matcher/confidence-scorer.d.ts +188 -0
- package/dist/matcher/confidence-scorer.d.ts.map +1 -0
- package/dist/matcher/confidence-scorer.js +302 -0
- package/dist/matcher/confidence-scorer.js.map +1 -0
- package/dist/matcher/index.d.ts +24 -0
- package/dist/matcher/index.d.ts.map +1 -0
- package/dist/matcher/index.js +26 -0
- package/dist/matcher/index.js.map +1 -0
- package/dist/matcher/outlier-detector.d.ts +252 -0
- package/dist/matcher/outlier-detector.d.ts.map +1 -0
- package/dist/matcher/outlier-detector.js +544 -0
- package/dist/matcher/outlier-detector.js.map +1 -0
- package/dist/matcher/pattern-matcher.d.ts +169 -0
- package/dist/matcher/pattern-matcher.d.ts.map +1 -0
- package/dist/matcher/pattern-matcher.js +692 -0
- package/dist/matcher/pattern-matcher.js.map +1 -0
- package/dist/matcher/types.d.ts +476 -0
- package/dist/matcher/types.d.ts.map +1 -0
- package/dist/matcher/types.js +36 -0
- package/dist/matcher/types.js.map +1 -0
- package/dist/parsers/base-parser.d.ts +282 -0
- package/dist/parsers/base-parser.d.ts.map +1 -0
- package/dist/parsers/base-parser.js +421 -0
- package/dist/parsers/base-parser.js.map +1 -0
- package/dist/parsers/css-parser.d.ts +225 -0
- package/dist/parsers/css-parser.d.ts.map +1 -0
- package/dist/parsers/css-parser.js +477 -0
- package/dist/parsers/css-parser.js.map +1 -0
- package/dist/parsers/index.d.ts +15 -0
- package/dist/parsers/index.d.ts.map +1 -0
- package/dist/parsers/index.js +15 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/json-parser.d.ts +219 -0
- package/dist/parsers/json-parser.d.ts.map +1 -0
- package/dist/parsers/json-parser.js +602 -0
- package/dist/parsers/json-parser.js.map +1 -0
- package/dist/parsers/markdown-parser.d.ts +276 -0
- package/dist/parsers/markdown-parser.d.ts.map +1 -0
- package/dist/parsers/markdown-parser.js +731 -0
- package/dist/parsers/markdown-parser.js.map +1 -0
- package/dist/parsers/parser-manager.d.ts +294 -0
- package/dist/parsers/parser-manager.d.ts.map +1 -0
- package/dist/parsers/parser-manager.js +738 -0
- package/dist/parsers/parser-manager.js.map +1 -0
- package/dist/parsers/python-parser.d.ts +204 -0
- package/dist/parsers/python-parser.d.ts.map +1 -0
- package/dist/parsers/python-parser.js +517 -0
- package/dist/parsers/python-parser.js.map +1 -0
- package/dist/parsers/types.d.ts +43 -0
- package/dist/parsers/types.d.ts.map +1 -0
- package/dist/parsers/types.js +7 -0
- package/dist/parsers/types.js.map +1 -0
- package/dist/parsers/typescript-parser.d.ts +264 -0
- package/dist/parsers/typescript-parser.d.ts.map +1 -0
- package/dist/parsers/typescript-parser.js +658 -0
- package/dist/parsers/typescript-parser.js.map +1 -0
- package/dist/rules/evaluator.d.ts +305 -0
- package/dist/rules/evaluator.d.ts.map +1 -0
- package/dist/rules/evaluator.js +579 -0
- package/dist/rules/evaluator.js.map +1 -0
- package/dist/rules/index.d.ts +13 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +13 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/quick-fix-generator.d.ts +334 -0
- package/dist/rules/quick-fix-generator.d.ts.map +1 -0
- package/dist/rules/quick-fix-generator.js +1075 -0
- package/dist/rules/quick-fix-generator.js.map +1 -0
- package/dist/rules/rule-engine.d.ts +241 -0
- package/dist/rules/rule-engine.d.ts.map +1 -0
- package/dist/rules/rule-engine.js +585 -0
- package/dist/rules/rule-engine.js.map +1 -0
- package/dist/rules/severity-manager.d.ts +394 -0
- package/dist/rules/severity-manager.d.ts.map +1 -0
- package/dist/rules/severity-manager.js +619 -0
- package/dist/rules/severity-manager.js.map +1 -0
- package/dist/rules/types.d.ts +370 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +133 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/rules/variant-manager.d.ts +388 -0
- package/dist/rules/variant-manager.d.ts.map +1 -0
- package/dist/rules/variant-manager.js +777 -0
- package/dist/rules/variant-manager.js.map +1 -0
- package/dist/scanner/change-detector.d.ts +164 -0
- package/dist/scanner/change-detector.d.ts.map +1 -0
- package/dist/scanner/change-detector.js +263 -0
- package/dist/scanner/change-detector.js.map +1 -0
- package/dist/scanner/dependency-graph.d.ts +270 -0
- package/dist/scanner/dependency-graph.d.ts.map +1 -0
- package/dist/scanner/dependency-graph.js +436 -0
- package/dist/scanner/dependency-graph.js.map +1 -0
- package/dist/scanner/file-walker.d.ts +127 -0
- package/dist/scanner/file-walker.d.ts.map +1 -0
- package/dist/scanner/file-walker.js +526 -0
- package/dist/scanner/file-walker.js.map +1 -0
- package/dist/scanner/index.d.ts +12 -0
- package/dist/scanner/index.d.ts.map +1 -0
- package/dist/scanner/index.js +12 -0
- package/dist/scanner/index.js.map +1 -0
- package/dist/scanner/types.d.ts +218 -0
- package/dist/scanner/types.d.ts.map +1 -0
- package/dist/scanner/types.js +10 -0
- package/dist/scanner/types.js.map +1 -0
- package/dist/scanner/worker-pool.d.ts +317 -0
- package/dist/scanner/worker-pool.d.ts.map +1 -0
- package/dist/scanner/worker-pool.js +571 -0
- package/dist/scanner/worker-pool.js.map +1 -0
- package/dist/store/cache-manager.d.ts +179 -0
- package/dist/store/cache-manager.d.ts.map +1 -0
- package/dist/store/cache-manager.js +391 -0
- package/dist/store/cache-manager.js.map +1 -0
- package/dist/store/history-store.d.ts +314 -0
- package/dist/store/history-store.d.ts.map +1 -0
- package/dist/store/history-store.js +707 -0
- package/dist/store/history-store.js.map +1 -0
- package/dist/store/index.d.ts +20 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +26 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/lock-file-manager.d.ts +202 -0
- package/dist/store/lock-file-manager.d.ts.map +1 -0
- package/dist/store/lock-file-manager.js +475 -0
- package/dist/store/lock-file-manager.js.map +1 -0
- package/dist/store/pattern-store.d.ts +289 -0
- package/dist/store/pattern-store.d.ts.map +1 -0
- package/dist/store/pattern-store.js +936 -0
- package/dist/store/pattern-store.js.map +1 -0
- package/dist/store/schema-validator.d.ts +159 -0
- package/dist/store/schema-validator.d.ts.map +1 -0
- package/dist/store/schema-validator.js +1096 -0
- package/dist/store/schema-validator.js.map +1 -0
- package/dist/store/types.d.ts +585 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/types.js +82 -0
- package/dist/store/types.js.map +1 -0
- package/dist/types/analysis.d.ts +19 -0
- package/dist/types/analysis.d.ts.map +1 -0
- package/dist/types/analysis.js +5 -0
- package/dist/types/analysis.js.map +1 -0
- package/dist/types/common.d.ts +7 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +5 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/patterns.d.ts +40 -0
- package/dist/types/patterns.d.ts.map +1 -0
- package/dist/types/patterns.js +7 -0
- package/dist/types/patterns.js.map +1 -0
- package/dist/types/violations.d.ts +7 -0
- package/dist/types/violations.d.ts.map +1 -0
- package/dist/types/violations.js +7 -0
- package/dist/types/violations.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confidence Scorer - Pattern confidence calculation
|
|
3
|
+
*
|
|
4
|
+
* Calculates confidence scores based on frequency, consistency,
|
|
5
|
+
* age, and spread. Classifies patterns into confidence levels.
|
|
6
|
+
*
|
|
7
|
+
* The confidence score is a weighted combination of four factors:
|
|
8
|
+
* - Frequency: How often the pattern appears relative to applicable locations
|
|
9
|
+
* - Consistency: How consistent the pattern implementation is across occurrences
|
|
10
|
+
* - Age: How long the pattern has been observed (normalized)
|
|
11
|
+
* - Spread: How many files contain the pattern relative to total files
|
|
12
|
+
*
|
|
13
|
+
* @requirements 5.1 - Pattern confidence scoring with frequency, consistency, age, spread factors
|
|
14
|
+
* @requirements 5.2 - Confidence score SHALL be a decimal value between 0.0 and 1.0
|
|
15
|
+
* @requirements 5.3 - High confidence: score >= 0.85
|
|
16
|
+
* @requirements 5.4 - Medium confidence: score >= 0.70 and < 0.85
|
|
17
|
+
* @requirements 5.5 - Low confidence: score >= 0.50 and < 0.70
|
|
18
|
+
* @requirements 5.6 - Uncertain: score < 0.50
|
|
19
|
+
*/
|
|
20
|
+
import { CONFIDENCE_THRESHOLDS, DEFAULT_CONFIDENCE_WEIGHTS, } from './types.js';
|
|
21
|
+
/**
|
|
22
|
+
* Default age normalization configuration
|
|
23
|
+
*/
|
|
24
|
+
export const DEFAULT_AGE_CONFIG = {
|
|
25
|
+
maxAgeDays: 30,
|
|
26
|
+
minAgeFactor: 0.1,
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* ConfidenceScorer class for calculating pattern confidence scores.
|
|
30
|
+
*
|
|
31
|
+
* Calculates a weighted confidence score from four factors:
|
|
32
|
+
* - Frequency: occurrences / totalLocations
|
|
33
|
+
* - Consistency: 1 - variance (inverted so higher is better)
|
|
34
|
+
* - Age: normalized based on days since first seen
|
|
35
|
+
* - Spread: fileCount / totalFiles
|
|
36
|
+
*
|
|
37
|
+
* The final score is classified into confidence levels:
|
|
38
|
+
* - High: score >= 0.85
|
|
39
|
+
* - Medium: score >= 0.70 and < 0.85
|
|
40
|
+
* - Low: score >= 0.50 and < 0.70
|
|
41
|
+
* - Uncertain: score < 0.50
|
|
42
|
+
*
|
|
43
|
+
* @requirements 5.1, 5.2, 5.3, 5.4, 5.5, 5.6
|
|
44
|
+
*/
|
|
45
|
+
export class ConfidenceScorer {
|
|
46
|
+
weights;
|
|
47
|
+
ageConfig;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new ConfidenceScorer instance.
|
|
50
|
+
*
|
|
51
|
+
* @param weights - Optional custom weights for score calculation
|
|
52
|
+
* @param ageConfig - Optional custom age normalization configuration
|
|
53
|
+
*/
|
|
54
|
+
constructor(weights, ageConfig) {
|
|
55
|
+
this.weights = {
|
|
56
|
+
...DEFAULT_CONFIDENCE_WEIGHTS,
|
|
57
|
+
...weights,
|
|
58
|
+
};
|
|
59
|
+
this.ageConfig = {
|
|
60
|
+
...DEFAULT_AGE_CONFIG,
|
|
61
|
+
...ageConfig,
|
|
62
|
+
};
|
|
63
|
+
// Validate weights sum to 1.0 (with small tolerance for floating point)
|
|
64
|
+
this.validateWeights();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Calculate the confidence score for a pattern.
|
|
68
|
+
*
|
|
69
|
+
* @param input - The input data for confidence calculation
|
|
70
|
+
* @returns The calculated confidence score with all factors
|
|
71
|
+
*
|
|
72
|
+
* @requirements 5.1 - Pattern confidence scoring with frequency, consistency, age, spread factors
|
|
73
|
+
* @requirements 5.2 - Confidence score SHALL be a decimal value between 0.0 and 1.0
|
|
74
|
+
*/
|
|
75
|
+
calculateScore(input) {
|
|
76
|
+
// Calculate individual factors
|
|
77
|
+
const frequency = this.calculateFrequency(input.occurrences, input.totalLocations);
|
|
78
|
+
const consistency = this.calculateConsistency(input.variance);
|
|
79
|
+
const ageFactor = this.calculateAgeFactor(input.daysSinceFirstSeen);
|
|
80
|
+
const spread = this.calculateSpread(input.fileCount, input.totalFiles);
|
|
81
|
+
// Calculate weighted score
|
|
82
|
+
const weightedScore = frequency * this.weights.frequency +
|
|
83
|
+
consistency * this.weights.consistency +
|
|
84
|
+
ageFactor * this.weights.age +
|
|
85
|
+
spread * this.weights.spread;
|
|
86
|
+
// Clamp score to [0.0, 1.0] range
|
|
87
|
+
const score = this.clamp(weightedScore, 0.0, 1.0);
|
|
88
|
+
// Classify into confidence level
|
|
89
|
+
const level = this.classifyLevel(score);
|
|
90
|
+
return {
|
|
91
|
+
frequency,
|
|
92
|
+
consistency,
|
|
93
|
+
age: input.daysSinceFirstSeen,
|
|
94
|
+
spread: input.fileCount,
|
|
95
|
+
score,
|
|
96
|
+
level,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Calculate the frequency factor.
|
|
101
|
+
*
|
|
102
|
+
* Frequency = occurrences / totalLocations
|
|
103
|
+
* Represents how often the pattern appears relative to applicable locations.
|
|
104
|
+
*
|
|
105
|
+
* @param occurrences - Number of pattern occurrences
|
|
106
|
+
* @param totalLocations - Total applicable locations
|
|
107
|
+
* @returns Frequency factor (0.0 to 1.0)
|
|
108
|
+
*
|
|
109
|
+
* @requirements 5.1 - Frequency factor in confidence scoring
|
|
110
|
+
*/
|
|
111
|
+
calculateFrequency(occurrences, totalLocations) {
|
|
112
|
+
// Handle edge cases
|
|
113
|
+
if (totalLocations <= 0) {
|
|
114
|
+
return 0.0;
|
|
115
|
+
}
|
|
116
|
+
if (occurrences <= 0) {
|
|
117
|
+
return 0.0;
|
|
118
|
+
}
|
|
119
|
+
// Calculate frequency ratio
|
|
120
|
+
const frequency = occurrences / totalLocations;
|
|
121
|
+
// Clamp to [0.0, 1.0] range
|
|
122
|
+
return this.clamp(frequency, 0.0, 1.0);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Calculate the consistency factor.
|
|
126
|
+
*
|
|
127
|
+
* Consistency = 1 - variance
|
|
128
|
+
* Higher consistency means less variance in pattern implementation.
|
|
129
|
+
* Variance should be normalized to [0.0, 1.0] range.
|
|
130
|
+
*
|
|
131
|
+
* @param variance - Variance in pattern implementation (0 = perfectly consistent)
|
|
132
|
+
* @returns Consistency factor (0.0 to 1.0)
|
|
133
|
+
*
|
|
134
|
+
* @requirements 5.1 - Consistency factor in confidence scoring
|
|
135
|
+
*/
|
|
136
|
+
calculateConsistency(variance) {
|
|
137
|
+
// Handle edge cases
|
|
138
|
+
if (variance < 0) {
|
|
139
|
+
// Negative variance is invalid, treat as 0
|
|
140
|
+
return 1.0;
|
|
141
|
+
}
|
|
142
|
+
// Clamp variance to [0.0, 1.0] range
|
|
143
|
+
const clampedVariance = this.clamp(variance, 0.0, 1.0);
|
|
144
|
+
// Consistency is inverse of variance
|
|
145
|
+
return 1.0 - clampedVariance;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Calculate the age factor.
|
|
149
|
+
*
|
|
150
|
+
* Age factor is normalized based on days since first observation.
|
|
151
|
+
* Older patterns get higher scores (more established).
|
|
152
|
+
* Uses logarithmic scaling for diminishing returns after maxAgeDays.
|
|
153
|
+
*
|
|
154
|
+
* @param daysSinceFirstSeen - Days since pattern was first observed
|
|
155
|
+
* @returns Age factor (0.0 to 1.0)
|
|
156
|
+
*
|
|
157
|
+
* @requirements 5.1 - Age factor in confidence scoring
|
|
158
|
+
*/
|
|
159
|
+
calculateAgeFactor(daysSinceFirstSeen) {
|
|
160
|
+
// Handle edge cases
|
|
161
|
+
if (daysSinceFirstSeen <= 0) {
|
|
162
|
+
return this.ageConfig.minAgeFactor;
|
|
163
|
+
}
|
|
164
|
+
// Linear scaling up to maxAgeDays
|
|
165
|
+
if (daysSinceFirstSeen >= this.ageConfig.maxAgeDays) {
|
|
166
|
+
return 1.0;
|
|
167
|
+
}
|
|
168
|
+
// Calculate normalized age factor
|
|
169
|
+
const normalizedAge = daysSinceFirstSeen / this.ageConfig.maxAgeDays;
|
|
170
|
+
// Scale between minAgeFactor and 1.0
|
|
171
|
+
const ageFactor = this.ageConfig.minAgeFactor +
|
|
172
|
+
normalizedAge * (1.0 - this.ageConfig.minAgeFactor);
|
|
173
|
+
return this.clamp(ageFactor, 0.0, 1.0);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Calculate the spread factor.
|
|
177
|
+
*
|
|
178
|
+
* Spread = fileCount / totalFiles
|
|
179
|
+
* Represents how widely the pattern is used across the codebase.
|
|
180
|
+
*
|
|
181
|
+
* @param fileCount - Number of files containing the pattern
|
|
182
|
+
* @param totalFiles - Total files in scope
|
|
183
|
+
* @returns Spread factor (0.0 to 1.0)
|
|
184
|
+
*
|
|
185
|
+
* @requirements 5.1 - Spread factor in confidence scoring
|
|
186
|
+
*/
|
|
187
|
+
calculateSpread(fileCount, totalFiles) {
|
|
188
|
+
// Handle edge cases
|
|
189
|
+
if (totalFiles <= 0) {
|
|
190
|
+
return 0.0;
|
|
191
|
+
}
|
|
192
|
+
if (fileCount <= 0) {
|
|
193
|
+
return 0.0;
|
|
194
|
+
}
|
|
195
|
+
// Calculate spread ratio
|
|
196
|
+
const spread = fileCount / totalFiles;
|
|
197
|
+
// Clamp to [0.0, 1.0] range
|
|
198
|
+
return this.clamp(spread, 0.0, 1.0);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Classify a score into a confidence level.
|
|
202
|
+
*
|
|
203
|
+
* @param score - The confidence score (0.0 to 1.0)
|
|
204
|
+
* @returns The confidence level classification
|
|
205
|
+
*
|
|
206
|
+
* @requirements 5.3 - High confidence: score >= 0.85
|
|
207
|
+
* @requirements 5.4 - Medium confidence: score >= 0.70 and < 0.85
|
|
208
|
+
* @requirements 5.5 - Low confidence: score >= 0.50 and < 0.70
|
|
209
|
+
* @requirements 5.6 - Uncertain: score < 0.50
|
|
210
|
+
*/
|
|
211
|
+
classifyLevel(score) {
|
|
212
|
+
if (score >= CONFIDENCE_THRESHOLDS.HIGH) {
|
|
213
|
+
return 'high';
|
|
214
|
+
}
|
|
215
|
+
if (score >= CONFIDENCE_THRESHOLDS.MEDIUM) {
|
|
216
|
+
return 'medium';
|
|
217
|
+
}
|
|
218
|
+
if (score >= CONFIDENCE_THRESHOLDS.LOW) {
|
|
219
|
+
return 'low';
|
|
220
|
+
}
|
|
221
|
+
return 'uncertain';
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get the current weights configuration.
|
|
225
|
+
*
|
|
226
|
+
* @returns The current confidence weights
|
|
227
|
+
*/
|
|
228
|
+
getWeights() {
|
|
229
|
+
return { ...this.weights };
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Get the current age normalization configuration.
|
|
233
|
+
*
|
|
234
|
+
* @returns The current age configuration
|
|
235
|
+
*/
|
|
236
|
+
getAgeConfig() {
|
|
237
|
+
return { ...this.ageConfig };
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Validate that weights sum to approximately 1.0.
|
|
241
|
+
* Throws an error if weights are invalid.
|
|
242
|
+
*/
|
|
243
|
+
validateWeights() {
|
|
244
|
+
const sum = this.weights.frequency +
|
|
245
|
+
this.weights.consistency +
|
|
246
|
+
this.weights.age +
|
|
247
|
+
this.weights.spread;
|
|
248
|
+
// Allow small tolerance for floating point errors
|
|
249
|
+
const tolerance = 0.001;
|
|
250
|
+
if (Math.abs(sum - 1.0) > tolerance) {
|
|
251
|
+
throw new Error(`Confidence weights must sum to 1.0, but got ${sum.toFixed(4)}. ` +
|
|
252
|
+
`Weights: frequency=${this.weights.frequency}, consistency=${this.weights.consistency}, ` +
|
|
253
|
+
`age=${this.weights.age}, spread=${this.weights.spread}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Clamp a value to a range.
|
|
258
|
+
*
|
|
259
|
+
* @param value - The value to clamp
|
|
260
|
+
* @param min - Minimum value
|
|
261
|
+
* @param max - Maximum value
|
|
262
|
+
* @returns The clamped value
|
|
263
|
+
*/
|
|
264
|
+
clamp(value, min, max) {
|
|
265
|
+
return Math.max(min, Math.min(max, value));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Create a confidence score from raw values.
|
|
270
|
+
* Utility function for creating ConfidenceScore objects directly.
|
|
271
|
+
*
|
|
272
|
+
* @param frequency - Frequency factor (0.0 to 1.0)
|
|
273
|
+
* @param consistency - Consistency factor (0.0 to 1.0)
|
|
274
|
+
* @param age - Age in days
|
|
275
|
+
* @param spread - Number of files
|
|
276
|
+
* @param score - Overall score (0.0 to 1.0)
|
|
277
|
+
* @returns A ConfidenceScore object
|
|
278
|
+
*/
|
|
279
|
+
export function createConfidenceScore(frequency, consistency, age, spread, score) {
|
|
280
|
+
const scorer = new ConfidenceScorer();
|
|
281
|
+
const level = scorer.classifyLevel(score);
|
|
282
|
+
return {
|
|
283
|
+
frequency,
|
|
284
|
+
consistency,
|
|
285
|
+
age,
|
|
286
|
+
spread,
|
|
287
|
+
score,
|
|
288
|
+
level,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Calculate confidence score using default weights.
|
|
293
|
+
* Convenience function for quick calculations.
|
|
294
|
+
*
|
|
295
|
+
* @param input - The input data for confidence calculation
|
|
296
|
+
* @returns The calculated confidence score
|
|
297
|
+
*/
|
|
298
|
+
export function calculateConfidence(input) {
|
|
299
|
+
const scorer = new ConfidenceScorer();
|
|
300
|
+
return scorer.calculateScore(input);
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=confidence-scorer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confidence-scorer.js","sourceRoot":"","sources":["../../src/matcher/confidence-scorer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AASH,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KAAK;KACN,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAsB;IACxD,MAAM,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACtC,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matcher module exports
|
|
3
|
+
*
|
|
4
|
+
* Provides pattern matching, confidence scoring, and outlier detection.
|
|
5
|
+
* This module is responsible for:
|
|
6
|
+
* - Matching code against pattern definitions
|
|
7
|
+
* - Calculating confidence scores based on frequency, consistency, age, and spread
|
|
8
|
+
* - Detecting statistical outliers that deviate from established patterns
|
|
9
|
+
*
|
|
10
|
+
* @requirements 5.1 - Pattern confidence scoring with frequency, consistency, age, spread factors
|
|
11
|
+
* @requirements 5.2 - Confidence score SHALL be a decimal value between 0.0 and 1.0
|
|
12
|
+
* @requirements 5.3 - High confidence: score >= 0.85
|
|
13
|
+
* @requirements 5.4 - Medium confidence: score >= 0.70 and < 0.85
|
|
14
|
+
* @requirements 5.5 - Low confidence: score >= 0.50 and < 0.70
|
|
15
|
+
* @requirements 5.6 - Uncertain: score < 0.50
|
|
16
|
+
* @requirements 5.7 - Outlier detection for code that deviates from patterns
|
|
17
|
+
*/
|
|
18
|
+
export * from './types.js';
|
|
19
|
+
export type { Location, SourceRange, MatchType, ExtendedMatchType, ConfidenceLevel, ConfidenceScore, ConfidenceWeights, ConfidenceInput, PatternMatch, PatternMatchResult, AggregatedMatchResult, PatternDefinition, ASTMatchConfig, RegexMatchConfig, StructuralMatchConfig, PatternMetadata, OutlierInfo, OutlierType, OutlierSignificance, OutlierContext, OutlierStatistics, OutlierDetectionResult, OutlierDetectionMethod, MatcherConfig, MatcherCacheConfig, MatcherContext, MatchingResult, MatchingError, } from './types.js';
|
|
20
|
+
export { CONFIDENCE_THRESHOLDS, DEFAULT_CONFIDENCE_WEIGHTS, } from './types.js';
|
|
21
|
+
export { PatternMatcher, type MatchOptions } from './pattern-matcher.js';
|
|
22
|
+
export { ConfidenceScorer, calculateConfidence, createConfidenceScore, type AgeNormalizationConfig, DEFAULT_AGE_CONFIG, } from './confidence-scorer.js';
|
|
23
|
+
export { OutlierDetector, detectOutliers, calculateStatistics, type OutlierDetectorConfig, type DataPoint, type OutlierRule, DEFAULT_OUTLIER_CONFIG, } from './outlier-detector.js';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/matcher/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,cAAc,YAAY,CAAC;AAG3B,YAAY,EAEV,QAAQ,EACR,WAAW,EAGX,SAAS,EACT,iBAAiB,EAGjB,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,eAAe,EAGf,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EAGrB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EAGf,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EAGtB,aAAa,EACb,kBAAkB,EAGlB,cAAc,EACd,cAAc,EACd,aAAa,GACd,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,sBAAsB,EAC3B,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matcher module exports
|
|
3
|
+
*
|
|
4
|
+
* Provides pattern matching, confidence scoring, and outlier detection.
|
|
5
|
+
* This module is responsible for:
|
|
6
|
+
* - Matching code against pattern definitions
|
|
7
|
+
* - Calculating confidence scores based on frequency, consistency, age, and spread
|
|
8
|
+
* - Detecting statistical outliers that deviate from established patterns
|
|
9
|
+
*
|
|
10
|
+
* @requirements 5.1 - Pattern confidence scoring with frequency, consistency, age, spread factors
|
|
11
|
+
* @requirements 5.2 - Confidence score SHALL be a decimal value between 0.0 and 1.0
|
|
12
|
+
* @requirements 5.3 - High confidence: score >= 0.85
|
|
13
|
+
* @requirements 5.4 - Medium confidence: score >= 0.70 and < 0.85
|
|
14
|
+
* @requirements 5.5 - Low confidence: score >= 0.50 and < 0.70
|
|
15
|
+
* @requirements 5.6 - Uncertain: score < 0.50
|
|
16
|
+
* @requirements 5.7 - Outlier detection for code that deviates from patterns
|
|
17
|
+
*/
|
|
18
|
+
// Export all types
|
|
19
|
+
export * from './types.js';
|
|
20
|
+
// Export constants
|
|
21
|
+
export { CONFIDENCE_THRESHOLDS, DEFAULT_CONFIDENCE_WEIGHTS, } from './types.js';
|
|
22
|
+
// Export matcher components
|
|
23
|
+
export { PatternMatcher } from './pattern-matcher.js';
|
|
24
|
+
export { ConfidenceScorer, calculateConfidence, createConfidenceScore, DEFAULT_AGE_CONFIG, } from './confidence-scorer.js';
|
|
25
|
+
export { OutlierDetector, detectOutliers, calculateStatistics, DEFAULT_OUTLIER_CONFIG, } from './outlier-detector.js';
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/matcher/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,mBAAmB;AACnB,cAAc,YAAY,CAAC;AAiD3B,mBAAmB;AACnB,OAAO,EACL,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AAEpB,4BAA4B;AAC5B,OAAO,EAAE,cAAc,EAAqB,MAAM,sBAAsB,CAAC;AACzE,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EAErB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,EAInB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outlier Detector - Statistical outlier detection for pattern deviations
|
|
3
|
+
*
|
|
4
|
+
* Identifies code that deviates from established patterns using statistical
|
|
5
|
+
* methods including z-score analysis, IQR (Interquartile Range) detection,
|
|
6
|
+
* and rule-based detection for specific pattern violations.
|
|
7
|
+
*
|
|
8
|
+
* @requirements 5.7 - Outlier detection for code that deviates from patterns
|
|
9
|
+
*/
|
|
10
|
+
import type { PatternMatchResult, OutlierInfo, OutlierType, OutlierDetectionResult, OutlierDetectionMethod } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for outlier detection
|
|
13
|
+
*/
|
|
14
|
+
export interface OutlierDetectorConfig {
|
|
15
|
+
/**
|
|
16
|
+
* Sensitivity threshold for outlier detection (0.0 to 1.0)
|
|
17
|
+
* Lower values = more sensitive (more outliers detected)
|
|
18
|
+
* Default: 0.5
|
|
19
|
+
*/
|
|
20
|
+
sensitivity: number;
|
|
21
|
+
/**
|
|
22
|
+
* Z-score threshold for statistical outlier detection
|
|
23
|
+
* Values with z-score above this are considered outliers
|
|
24
|
+
* Default: 2.0 (approximately 95% confidence)
|
|
25
|
+
*/
|
|
26
|
+
zScoreThreshold: number;
|
|
27
|
+
/**
|
|
28
|
+
* IQR multiplier for IQR-based outlier detection
|
|
29
|
+
* Values outside Q1 - (multiplier * IQR) or Q3 + (multiplier * IQR) are outliers
|
|
30
|
+
* Default: 1.5 (standard Tukey fence)
|
|
31
|
+
*/
|
|
32
|
+
iqrMultiplier: number;
|
|
33
|
+
/**
|
|
34
|
+
* Minimum sample size for statistical detection
|
|
35
|
+
* Below this, rule-based detection is used instead
|
|
36
|
+
* Default: 5
|
|
37
|
+
*/
|
|
38
|
+
minSampleSize: number;
|
|
39
|
+
/**
|
|
40
|
+
* Detection method to use
|
|
41
|
+
* Default: 'statistical'
|
|
42
|
+
*/
|
|
43
|
+
method: OutlierDetectionMethod;
|
|
44
|
+
/**
|
|
45
|
+
* Whether to include context information in outlier results
|
|
46
|
+
* Default: true
|
|
47
|
+
*/
|
|
48
|
+
includeContext: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Default outlier detector configuration
|
|
52
|
+
*/
|
|
53
|
+
export declare const DEFAULT_OUTLIER_CONFIG: OutlierDetectorConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Input data point for outlier analysis
|
|
56
|
+
*/
|
|
57
|
+
export interface DataPoint {
|
|
58
|
+
/** The value to analyze */
|
|
59
|
+
value: number;
|
|
60
|
+
/** Associated pattern match result */
|
|
61
|
+
match: PatternMatchResult;
|
|
62
|
+
/** Optional label for the data point */
|
|
63
|
+
label?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Rule definition for rule-based outlier detection
|
|
67
|
+
*/
|
|
68
|
+
export interface OutlierRule {
|
|
69
|
+
/** Rule identifier */
|
|
70
|
+
id: string;
|
|
71
|
+
/** Rule name */
|
|
72
|
+
name: string;
|
|
73
|
+
/** Outlier type this rule detects */
|
|
74
|
+
type: OutlierType;
|
|
75
|
+
/** Function to check if a match violates the rule */
|
|
76
|
+
check: (match: PatternMatchResult, allMatches: PatternMatchResult[]) => boolean;
|
|
77
|
+
/** Function to generate the reason for the outlier */
|
|
78
|
+
getReason: (match: PatternMatchResult) => string;
|
|
79
|
+
/** Expected value/structure */
|
|
80
|
+
getExpected?: (match: PatternMatchResult, allMatches: PatternMatchResult[]) => string;
|
|
81
|
+
/** Suggested fix */
|
|
82
|
+
getSuggestedFix?: (match: PatternMatchResult) => string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* OutlierDetector class for detecting statistical outliers in pattern matches.
|
|
86
|
+
*
|
|
87
|
+
* Supports multiple detection methods:
|
|
88
|
+
* - Statistical: Uses z-score and IQR analysis
|
|
89
|
+
* - Rule-based: Uses predefined rules for specific violations
|
|
90
|
+
* - Clustering: Groups similar matches and identifies outliers (future)
|
|
91
|
+
* - ML-based: Machine learning-based detection (future)
|
|
92
|
+
*
|
|
93
|
+
* @requirements 5.7 - Outlier detection for code that deviates from patterns
|
|
94
|
+
*/
|
|
95
|
+
export declare class OutlierDetector {
|
|
96
|
+
private config;
|
|
97
|
+
private rules;
|
|
98
|
+
/**
|
|
99
|
+
* Create a new OutlierDetector instance.
|
|
100
|
+
*
|
|
101
|
+
* @param config - Optional configuration for outlier detection
|
|
102
|
+
*/
|
|
103
|
+
constructor(config?: Partial<OutlierDetectorConfig>);
|
|
104
|
+
/**
|
|
105
|
+
* Detect outliers in a set of pattern matches.
|
|
106
|
+
*
|
|
107
|
+
* @param matches - Array of pattern match results to analyze
|
|
108
|
+
* @param patternId - ID of the pattern being analyzed
|
|
109
|
+
* @returns Outlier detection result with all detected outliers
|
|
110
|
+
*
|
|
111
|
+
* @requirements 5.7 - Outlier detection for code that deviates from patterns
|
|
112
|
+
*/
|
|
113
|
+
detect(matches: PatternMatchResult[], patternId: string): OutlierDetectionResult;
|
|
114
|
+
/**
|
|
115
|
+
* Detect outliers using statistical methods (z-score and IQR).
|
|
116
|
+
*
|
|
117
|
+
* @param matches - Pattern matches to analyze
|
|
118
|
+
* @param patternId - Pattern ID
|
|
119
|
+
* @returns Array of detected outliers
|
|
120
|
+
*/
|
|
121
|
+
detectStatistical(matches: PatternMatchResult[], patternId: string): OutlierInfo[];
|
|
122
|
+
/**
|
|
123
|
+
* Detect outliers using z-score method.
|
|
124
|
+
*
|
|
125
|
+
* Z-score measures how many standard deviations a value is from the mean.
|
|
126
|
+
* Values with |z-score| > threshold are considered outliers.
|
|
127
|
+
*
|
|
128
|
+
* @param dataPoints - Data points to analyze
|
|
129
|
+
* @param patternId - Pattern ID
|
|
130
|
+
* @returns Array of detected outliers
|
|
131
|
+
*/
|
|
132
|
+
detectByZScore(dataPoints: DataPoint[], patternId: string): OutlierInfo[];
|
|
133
|
+
/**
|
|
134
|
+
* Detect outliers using IQR (Interquartile Range) method.
|
|
135
|
+
*
|
|
136
|
+
* IQR is the range between Q1 (25th percentile) and Q3 (75th percentile).
|
|
137
|
+
* Values outside [Q1 - k*IQR, Q3 + k*IQR] are considered outliers.
|
|
138
|
+
*
|
|
139
|
+
* @param dataPoints - Data points to analyze
|
|
140
|
+
* @param patternId - Pattern ID
|
|
141
|
+
* @returns Array of detected outliers
|
|
142
|
+
*/
|
|
143
|
+
detectByIQR(dataPoints: DataPoint[], patternId: string): OutlierInfo[];
|
|
144
|
+
/**
|
|
145
|
+
* Detect outliers using rule-based detection.
|
|
146
|
+
*
|
|
147
|
+
* @param matches - Pattern matches to analyze
|
|
148
|
+
* @param patternId - Pattern ID
|
|
149
|
+
* @returns Array of detected outliers
|
|
150
|
+
*/
|
|
151
|
+
detectRuleBased(matches: PatternMatchResult[], patternId: string): OutlierInfo[];
|
|
152
|
+
/**
|
|
153
|
+
* Register a custom outlier detection rule.
|
|
154
|
+
*
|
|
155
|
+
* @param rule - The rule to register
|
|
156
|
+
*/
|
|
157
|
+
registerRule(rule: OutlierRule): void;
|
|
158
|
+
/**
|
|
159
|
+
* Unregister an outlier detection rule.
|
|
160
|
+
*
|
|
161
|
+
* @param ruleId - ID of the rule to unregister
|
|
162
|
+
* @returns True if the rule was removed, false if it didn't exist
|
|
163
|
+
*/
|
|
164
|
+
unregisterRule(ruleId: string): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Get all registered rules.
|
|
167
|
+
*
|
|
168
|
+
* @returns Array of registered rules
|
|
169
|
+
*/
|
|
170
|
+
getRules(): OutlierRule[];
|
|
171
|
+
/**
|
|
172
|
+
* Get the current configuration.
|
|
173
|
+
*
|
|
174
|
+
* @returns Copy of the current configuration
|
|
175
|
+
*/
|
|
176
|
+
getConfig(): OutlierDetectorConfig;
|
|
177
|
+
/**
|
|
178
|
+
* Update the configuration.
|
|
179
|
+
*
|
|
180
|
+
* @param config - Partial configuration to update
|
|
181
|
+
*/
|
|
182
|
+
updateConfig(config: Partial<OutlierDetectorConfig>): void;
|
|
183
|
+
/**
|
|
184
|
+
* Select the appropriate detection method based on sample size and config.
|
|
185
|
+
*/
|
|
186
|
+
private selectMethod;
|
|
187
|
+
/**
|
|
188
|
+
* Calculate basic statistics for a set of values.
|
|
189
|
+
*/
|
|
190
|
+
private calculateStatistics;
|
|
191
|
+
/**
|
|
192
|
+
* Calculate a quartile value from sorted data.
|
|
193
|
+
*/
|
|
194
|
+
private calculateQuartile;
|
|
195
|
+
/**
|
|
196
|
+
* Calculate the percentile rank of a value in a dataset.
|
|
197
|
+
*/
|
|
198
|
+
private calculatePercentile;
|
|
199
|
+
/**
|
|
200
|
+
* Classify outlier significance based on z-score.
|
|
201
|
+
*/
|
|
202
|
+
private classifySignificance;
|
|
203
|
+
/**
|
|
204
|
+
* Classify outlier significance based on IQR distance.
|
|
205
|
+
*/
|
|
206
|
+
private classifySignificanceByIQR;
|
|
207
|
+
/**
|
|
208
|
+
* Calculate deviation score from z-score (normalized to 0-1).
|
|
209
|
+
*/
|
|
210
|
+
private calculateDeviationScore;
|
|
211
|
+
/**
|
|
212
|
+
* Determine the outlier type based on match characteristics.
|
|
213
|
+
*/
|
|
214
|
+
private determineOutlierType;
|
|
215
|
+
/**
|
|
216
|
+
* Create an OutlierInfo object from match data.
|
|
217
|
+
*/
|
|
218
|
+
private createOutlierInfo;
|
|
219
|
+
/**
|
|
220
|
+
* Clamp a value to a range.
|
|
221
|
+
*/
|
|
222
|
+
private clamp;
|
|
223
|
+
/**
|
|
224
|
+
* Register default outlier detection rules.
|
|
225
|
+
*/
|
|
226
|
+
private registerDefaultRules;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Detect outliers using default configuration.
|
|
230
|
+
* Convenience function for quick outlier detection.
|
|
231
|
+
*
|
|
232
|
+
* @param matches - Pattern matches to analyze
|
|
233
|
+
* @param patternId - Pattern ID
|
|
234
|
+
* @returns Outlier detection result
|
|
235
|
+
*/
|
|
236
|
+
export declare function detectOutliers(matches: PatternMatchResult[], patternId: string): OutlierDetectionResult;
|
|
237
|
+
/**
|
|
238
|
+
* Calculate statistics for a set of values.
|
|
239
|
+
* Utility function for external use.
|
|
240
|
+
*
|
|
241
|
+
* @param values - Array of numeric values
|
|
242
|
+
* @returns Statistics object with mean, stddev, and quartiles
|
|
243
|
+
*/
|
|
244
|
+
export declare function calculateStatistics(values: number[]): {
|
|
245
|
+
mean: number;
|
|
246
|
+
standardDeviation: number;
|
|
247
|
+
q1: number;
|
|
248
|
+
median: number;
|
|
249
|
+
q3: number;
|
|
250
|
+
iqr: number;
|
|
251
|
+
};
|
|
252
|
+
//# sourceMappingURL=outlier-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outlier-detector.d.ts","sourceRoot":"","sources":["../../src/matcher/outlier-detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,WAAW,EAGX,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,MAAM,EAAE,sBAAsB,CAAC;IAE/B;;;OAGG;IACH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