internal

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const Int64Max = 1<<63 - 1

Variables

View Source
var FifteenSeconds = 15 * time.Second
View Source
var FiveSeconds = 5 * time.Second
View Source
var KafkaUMHTopicCompiledRegex = regexp.MustCompile(KafkaUMHTopicRegex)
View Source
var KafkaUMHTopicRegex = `` /* 378-byte string literal not displayed */
View Source
var Marshal = func(v interface{}) (io.Reader, error) {
	b, err := json.MarshalIndent(v, "", "\t")
	if err != nil {
		return nil, err
	}
	return bytes.NewReader(b), nil
}

Marshal is a function that marshals the object into an io.Reader. By default, it uses the JSON marshaller.

View Source
var OneSecond = 1 * time.Second
View Source
var TenSeconds = 10 * time.Second
View Source
var Unmarshal = func(r io.Reader, v interface{}) error {
	return json.NewDecoder(r).Decode(v)
}

Unmarshal is a function that unmarshals the data from the reader into the specified value. By default, it uses the JSON unmarshaller.

Functions

func AsHash

func AsHash(o interface{}) string

AsHash returns a hash for a given interface

func AsXXHash

func AsXXHash(inputs ...[]byte) []byte

AsXXHash returns the XXHash128 of the given data. This hash is extremely fast and reasonable for use as a key in a cache. https://cyan4973.github.io/xxHash/

func Divmod

func Divmod(numerator, denominator int64) (quotient, remainder int64)

Divmod allows division with remainder. Source: https://stackoverflow.com/questions/43945675/division-with-returning-quotient-and-remainder

func EnvIsTrue

func EnvIsTrue(envVariable string) bool

func GetAssetIDFromCache

func GetAssetIDFromCache(customerID string, location string, assetID string) (DBassetID uint32, cacheHit bool)

GetAssetIDFromCache gets asset id from cache

func GetAverageStateTimeFromCache

func GetAverageStateTimeFromCache(key string) (data []interface{}, cacheHit bool)

GetAverageStateTimeFromCache gets average state time from cache

func GetBackoffTime

func GetBackoffTime(retries int64, slotTime time.Duration, maximum time.Duration) (backoff time.Duration)

func GetCalculatateLowSpeedStatesFromCache

func GetCalculatateLowSpeedStatesFromCache(from time.Time, to time.Time, assetID uint32) (processedStateArray []datamodel.StateEntry, cacheHit bool)

GetCalculatateLowSpeedStatesFromCache get low speed states from cache

func GetCustomerConfigurationFromCache

func GetCustomerConfigurationFromCache(customerID string) (data datamodel.CustomerConfiguration, cacheHit bool)

GetCustomerConfigurationFromCache gets customer configuration from cache

func GetDistinctProcessValuesFromCache

func GetDistinctProcessValuesFromCache(customerID string, location string, assetID string) (data []string, cacheHit bool)

GetDistinctProcessValuesFromCache gets distinct process values from cache

func GetMemcached

func GetMemcached(key string) (value interface{}, found bool)

func GetProcessStatesFromCache

func GetProcessStatesFromCache(key string) (processedStateArray []datamodel.StateEntry, cacheHit bool)

GetProcessStatesFromCache gets process states from cache

func GetProductIDFromCache

func GetProductIDFromCache(productName int32, DBassetID uint32) (DBProductId uint32, cacheHit bool)

GetProductIDFromCache gets Product from cache

func GetRawCountsFromCache

func GetRawCountsFromCache(assetID uint32, from time.Time, to time.Time) (data []datamodel.CountEntry, cacheHit bool)

GetRawCountsFromCache gets raw counts from cache

func GetRawShiftsFromCache

func GetRawShiftsFromCache(assetID uint32, from time.Time, to time.Time, configuration datamodel.CustomerConfiguration) (data []datamodel.ShiftEntry, cacheHit bool)

GetRawShiftsFromCache gets raw shifts from cache

func GetStatesRawFromCache

func GetStatesRawFromCache(assetID uint32, from time.Time, to time.Time, configuration datamodel.CustomerConfiguration) (data []datamodel.StateEntry, cacheHit bool)

