feat(cmd/temperature/compress): new subcommand to compress logfiles

This commit is contained in:
Markus Pesch 2019-06-22 14:38:58 +02:00
parent bbcccd7479
commit 6707dabdf1
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
9 changed files with 105 additions and 72 deletions

View File

@ -0,0 +1,35 @@
package temperature
import (
"log"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/spf13/cobra"
)
var compressTemperatureCmd = &cobra.Command{
Use: "compress",
Short: "Compress temperature logfiles",
Args: cobra.ExactArgs(1),
Example: `flucky temperature compress /var/log/flucky/temperature.json
flucky temperature compress /var/log/flucky/temperature.xml`,
Run: func(cmd *cobra.Command, args []string) {
temperatureLogfile := logfile.New(args[0])
temperatures, err := temperatureLogfile.ReadTemperatures()
if err != nil {
log.Fatalln(err)
}
temperatures = logfile.CompressTemperature(temperatures)
err = temperatureLogfile.WriteTemperatures(temperatures)
if err != nil {
log.Fatalln(err)
}
},
}
func init() {
temperatureCmd.AddCommand(compressTemperatureCmd)
}

View File

@ -7,9 +7,6 @@ import (
"github.com/spf13/cobra"
)
var logfileInput string
var logfileOutput string
var convertTemperatureCmd = &cobra.Command{
Use: "convert",
Short: "Convert temperature logfiles into other markup language",

View File

@ -2,10 +2,10 @@
{
"temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957",
"temperature_value": "24.562",
"temperature_from_date": "2019-10-01T00:00:00.000000000+02:00",
"temperature_till_date": "2019-05-01T00:00:00.000000000+02:00",
"temperature_from_date": "2019-10-01T00:00:00+02:00",
"temperature_till_date": "2019-05-01T00:00:00+02:00",
"sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e",
"creation_date": "2019-05-01T00:00:00.000000000+02:00",
"update_date": "2019-10-01T00:00:00.000000000+02:00"
"creation_date": "2019-05-01T00:00:00+02:00",
"update_date": "2019-10-01T00:00:00+02:00"
}
]

View File

@ -2,10 +2,10 @@
{
"temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957",
"temperature_value": "24.562",
"temperature_from_date": "2019-05-01T00:00:00.000000000+02:00",
"temperature_till_date": "2019-10-01T00:00:00.000000000+02:00",
"temperature_from_date": "2019-05-01T00:00:00+02:00",
"temperature_till_date": "2019-10-01T00:00:00+02:00",
"sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e",
"creation_date": "2019-10-01T00:00:00.000000000+02:00",
"update_date": "2019-05-01T00:00:00.000000000+02:00"
"creation_date": "2019-10-01T00:00:00+02:00",
"update_date": "2019-05-01T00:00:00+02:00"
}
]

View File

@ -2,10 +2,10 @@
{
"temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957",
"temperature_value": "24.562",
"temperature_from_date": "2019-05-01T00:00:00.000000000+02:00",
"temperature_till_date": "2019-10-01T00:00:00.000000000+02:00",
"temperature_from_date": "2019-05-01T00:00:00+02:00",
"temperature_till_date": "2019-10-01T00:00:00+02:00",
"sensor_id": "",
"creation_date": "2019-05-01T00:00:00.000000000+02:00",
"update_date": "2019-10-01T00:00:00.000000000+02:00"
"creation_date": "2019-05-01T00:00:00+02:00",
"update_date": "2019-10-01T00:00:00+02:00"
}
]

View File

@ -1,10 +1,11 @@
[
{
"temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957",
"temperature_from_date": "2019-05-01T00:00:00.000000000+02:00",
"temperature_till_date": "2019-10-01T00:00:00.000000000+02:00",
"temperature_value": "0",
"temperature_from_date": "2019-05-01T00:00:00+02:00",
"temperature_till_date": "2019-10-01T00:00:00+02:00",
"sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e",
"creation_date": "2019-05-01T00:00:00.000000000+02:00",
"update_date": "2019-10-01T00:00:00.000000000+02:00"
"creation_date": "2019-05-01T00:00:00+02:00",
"update_date": "2019-10-01T00:00:00+02:00"
}
]

View File

@ -2,10 +2,10 @@
{
"temperature_id": "",
"temperature_value": "24.562",
"temperature_from_date": "2019-05-01T00:00:00.000000000+02:00",
"temperature_till_date": "2019-10-01T00:00:00.000000000+02:00",
"temperature_from_date": "2019-05-01T00:00:00+02:00",
"temperature_till_date": "2019-10-01T00:00:00+02:00",
"sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e",
"creation_date": "2019-05-01T00:00:00.000000000+02:00",
"update_date": "2019-10-01T00:00:00.000000000+02:00"
"creation_date": "2019-05-01T00:00:00+02:00",
"update_date": "2019-10-01T00:00:00+02:00"
}
]