utils

package
v0.0.0-...-d8d2920 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: GPL-3.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Identifier = iota
	// e.g. 50
	Literal
	// e.g. + - * /
	Operator
	// ,
	COMMA
)

Variables

View Source
var Conf *viper.Viper
View Source
var EnumLocs []string
View Source
var Enums []string
View Source
var Limit int = 1e7

Limit is an absolute limit on number of iterations.

View Source
var MpLocs []string
View Source
var Mps []string
View Source
var Rdb *redis.Client
View Source
var TableLocs []string
View Source
var Tables []string

Functions

func Dur

func Dur(x Date, y Date) int

func ErrPos

func ErrPos(s string, pos int) string

func FieldsToCsvString

func FieldsToCsvString[T any](a T, suffix string) string

func FilePathToName

func FilePathToName(str string) (string, error)

func FindFieldByName

func FindFieldByName[T any](s T, fieldName string) (reflect.Value, bool)

func FindFile

func FindFile(tbl string) (fileLoc string)

func FindMp

func FindMp(fileName string) (fileLoc string)

todo: remove the below functions

func GetEnumName

func GetEnumName(enm string) string

func GetFileList

func GetFileList(root string, suffix string) (paths []string, err error)

func GetFileName

func GetFileName(s string) string

func GetFilePath

func GetFilePath(fileName string, paths []string) (fileLoc string)

func GetMongoClient

func GetMongoClient(ctx context.Context) *qmgo.Client

func GetRedisClient

func GetRedisClient() *redis.Client

func InitializePath

func InitializePath(path string)

func IntToClmTitle

func IntToClmTitle(n int) string

1 -> A, 2 -> B, 3 -> C, ..., 26 -> Z, 27 -> AA, 28 -> AB, ...

func IsDir

func IsDir(path string) bool

func IsFac

func IsFac(filePath string) bool

func LoadCsv

func LoadCsv[T any](fileName string, row T) []*T

func LoadFacHashToFastCache0814

func LoadFacHashToFastCache0814(filePath string, maxBytes int) ([]string, *fastcache.Cache)

func LoadFacHashToFastCacheBk

func LoadFacHashToFastCacheBk(filePath string, maxBytes int) *fastcache.Cache

func LoadFacToFastCache

func LoadFacToFastCache(filePath string, maxBytes int) *fastcache.Cache

func LoadFacToHashMap

func LoadFacToHashMap(filePath string) map[string]map[string]string

func LoadFacToMap

func LoadFacToMap(filePath string) map[string]string

func LoadFacToRedisHash

func LoadFacToRedisHash(filePath string)

func LoadFileToStruct

func LoadFileToStruct[T any](fileName string, skipLines int, dataStruct T) []*T

func LoadPropMpToChn

func LoadPropMpToChn[T any](fileName string, dataStruct T, dataChn chan *T)

func LoadPropMpToStruct

func LoadPropMpToStruct[T any](fileName string, dataStruct T) []*T

func MapContainsValue

func MapContainsValue[K, V comparable](m map[K]V, value V) bool

func MapUniqValues

func MapUniqValues[T comparable](m map[string]T) []T

func MergeStringSlices

func MergeStringSlices(slices ...[]string) []string

func ParseCsvMap

func ParseCsvMap(filename string) (map[string][]string, error)

func PivotFloat64

func PivotFloat64(data any, tags []string, fieldsToSum []string) map[string]map[string]float64

func ReadConfig

func ReadConfig(c *viper.Viper)

func ReadProdSpecs

func ReadProdSpecs(filePath string) ([]string, map[string][]string)

func RecordToCsvString

func RecordToCsvString[T any](record T, suffix string) string

func RemoveDup

func RemoveDup(this []*float64) []*float64

func ReplaceWholeWord

func ReplaceWholeWord(originalString string, oldWord string, newWord string) string

func SCA

func SCA(A [][]float64, b []float64, δ float64) (x []float64, i int, err error)

SCA solves the non-negative least squares problem.

Argument A represents a design or input matrix. Each element of A must have the same length. b represents a measurement or output vector. δ is a tolerance for the result.

