confidence

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 7 Imported by: 0

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

func IsKnownFormatExtension(path string) bool

IsKnownFormatExtension returns true if the file extension maps to a recognized format.

func Validate

func Validate(r *Report) error

Validate checks that a report has valid data.

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.

const (
	FormatJSON Format = "json"
	FormatYAML Format = "yaml"
	FormatAuto Format = "auto"
)

func DetectFormat added in v1.1.0

func DetectFormat(path string) Format

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

func ParseFileWithFormat(path string, format Format) (*Report, error)

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

func ParseWithFormat(r io.Reader, format Format) (*Report, error)

ParseWithFormat reads and parses a confidence report from an io.Reader using the specified format.

func (*Report) CalculateScore

func (r *Report) CalculateScore() int

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

func (r *Report) EffectiveFailLabel() string

EffectiveFailLabel returns the custom fail label or "FAIL" if not specified.

func (*Report) EffectivePassLabel

func (r *Report) EffectivePassLabel() string

EffectivePassLabel returns the custom pass label or "PASS" if not specified.

func (*Report) Passed

func (r *Report) Passed() bool

Passed returns true if the score meets or exceeds the threshold.

func (*Report) ScoreValue added in v1.1.0

func (r *Report) ScoreValue() int

ScoreValue returns the score value, or 0 if nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL