fix(cli/db): remove obsolete db subcommand
This commit is contained in:
@ -7,24 +7,17 @@ import (
|
||||
"github.com/go-flucky/flucky/pkg/types"
|
||||
)
|
||||
|
||||
// var validUUID = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")
|
||||
|
||||
// Append adds an array of several measured values to a logfile
|
||||
func Append(logfile Logfile, measuredValues []*types.MeasuredValue) error {
|
||||
|
||||
allMeasuredValues, err := logfile.Read()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allMeasuredValues = append(allMeasuredValues, measuredValues...)
|
||||
|
||||
err = logfile.Write(allMeasuredValues)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -32,9 +25,7 @@ func Append(logfile Logfile, measuredValues []*types.MeasuredValue) error {
|
||||
// file extension of the logfile is taken into account to format the logfile
|
||||
// into the correct format.
|
||||
func New(logfile string) Logfile {
|
||||
|
||||
ext := filepath.Ext(logfile)
|
||||
|
||||
switch ext {
|
||||
case ".csv":
|
||||
return &csvLogfile{
|
||||
@ -53,7 +44,6 @@ func New(logfile string) Logfile {
|
||||
logfile: logfile,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func writeCreationDate(measuredValues []*types.MeasuredValue) error {
|
||||
|
@ -31,6 +31,13 @@ func Compression(measuredValues []*types.MeasuredValue) []*types.MeasuredValue {
|
||||
now := format.FormatedTime()
|
||||
|
||||
for _, measuredValue := range measuredValues {
|
||||
|
||||
// If the sensor id does not exist in the map, a new map is initialized,
|
||||
// which can assume measured value types as the key. Behind this key there
|
||||
// is a pointer which refers to a measured value in the memory. This new map
|
||||
// is added to the map "lastMeasuredValuesBySensors" under the sensor ID.
|
||||
// This makes it possible to store one measured value per measured value
|
||||
// type per sensor.
|
||||
if _, ok := lastMeasuredValuesBySensors[measuredValue.SensorID]; !ok {
|
||||
lastMeasuredValuesBySensors[measuredValue.SensorID] = make(map[types.MeasuredValueType]*types.MeasuredValue, 0)
|
||||
}
|
||||
@ -93,21 +100,27 @@ func Round(measuredValues []*types.MeasuredValue, round float64) {
|
||||
}
|
||||
}
|
||||
|
||||
// Write measured values to the given storage endpoint url. The scheme must be
|
||||
// matched to a provider, if the scheme is not implemented, the function
|
||||
// returns an error
|
||||
// Write measured values to the given storage endpoint url. If the storage
|
||||
// provider defined to a file, the data will be overwritten. If a database
|
||||
// provider is used, the data is simply added without deleting the existing
|
||||
// data. The scheme must be matched to a storage provider, if the scheme is not
|
||||
// implemented, the function returns an error
|
||||
func Write(ctx context.Context, measuredValues []*types.MeasuredValue, storageEndpoint *url.URL) error {
|
||||
switch storageEndpoint.Scheme {
|
||||
case "file":
|
||||
measuredValueLogfile := logfile.New(storageEndpoint.Path)
|
||||
return measuredValueLogfile.Write(measuredValues)
|
||||
storedMeasuredValues, err := measuredValueLogfile.Read()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
storedMeasuredValues = append(storedMeasuredValues, measuredValues...)
|
||||
return measuredValueLogfile.Write(storedMeasuredValues)
|
||||
case "postgres":
|
||||
database, err := db.New(storageEndpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer database.Close()
|
||||
|
||||
if err := database.InsertMeasuredValues(ctx, measuredValues); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user