streams

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package streams provides a way to access predictions in a YAML stream.

YAML streams contain one or more documents in them, separated by three hyphen-minuses (---). In streams that we’re using, the first document functions as a metadata header while all subsequent documents are predictions. Each prediction, with few exceptions, has both a claim and a confidence.

Index

Constants

View Source
const (
	NeitherTitleNorScopeInMetadataBlock = ValidationError("Neither title nor scope in metadata block")
)

Various errors returned when decoding documents out of a stream and into structs.

Variables

This section is empty.

Functions

func ConfidencesUsed

func ConfidencesUsed(sts []Stream) []float64

ConfidencesUsed returns a list of all confidence intervals used in the given Streams.

func Everything

func Everything(_ PredictionDocument) bool

Everything is a Filter that filters nothing out.

func KeysUsed

func KeysUsed(sts []Stream) []string

KeysUsed returns a list of all keys used in the given Streams.

A “key”, here, is the title and scope of a given stream, with a space in between.

func NewErrorClaimMissing

func NewErrorClaimMissing(s Stream, i int) error

NewErrorClaimMissing returns an error that describes the approximate location of a prediction that has no claim.

func NewErrorConfidenceImpossible

func NewErrorConfidenceImpossible(s Stream, i int) error

NewErrorConfidenceImpossible returns an error describing a prediction that has a confidence level below 0% or above 100%.

func NewErrorConfidenceMissing

func NewErrorConfidenceMissing(s Stream, i int) error

NewErrorConfidenceMissing returns an error describing a prediction that lacks a confidence level.

func NewErrorConfidenceUnity

func NewErrorConfidenceUnity(s Stream, i int) error

NewErrorConfidenceUnity returns an error describing a prediction that has a confidence level of 100%.

func NewErrorConfidenceZero

func NewErrorConfidenceZero(s Stream, i int) error

NewErrorConfidenceZero returns an error describing a prediction that has a confidence level of zero.

func TagsUsed

func TagsUsed(sts []Stream) []string

TagsUsed returns a list of all tags used in the given slice of stream.Stream.

Types

type Filter

type Filter func(PredictionDocument) bool

A Filter removes predictions from consideration if the predicate returns false.

func MatchingConfidence

func MatchingConfidence(conf float64) Filter

MatchingConfidence returns a Filter that returns true if the prediction’s confidence level matches (to within a fudge factor) the given confidence level.

func MatchingKey

func MatchingKey(key string) Filter

MatchingKey returns a Filter that returns true if the prediction’s key matches the given key.

func MatchingTag

func MatchingTag(tag string) Filter

MatchingTag returns a Filter that returns true if the prediction’s tag matches the given tag.

type MetadataDocument

type MetadataDocument struct {
	Title string
	Scope string
	Salt  string
	Notes string

	// These are here to detect when a user accidentally omits a metadata document in a stream.
	MisplacedClaim      string `yaml:"claim"`
	MisplacedConfidence string `yaml:"confidence"`
}

A MetadataDocument contains information about the predictions in its Stream.

type PredictionDocument

type PredictionDocument struct {
	Claim             string
	Confidence        *float64
	Tags              []string
	Happened          *bool
	CauseForExclusion string `yaml:"cause for exclusion"`
	Hash              bool
	Salt              string
	Notes             string

	Parent *Stream
}

A PredictionDocument contains a claim, the claim’s confidence, and so on.

func DocumentsMatching

func DocumentsMatching(sts []Stream, f Filter) []PredictionDocument

DocumentsMatching returns PredictionDocuments from streams that pass the given Filter.

func (*PredictionDocument) HasTag

func (d *PredictionDocument) HasTag(tag string) bool

HasTag returns true if the given tag is in the receiver’s tag list.

func (*PredictionDocument) ShouldExclude

func (d *PredictionDocument) ShouldExclude() bool

ShouldExclude returns true if the receiver should be excluded from stats calculation.

type PredictionErrorMaker

type PredictionErrorMaker func(Stream, int) error

A PredictionErrorMaker takes a Stream and an index and returns an error. The index is meant to be the index of the prediction, so the first prediction is referred to with a zero index.

type Stream

type Stream struct {
	FromFilename string
	Metadata     MetadataDocument
	Predictions  []PredictionDocument
}

A Stream (YAML stream) contains a metadata document and predictions documents.

In YAML, documents are prefixed by “---”.

func FromFiles

func FromFiles(filenames []string) ([]Stream, error)

FromFiles generates a slice of Stream from the filenames specified.

func FromReader

func FromReader(r io.Reader) (Stream, error)

FromReader decodes into a Stream from an io.Reader.

type ValidationError

type ValidationError string

A ValidationError is returned when something about the stream isn’t right.

func (ValidationError) Error

func (e ValidationError) Error() string

type ValidationFunction

type ValidationFunction func(Stream) []error

A ValidationFunction ensures that a Stream passes a sanity check.

Because many things can go wrong in a Stream that a user would want to know about all at once, ValidationFunction returns a slice of error.

type Validator

type Validator struct{}

A Validator contains data useful for ValidationFunctions.

func (*Validator) AllConfidencesBetweenZeroAndOneHundredInclusive

func (sv *Validator) AllConfidencesBetweenZeroAndOneHundredInclusive(s Stream) []error

AllConfidencesBetweenZeroAndOneHundredInclusive ensures all confidences are on [0, 100].

func (*Validator) AllConfidencesSensible

func (sv *Validator) AllConfidencesSensible(s Stream) []error

AllConfidencesSensible ensures no confidence level is 0 or 100.

func (*Validator) AllPredictionsHaveClaims

func (sv *Validator) AllPredictionsHaveClaims(s Stream) []error

AllPredictionsHaveClaims ensures that all predictions in a stream have one claim in each.

func (*Validator) AllPredictionsHaveConfidences

func (sv *Validator) AllPredictionsHaveConfidences(s Stream) []error

AllPredictionsHaveConfidences ensures that all predictions have a confidence key and a value of some sort.

func (*Validator) HasTitleOrScopeInMetadataBlock

func (sv *Validator) HasTitleOrScopeInMetadataBlock(s Stream) []error

HasTitleOrScopeInMetadataBlock ensures that a stream has either title key or a scope key in the metadata block (or both). At least one of those keys’ values must be something other than the empty string.

func (*Validator) RunAll

func (sv *Validator) RunAll(s Stream) []error

RunAll is a convenience function to run all known stream validators.

func (*Validator) RunMinimal

func (sv *Validator) RunMinimal(s Stream) []error

RunMinimal is a convenience function to run the bare minimum of sanity checks.

func (*Validator) RunValidationFunctions

func (sv *Validator) RunValidationFunctions(s Stream, vfs ...ValidationFunction) []error

RunValidationFunctions runs a bunch of validation functions on a stream.

It returns a slice of error of everything that didn’t pass muster.

Jump to

Keyboard shortcuts

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