mframe

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 10 Imported by: 0

README

mframe

Documentation

Overview

Package mframe provides a DataFrame struct and methods to manipulate it. This file contains the Filter and FindFirstByKey methods. The Filter method filters the DataFrame based on a given operator, key, value, and options. The FindFirstByKey method returns the first row that matches a given key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(value, substring string) bool

func EndsWith

func EndsWith(value, suffix string) bool

func Equals

func Equals(left, right interface{}) bool

func InCIDR

func InCIDR(value, cidr string) bool

func InList

func InList[v float64 | string, result bool](value v, list []v) result

func MajorThan

func MajorThan(left, right float64) bool

func MatchesRegExp

func MatchesRegExp(value, regExp string) bool

func StartsWith

func StartsWith(value, prefix string) bool

Types

type BooleansBTree

type BooleansBTree map[string]map[bool]map[uuid.UUID]bool

BooleansBTree is a map of string keys to map of boolean keys to map of UUID keys to boolean values.

type DataFrame

type DataFrame struct {
	Data     map[uuid.UUID]Row
	Keys     KeysBTree
	Strings  StringsBTree
	Numerics NumericsBTree
	Booleans BooleansBTree
	ExpireAt ExpireAtBTree
	Locker   sync.RWMutex
	TTL      time.Duration
}

DataFrame is a struct that holds data in a map of UUID keys to Row values, and several B-tree maps for indexing.

func (*DataFrame) Append

func (d *DataFrame) Append(df *DataFrame, key string)

Append appends the rows of a DataFrame to another DataFrame, adding a key column with the specified key value.

func (*DataFrame) Average

func (d *DataFrame) Average(name, field string) *DataFrame

Average returns a new DataFrame with the average of values in a column of the original DataFrame. The name parameter is used to set the name of the new column with the average value. The field parameter is used to specify the name of the column to calculate the average from.

func (*DataFrame) CleanExpired

func (d *DataFrame) CleanExpired()

CleanExpired removes elements from the DataFrame that have expired based on their expiration time. It runs in an infinite loop, checking for expired elements every second.

func (*DataFrame) Count

func (d *DataFrame) Count(name string) *DataFrame

Count returns a new DataFrame with the count of rows in the original DataFrame. The name parameter is used to set the name of the new column with the count value.

func (*DataFrame) CountUnique

func (d *DataFrame) CountUnique(name, field string) *DataFrame

CountUnique returns a new DataFrame with the count of unique values in a column of the original DataFrame. The name parameter is used to set the name of the new column with the count value. The field parameter is used to specify the name of the column to count unique values from.

func (*DataFrame) Filter

func (d *DataFrame) Filter(operator, key string, value interface{}, options map[string]bool) *DataFrame

Filter filters the DataFrame based on a given operator, key, value, and options. The supported operators are: - "==": equal to - "!=": not equal to - ">": greater than - "<": less than - ">=": greater than or equal to - "<=": less than or equal to - "in list": in list of values - "not in list": not in list of values - "regexp": matches regular expression - "not regexp": does not match regular expression - "in cidr": in CIDR range - "not in cidr": not in CIDR range - "contains": contains substring - "not contains": does not contain substring

func (*DataFrame) FindFirstByKey

func (d *DataFrame) FindFirstByKey(key string) (uuid.UUID, string, interface{})

FindFirstByKey returns the first row that matches a given key.

func (*DataFrame) Init

func (d *DataFrame) Init(ttl time.Duration)

Init initializes a DataFrame with a given TTL.

func (*DataFrame) Insert

func (d *DataFrame) Insert(data map[string]interface{})

Insert adds a new row to the DataFrame with the given data. The data is a map of string keys to interface{} values. The function indexes the data and adds it to the DataFrame. The function also generates a new UUID for the row and sets its expiration time. The function is thread-safe and uses a mutex to protect the DataFrame from concurrent writes.

func (*DataFrame) Max

func (d *DataFrame) Max(name, field string) *DataFrame

Max returns a new DataFrame with the maximum value in a column of the original DataFrame. The name parameter is used to set the name of the new column with the maximum value. The field parameter is used to specify the name of the column to find the maximum value from.

func (*DataFrame) Median

func (d *DataFrame) Median(name, field string) *DataFrame

Median returns a new DataFrame with the median of values in a column of the original DataFrame. The name parameter is used to set the name of the new column with the median value. The field parameter is used to specify the name of the column to calculate the median from.

func (*DataFrame) Min

func (d *DataFrame) Min(name, field string) *DataFrame

Min returns a new DataFrame with the minimum value in a column of the original DataFrame. The name parameter is used to set the name of the new column with the minimum value. The field parameter is used to specify the name of the column to find the minimum value from.

func (*DataFrame) RemoveElement

func (d *DataFrame) RemoveElement(id uuid.UUID)

RemoveElement removes an element from the DataFrame by its ID. It deletes the element from the Data, ExpireAt, Strings, Numerics, and Booleans maps.

func (*DataFrame) SliceOf

func (d *DataFrame) SliceOf(field string) []interface{}

SliceOf returns a slice of interface{} representing the values of a specific field in the DataFrame.

func (*DataFrame) SliceOfFloat64

func (d *DataFrame) SliceOfFloat64(field string) []float64

SliceOfFloat64 returns a slice of float64 representing the values of a specific field in the DataFrame. If a value cannot be converted to float64, it is skipped.

func (*DataFrame) Stats

func (d *DataFrame) Stats(name string)

Stats periodically logs statistics about the DataFrame.

func (*DataFrame) Sum

func (d *DataFrame) Sum(name, field string) *DataFrame

Sum returns a new DataFrame with the sum of values in a column of the original DataFrame. The name parameter is used to set the name of the new column with the sum value. The field parameter is used to specify the name of the column to sum values from.

func (*DataFrame) ToSlice

func (d *DataFrame) ToSlice() []map[string]interface{}

ToSlice returns a slice of maps representing the DataFrame's data. Each map contains the column names as keys and the corresponding row values as values.

func (*DataFrame) Variance

func (d *DataFrame) Variance(name, field string) *DataFrame

Variance returns a new DataFrame with the variance of values in a column of the original DataFrame. The name parameter is used to set the name of the new column with the variance value. The field parameter is used to specify the name of the column to calculate the variance from.

type ExpireAtBTree

type ExpireAtBTree map[uuid.UUID]time.Time

ExpireAtBTree is a map of UUID keys to time.Time values.

type KeysBTree

type KeysBTree map[string]string

KeysBTree is a map of string keys to string values.

type NumericsBTree

type NumericsBTree map[string]map[float64]map[uuid.UUID]bool

NumericsBTree is a map of string keys to map of float64 keys to map of UUID keys to boolean values.

type Row

type Row map[string]interface{}

Row is a map of string keys to interface{} values.

type StringsBTree

type StringsBTree map[string]map[string]map[uuid.UUID]bool

StringsBTree is a map of string keys to map of string keys to map of UUID keys to boolean values.

Jump to

Keyboard shortcuts

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