Documentation
¶
Overview ¶
Package confidence provides types and parsing for confidence report JSON.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsKnownFormatExtension ¶ added in v1.1.1
IsKnownFormatExtension returns true if the file extension maps to a recognized format.
Types ¶
type ColorThresholds ¶
type ColorThresholds struct {
GreenAbove int `json:"greenAbove"`
YellowAbove int `json:"yellowAbove"`
}
ColorThresholds defines score boundaries for color coding. GreenAbove is the minimum score for green (success) color. YellowAbove is the minimum score for yellow (warning) color. Scores below YellowAbove are shown in red (danger).
func DefaultColorThresholds ¶
func DefaultColorThresholds() ColorThresholds
DefaultColorThresholds returns the default color thresholds.
type Factor ¶
type Factor struct {
Name string `json:"name"`
Score int `json:"score"`
Weight int `json:"weight"`
Threshold int `json:"threshold,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
}
Factor represents a single confidence factor contributing to the overall score.
type Format ¶
type Format string
Format represents the input file format.
func DetectFormat ¶ added in v1.1.0
DetectFormat returns the format based on file extension. Returns FormatJSON for .json files and unknown extensions. Callers can use IsKnownFormatExtension to check if the extension was recognized.
type Report ¶
type Report struct {
Title string `json:"title"`
Score *int `json:"score"`
Threshold int `json:"threshold"`
Description string `json:"description,omitempty"`
Factors []Factor `json:"factors,omitempty"`
Thresholds *ColorThresholds `json:"thresholds,omitempty"`
// Metadata fields
Version string `json:"version,omitempty"`
GeneratedAt string `json:"generatedAt,omitempty"`
Source string `json:"source,omitempty"`
// Custom labels
PassLabel string `json:"passLabel,omitempty"`
FailLabel string `json:"failLabel,omitempty"`
}
Report represents a complete confidence report with overall score and breakdown.
func ParseFileWithFormat ¶
ParseFileWithFormat reads and parses a confidence report from a file path using the specified format. If format is FormatAuto, it's detected from the extension.
func ParseWithFormat ¶
ParseWithFormat reads and parses a confidence report from an io.Reader using the specified format.
func (*Report) CalculateScore ¶
CalculateScore computes the weighted average score from factors. Returns 0 if no factors exist or total weight is zero.
func (*Report) EffectiveColorThresholds ¶
func (r *Report) EffectiveColorThresholds() ColorThresholds
EffectiveColorThresholds returns the report's thresholds or defaults if not specified.
func (*Report) EffectiveFailLabel ¶
EffectiveFailLabel returns the custom fail label or "FAIL" if not specified.
func (*Report) EffectivePassLabel ¶
EffectivePassLabel returns the custom pass label or "PASS" if not specified.
func (*Report) ScoreValue ¶ added in v1.1.0
ScoreValue returns the score value, or 0 if nil.