session

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionActive        = errors.New("session already active on the connector")
	ErrInvalidTagId         = errors.New("tag ID invalid")
	ErrInvalidTransactionId = errors.New("transaction id invalid")
)

Functions

This section is empty.

Types

type Session

type Session struct {
	IsActive      bool
	TransactionId string
	TagId         string
	Started       string
	Consumption   []types.MeterValue
}

func NewEmptySession

func NewEmptySession() *Session

func (*Session) AddSampledValue

func (session *Session) AddSampledValue(samples []types.SampledValue)

AddSampledValue Add all the samples taken to the Session.

func (*Session) CalculateAvgPower

func (session *Session) CalculateAvgPower() float64

CalculateAvgPower calculate the average power for a session based on sampled values

func (*Session) CalculateEnergyConsumption

func (session *Session) CalculateEnergyConsumption() float64

CalculateEnergyConsumption calculate the total energy consumption for a session that was active only with energy measurments

func (*Session) CalculateEnergyConsumptionWithAvgPower

func (session *Session) CalculateEnergyConsumptionWithAvgPower() float64

CalculateEnergyConsumptionWithAvgPower calculate the total energy consumption for a session that was active, if it had any measurements

func (*Session) EndSession

func (session *Session) EndSession()

EndSession End the Session if one is active. Reset the attributes, except the measurands.

func (*Session) StartSession

func (session *Session) StartSession(transactionId string, tagId string) error

StartSession Starts the Session, storing the transactionId and tagId of the user. Checks if transaction and tagId are valid strings.

type SessionInterface

type SessionInterface interface {
	StartSession(transactionId string, tagId string) error
	EndSession()
	AddSampledValue(samples []types.SampledValue)
	CalculateAvgPower() float64
	CalculateEnergyConsumptionWithAvgPower() float64
	CalculateEnergyConsumption() float64
}

Jump to

Keyboard shortcuts

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