GetStatesRawFromCache gets raw states from cache

func GetTiered

func GetTiered(key string) (cached bool, value interface{})

GetTiered Attempts to get key from memory cache, if fails it falls back to redis

func GetUniqueProductIDFromCache

func GetUniqueProductIDFromCache(aid string, DBassetID uint32) (uid uint32, cacheHit bool)

GetUniqueProductIDFromCache gets uniqueProduct from cache

func InitCache

func InitCache(redisURI string, redisURI2 string, redisURI3 string, redisPassword string, redisDB int, dryRun string)

InitCache initializes a redis cache

func InitMemcache

func InitMemcache()

func IsInSliceFloat64

func IsInSliceFloat64(slice []float64, val float64) bool

IsInSliceFloat64 takes a slice and looks for an element in it. If found it will return it's key, otherwise it will return -1 and a bool of false.

func IsInSliceInt32

func IsInSliceInt32(slice []int32, val int32) bool

IsInSliceInt32 takes a slice and looks for an element in it. If found it will return it's key, otherwise it will return -1 and a bool of false.

func IsKafkaTopicValid

func IsKafkaTopicValid(topic string) bool

func IsRedisAvailable

func IsRedisAvailable() bool

func IsValidStruct

func IsValidStruct(testStruct interface{}, allowedNilFields []string) (success bool)

func Load

func Load(path string, v interface{}) error

Load loads the file at path into v. Use os.IsNotExist() to see if the returned error is due to the file being missing.

func LogObject

func LogObject(functionName string, objectName string, now time.Time, v interface{})

LogObject is used to create testfiles for golden testing

func SanitizeByteArray

func SanitizeByteArray(unsafebytearray []byte) (safestring string)

SanitizeByteArray formats the byte array and passes it through SanitizeString

func SanitizeString

func SanitizeString(unsafestring string) (safestring string)

SanitizeString removes any rune that is not graphic and printable.

func SanitizeStringArray

func SanitizeStringArray(unsafestringarray []string) (safestrings []string)

func Save

func Save(path string, v interface{}) error

Save saves a representation of v to the file at path.

func SaveIoddFile

func SaveIoddFile(vendorId int64, deviceId int, relativeDirectoryPath string) (err error)

func SetMemcached

func SetMemcached(key string, value interface{})

func SetMemcachedLong

func SetMemcachedLong(key string, value interface{}, d time.Duration)

func SetTiered

func SetTiered(key string, value interface{}, redisExpiration time.Duration)

SetTiered sets memcache and redis with expiration

func SetTieredLongTerm

func SetTieredLongTerm(key string, value interface{})

SetTieredLongTerm is an helper, that calls SetTiered with default redis expiration

func SetTieredShortTerm

func SetTieredShortTerm(key string, value interface{})

SetTieredShortTerm is an helper, that calls SetTiered with default memory expiration

func SleepBackedOff

func SleepBackedOff(retries int64, slotTime time.Duration, maximum time.Duration)

func StoreAssetIDToCache

func StoreAssetIDToCache(customerID string, location string, assetID string, DBassetID uint32)

StoreAssetIDToCache stores asset id to cache

func StoreAverageStateTimeToCache

func StoreAverageStateTimeToCache(key string, data []interface{})

StoreAverageStateTimeToCache stores average state time to cache

func StoreCalculatateLowSpeedStatesToCache

func StoreCalculatateLowSpeedStatesToCache(from time.Time, to time.Time, assetID uint32, processedStateArray []datamodel.StateEntry)

StoreCalculatateLowSpeedStatesToCache stores low speed states to cache

func StoreCustomerConfigurationToCache

func StoreCustomerConfigurationToCache(customerID string, data datamodel.CustomerConfiguration)

StoreCustomerConfigurationToCache stores customer configuration to cache

func StoreDistinctProcessValuesToCache

func StoreDistinctProcessValuesToCache(customerID string, location string, assetID string, data []string)

StoreDistinctProcessValuesToCache stores distinct process values to cache

