fix(pkg/logfile): description for exported functions

This commit is contained in:
Markus Pesch 2019-06-15 12:12:57 +02:00
parent fbb062d091
commit 314f5a41e5
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982

View File

@ -12,9 +12,6 @@ import (
"github.com/volker-raschek/flucky/pkg/types" "github.com/volker-raschek/flucky/pkg/types"
) )
// Define the entry size for each logfile
var templeratureSplitBy = 10000
// CompressTemperature compresses the temperatures from an array. It is checked // CompressTemperature compresses the temperatures from an array. It is checked
// whether the measured temperature of a value corresponds to that of the // whether the measured temperature of a value corresponds to that of the
// predecessor. If this is the case, the current value is discarded and the // predecessor. If this is the case, the current value is discarded and the
@ -54,6 +51,7 @@ func CompressTemperature(temperatures []*types.Temperature) []*types.Temperature
return compressedTemperatures return compressedTemperatures
} }
// ReadTemperatures from a file and returns an array with temperatures
func ReadTemperatures(temperatureLogfile string) ([]*types.Temperature, error) { func ReadTemperatures(temperatureLogfile string) ([]*types.Temperature, error) {
if _, err := os.Stat(temperatureLogfile); os.IsNotExist(err) { if _, err := os.Stat(temperatureLogfile); os.IsNotExist(err) {
@ -76,6 +74,8 @@ func ReadTemperatures(temperatureLogfile string) ([]*types.Temperature, error) {
return temperatures, nil return temperatures, nil
} }
// ReadTemperaturesCustom from a custom reader and returns an array with
// temperatures
func ReadTemperaturesCustom(r io.Reader) ([]*types.Temperature, error) { func ReadTemperaturesCustom(r io.Reader) ([]*types.Temperature, error) {
temperatures := make([]*types.Temperature, 0) temperatures := make([]*types.Temperature, 0)
@ -89,7 +89,9 @@ func ReadTemperaturesCustom(r io.Reader) ([]*types.Temperature, error) {
return temperatures, nil return temperatures, nil
} }
func SplittTemperatures(temperatures []*types.Temperature) [][]*types.Temperature { // SplittTemperatures into multiple arrays. The Size can be defined by
// temperatureSplitBy parameter.
func SplittTemperatures(temperatures []*types.Temperature, templeratureSplitBy int) [][]*types.Temperature {
splittedTemperatures := make([][]*types.Temperature, 0) splittedTemperatures := make([][]*types.Temperature, 0)
newTemperatures := make([]*types.Temperature, 0) newTemperatures := make([]*types.Temperature, 0)
for _, temperature := range temperatures { for _, temperature := range temperatures {
@ -103,12 +105,15 @@ func SplittTemperatures(temperatures []*types.Temperature) [][]*types.Temperatur
return splittedTemperatures return splittedTemperatures
} }
// SortTemperatures by TemperatureFromDate
func SortTemperatures(temperatures []*types.Temperature) { func SortTemperatures(temperatures []*types.Temperature) {
sort.SliceStable(temperatures, func(i int, j int) bool { sort.SliceStable(temperatures, func(i int, j int) bool {
return temperatures[i].TemperatureFromDate.Before(temperatures[j].TemperatureFromDate) return temperatures[i].TemperatureFromDate.Before(temperatures[j].TemperatureFromDate)
}) })
} }
// WriteTemperatures encode temperatures into json and write it into a file.
// Compression can be enabled over a bolean parameter
func WriteTemperatures(temperatures []*types.Temperature, temperatureLogfile string, compression bool) error { func WriteTemperatures(temperatures []*types.Temperature, temperatureLogfile string, compression bool) error {
allTemperatures := make([]*types.Temperature, 0) allTemperatures := make([]*types.Temperature, 0)
@ -156,6 +161,8 @@ func WriteTemperatures(temperatures []*types.Temperature, temperatureLogfile str
return nil return nil
} }
// WriteTemperaturesCustom encode temperatures into json and write it into
// custom writer. Compression can be enabled over a bolean parameter
func WriteTemperaturesCustom(temperatures []*types.Temperature, w io.Writer, compression bool) error { func WriteTemperaturesCustom(temperatures []*types.Temperature, w io.Writer, compression bool) error {
if compression { if compression {