record

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Average

func Average(records []*api.Record, path string) (*float64, error)

Average returns the average value of the provided numeric path.

Using average on non-numeric paths will raise an error. Null values are ignored in the calculation. Returns null if all values are null.

func Confidence

func Confidence(records []*api.Record, path string, caseSensitive bool) (*float64, error)

Confidence describes the probability of having the one truly correct value for the provided path.

The resulting value is a float ranging from 0 to 1 representing a percentage.

Example: For the values ["a","a","a","b"]

a: 3 * 0.75

b: 1 * 0.25

confidence: 62.5%

Null values are ignored in the calculation. Returns null if all values are null.

func Count

func Count(records []*api.Record) int

Count returns the amount of records in the provided list.

Entries with nil values will be counted just as any non-nil entry.

func CountDistinct

func CountDistinct(records []*api.Record, paths []string, caseSensitive bool) (int, error)

CountDistinct returns the number of unique non-null values for the provided path.

If multiple paths were provided, then each unique combination of the path values will be considered. If all paths are null, then this does not count as a new value. However, if at least one path has a value, then this does count as a new value.

func Extract

func Extract(record *api.Record, path string) any

Extract provides the value of a record for the given path.

func ExtractArray

func ExtractArray(record *api.Record, path string) ([]any, error)

ExtractArray provides an array value of a record for the given path.

func ExtractNumber

func ExtractNumber(record *api.Record, path string) (*float64, error)

ExtractNumber provides a numeric value of a record for the given path.

func ExtractString

func ExtractString(record *api.Record, path string, caseSensitive bool) (*string, error)

ExtractString provides a string value of a record for the given path.

If the value of that path is an array or a map, it will stringify the value into JSON.

func ExtractTime

func ExtractTime(record *api.Record, path string) (*time.Time, error)

ExtractTime provides a time value of a record for the given path.

func Filter

func Filter(records []*api.Record, conditions []*FilterCondition) ([]*api.Record, error)

Filter returns a new RecordInsights that only contains the records for which the FilterCondition applies.

If no records match the filter condition, then an empty RecordInsights is returned.

func First

func First(records []*api.Record) *api.Record

First returns the first record from the provided list of records.

func Flatten

func Flatten(records []*api.Record, path string) ([]any, error)

Flatten merges the array on the given path of all records into a single array.

Using flatten on non-array fields will raise an error.

func FlattenDistinct

func FlattenDistinct(records []*api.Record, path string, caseSensitive bool) ([]any, error)

FlattenDistinct merges the array on the given path of all records into a single array where each value is unique.

Using flatten on non-array fields will raise an error.

By default, the case of the value is ignored.

func Group

func Group(records []*api.Record, paths []string, caseSensitive bool) ([][]*api.Record, error)

Group returns a list of record lists where the records have been grouped by the provided paths.

func Last

func Last(records []*api.Record) *api.Record

Last returns the last record from the provided list of records.

func Limit

func Limit(records []*api.Record, count int, offset int) []*api.Record

Limit returns a new record list that contains up to 'count' records.

By default it takes the first records from the list. If offset was provided it will skip 'offset' records.

If the list does not provide enough records, then an empty list is returned.

func Max

func Max(records []*api.Record, path string) (*float64, error)

Max returns the highest value of the provided numeric path.

Returns null if all values are null.

func Median

func Median(records []*api.Record, path string) (*float64, error)

Median returns the median value of the provided numeric path.

Using median on non-numeric paths will raise an error. Null values are ignored in the calculation. Returns null if all values are null.

func Min

func Min(records []*api.Record, path string) (*float64, error)

Min returns the lowest value of the provided numeric path.

Using min on non-numeric paths will raise an error. Returns null if all values are null.

func Newest

func Newest(records []*api.Record, path string) (*api.Record, error)

Newest returns the Record for where the provided time path has the highest (most recent) value.

Returns null if the list is empty or does not contain records with the provided path.

Using newest on non-time paths will raise an error.

func Oldest

func Oldest(records []*api.Record, path string) (*api.Record, error)

Oldest returns the Record for where the provided time path has the lowest (least recent) value.

Returns null if the list is empty or does not contain records with the provided path.

Using oldest on non-time paths will raise an error.

func Sort

func Sort(records []*api.Record, criteria []*SortCriteria) ([]*api.Record, error)

Sort returns a new RecordInsights that contains the records ordered by the provided SortCriteria.

func StandardDeviation

func StandardDeviation(records []*api.Record, path string) (*float64, error)

StandardDeviation calculates the standard deviation for the provided numeric path.

Using standardDeviation on non-numeric paths will raise an error. Null values are ignored in the calculation. Returns null if all values are null.

func Sum

func Sum(records []*api.Record, path string) (*float64, error)

Sum returns the sum of the provided numeric path.

Using sum on non-numeric paths will raise an error. Null values are ignored in the calculation. Returns null if all values are null.

func Values

func Values(records []*api.Record, path string) []any

Values returns all non-null values of the current records.

func ValuesDistinct

func ValuesDistinct(records []*api.Record, path string, caseSensitive bool) ([]any, error)

ValuesDistinct returns all unique non-null values of the current records. By default, the case of the value is ignored.

Types

type FilterCondition

type FilterCondition struct {
	Path string

	Equals any
	IsNull *bool

	StartsWith *string
	EndsWith   *string
	LikeRegex  *string

	LessThan      *float64
	LessEquals    *float64
	GreaterThan   *float64
	GreaterEquals *float64

	After  *time.Time
	Since  *time.Time
	Before *time.Time
	Until  *time.Time

	Invert        *bool
	CaseSensitive *bool
}

FilterCondition defines the criteria for filtering a record list.

Each filter condition must have a filter upon which the checks are applied and should have at least one criteria defined.

Some criteria are mutually exclusive due to either logical reasons or type constraints. E.g. lessThan and after cannot be used together due to different type expectations.

type FrequencyDistributionEntry

type FrequencyDistributionEntry struct {
	Value      any     `json:"value"`
	Frequency  int     `json:"frequency"`
	Percentage float64 `json:"percentage"`
	// contains filtered or unexported fields
}

FrequencyDistributionEntry represents a single row of a frequency distribution table.

func FrequencyDistribution

func FrequencyDistribution(records []*api.Record, path string, caseSensitive bool, top int, sortASC bool) ([]*FrequencyDistributionEntry, error)

FrequencyDistribution returns how often a non-null value for the provided field is present.

By default, the results are ordered with the highest percentage first, but it can be changed using the 'sortASC' option.

Using the 'top' option it is possible to limit the results to only the n highest or lowest results.

Values with with equal frequency will always be returned in the order of the first occurrence for that value.

type SortCriteria

type SortCriteria struct {
	Path string
	ASC  bool
}

SortCriteria defines how to sort.

Jump to

Keyboard shortcuts

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