Iteration will stop when the least squares objective is within δ of an optimal solution.

The result x returns coefficients of the fitted linear function, it will have the same length as elements of A. Result i is the number of iterations performed. An error is returned if A and b are not the same length.

func SCAKKT

func SCAKKT(A [][]float64, b []float64, ε float64) ([]float64, int, error)

SCAKKT solves the non-negative least squares problem.

Argument A represents a design or input matrix. Each element of A must have the same length. b represents a measurement or output vector. ε is a tolerance for stopping iteration.

Stopping criteria for this function are based on Karush–Kuhn–Tucker conditions (see https://en.wikipedia.org/wiki/Karush%E2%80%93Kuhn%E2%80%93Tucker_conditions). Iteration stops when a result is non-negative and the gradient of the objective function is within ε of KKT conditions. The advantage of this function over SCA is that stopping conditions are simpler to compute and so each iteration takes less time. The disadvantage is that the ε of this function is less obviously related to the objective function and stopping criteria are less clear.

The result x returns coefficients of the fitted linear function, it will have the same length as elements of A. Result i is the number of iterations performed. An error is returned if A and b are not the same length.

func SCALimit

func SCALimit(A [][]float64, b []float64, limit int) ([]float64, int, error)

SCALimit solves the non-negative least squares problem.

Argument A represents a design or input matrix. Each element of A must have the same length. b represents a measurement or output vector. limit is a maximum number of iterations.

Iteration will stops after limit iterations or when the result does not change from one iteration to the next. If argument limit is < 0, the package value Limit is used.

The result x returns coefficients of the fitted linear function, it will have the same length as elements of A. Result i is the number of iterations performed. An error is returned if A and b are not the same length.

func SetLogOutput

func SetLogOutput()

func StreamGenericCsvFile

func StreamGenericCsvFile[T any](filePath string, row T, dataChn chan *T)

func StreamGenericTxtFile

func StreamGenericTxtFile[T any](filePath string, headerLine int, row T, dataChn chan *T)

for MP source with header and contents in the same file

func StringExists

func StringExists(s []string, t string) bool

func WriteCsv

func WriteCsv(start, end Date, res ProjResult)

Types

type Date

type Date struct {
	Year  int
	Month int
}

func (Date) CalendarDate

func (this Date) CalendarDate(i int) Date

func (Date) CalendarMth

func (this Date) CalendarMth(t int) (res int)

func (Date) CalendarYr

func (this Date) CalendarYr(t int) (res int)

func (Date) DateStr

func (this Date) DateStr() (res string)

func (Date) DateValue

func (this Date) DateValue() (res int)

func (Date) T

func (this Date) T(Year, Month int) int

type Enum

type Enum struct {
	VarName string
	// contains filtered or unexported fields
}

bi-directional map

func LoadCsvToEnum

func LoadCsvToEnum(filePath string) *Enum

func NewEnum

func NewEnum() *Enum

func (*Enum) Add

func (m *Enum) Add(a int, b string)

func (*Enum) IntToStr

func (m *Enum) IntToStr(a int) (string, bool)

func (*Enum) SetNames

func (m *Enum) SetNames(idxName, varName string)

func (*Enum) Size

func (m *Enum) Size() int

func (*Enum) StrToInt

func (m *Enum) StrToInt(b string) (int, bool)

type Parser

type Parser struct {
	Source string
	// contains filtered or unexported fields
}

type ProjResult

type ProjResult struct {
	VarName string
	Res     []float64
}

type TblCache

type TblCache struct {
	Caches  *fastcache.Cache // cache for each table, with rowKey as keys
	SubKeys []string         // sub key for each record
}

func LoadFacToTblCache

func LoadFacToTblCache(filePath string, maxBytes int) *TblCache

type Token

type Token struct {
	// raw characters
	Tok string
	// type with Literal/Operator
	Type,
	Flag int
	Offset int
}

func Parse

func Parse(s string) ([]*Token, error)

Jump to

Keyboard shortcuts

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