func StoreProcessStatesToCache

func StoreProcessStatesToCache(key string, processedStateArray []datamodel.StateEntry)

StoreProcessStatesToCache stores process states to the cache

func StoreProductIDToCache

func StoreProductIDToCache(productName int32, DBassetID uint32, DBProductId uint32)

StoreUniqueProductIDToCache stores uniqueProductID to cache

func StoreRawCountsToCache

func StoreRawCountsToCache(assetID uint32, from time.Time, to time.Time, data []datamodel.CountEntry)

StoreRawCountsToCache stores raw counts to cache

func StoreRawShiftsToCache

func StoreRawShiftsToCache(assetID uint32, from time.Time, to time.Time, configuration datamodel.CustomerConfiguration, data []datamodel.ShiftEntry)

StoreRawShiftsToCache stores raw shifts to cache

func StoreRawStatesToCache

func StoreRawStatesToCache(assetID uint32, from time.Time, to time.Time, configuration datamodel.CustomerConfiguration, data []datamodel.StateEntry)

StoreRawStatesToCache stores raw states to cache

func StoreUniqueProductIDToCache

func StoreUniqueProductIDToCache(aid string, DBassetID uint32, uid uint32)

StoreUniqueProductIDToCache stores uniqueProductID to cache

func Uint128ToBytes

func Uint128ToBytes(a xxh3.Uint128) (b []byte)

Uint128ToBytes converts a uint128 to a byte array

func UniqueInt

func UniqueInt(input []int) []int

UniqueInt returns a unique subset of the int slice provided.

Types

type Content

type Content struct {
	HasMoreVersions    bool   `json:"hasMoreVersions"`
	DeviceID           int64  `json:"deviceId"`
	IoLinkRev          string `json:"ioLinkRev"`
	VersionString      string `json:"versionString"`
	IoddID             int64  `json:"ioddId"`
	ProductID          string `json:"productId"`
	ProductVariantID   int64  `json:"productVariantId"`
	ProductName        string `json:"productName"`
	VendorName         string `json:"vendorName"`
	UploadDate         int64  `json:"uploadDate"`
	VendorID           int64  `json:"vendorId"`
	IoddStatus         string `json:"ioddStatus"`
	IndicationOfSource string `json:"indicationOfSource"`
}

type IoDDFile

type IoDDFile struct {
	Name    string
	File    []byte
	Context Content
}

IoDDFile is a helper structure with the name, file and additional context of the iodd file

func GetIoddFile

func GetIoddFile(vendorId int64, deviceId int) (files []IoDDFile, err error)

GetIoddFile downloads a ioddfiles from ioddfinder and returns a list of valid files for the request (This can be multiple, if the vendor has multiple languages or versions published)

type Ioddfinder

type Ioddfinder struct {
	Content          []Content     `json:"content"`
	Number           int64         `json:"number"`
	Size             int64         `json:"size"`
	NumberOfElements int64         `json:"numberOfElements"`
	Sort             []interface{} `json:"sort"`
	First            bool          `json:"first"`
	Last             bool          `json:"last"`
	TotalPages       int64         `json:"totalPages"`
	TotalElements    int64         `json:"totalElements"`
}

func UnmarshalIoddfinder

func UnmarshalIoddfinder(data []byte) (Ioddfinder, error)

func (*Ioddfinder) Marshal

func (r *Ioddfinder) Marshal() ([]byte, error)

type TopicInformation

type TopicInformation struct {
	AssetId            string
	Location           string
	CustomerId         string
	Topic              string
	ExtendedTopics     []string
	TransmitterId      *string
	MacAddressOfCamera *string
}

func GetTopicInformationCached

func GetTopicInformationCached(topic string) *TopicInformation

GetTopicInformationCached returns the topic information for the given topic. The topic information is cached in an LRU cache, resulting in up to 10x performance improvement.

type Xy

type Xy struct {
	X []float64
	Y []float64
}

func (Xy) Len

func (d Xy) Len() int

func (Xy) XY

func (d Xy) XY(i int) (x, y float64)

Jump to

Keyboard shortcuts

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