From 6707dabdf177a158b9f4cf9a6cd06a81e0031d24 Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Sat, 22 Jun 2019 14:38:58 +0200 Subject: [PATCH] feat(cmd/temperature/compress): new subcommand to compress logfiles --- cmd/temperature/compression.go | 35 +++++++++++++++++++ cmd/temperature/convert.go | 3 -- .../test/json/faultyTemperatures_01.json | 16 ++++----- .../test/json/faultyTemperatures_02.json | 16 ++++----- .../test/json/faultyTemperatures_03.json | 16 ++++----- .../test/json/faultyTemperatures_04.json | 15 ++++---- .../test/json/faultyTemperatures_05.json | 16 ++++----- .../test/json/validTemperatures_01.json | 30 ++++++++-------- .../test/json/validTemperatures_02.json | 30 ++++++++-------- 9 files changed, 105 insertions(+), 72 deletions(-) create mode 100644 cmd/temperature/compression.go diff --git a/cmd/temperature/compression.go b/cmd/temperature/compression.go new file mode 100644 index 0000000..a82afcb --- /dev/null +++ b/cmd/temperature/compression.go @@ -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) +} diff --git a/cmd/temperature/convert.go b/cmd/temperature/convert.go index 2d40226..91c2eac 100644 --- a/cmd/temperature/convert.go +++ b/cmd/temperature/convert.go @@ -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", diff --git a/pkg/logfile/test/json/faultyTemperatures_01.json b/pkg/logfile/test/json/faultyTemperatures_01.json index ef13701..b238aa8 100644 --- a/pkg/logfile/test/json/faultyTemperatures_01.json +++ b/pkg/logfile/test/json/faultyTemperatures_01.json @@ -1,11 +1,11 @@ [ { - "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", - "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" + "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", + "temperature_value": "24.562", + "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+02:00", + "update_date": "2019-10-01T00:00:00+02:00" } -] \ No newline at end of file +] diff --git a/pkg/logfile/test/json/faultyTemperatures_02.json b/pkg/logfile/test/json/faultyTemperatures_02.json index 2733e49..05c8336 100644 --- a/pkg/logfile/test/json/faultyTemperatures_02.json +++ b/pkg/logfile/test/json/faultyTemperatures_02.json @@ -1,11 +1,11 @@ [ { - "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", - "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" + "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", + "temperature_value": "24.562", + "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+02:00", + "update_date": "2019-05-01T00:00:00+02:00" } -] \ No newline at end of file +] diff --git a/pkg/logfile/test/json/faultyTemperatures_03.json b/pkg/logfile/test/json/faultyTemperatures_03.json index 5417ad4..0fa6e01 100644 --- a/pkg/logfile/test/json/faultyTemperatures_03.json +++ b/pkg/logfile/test/json/faultyTemperatures_03.json @@ -1,11 +1,11 @@ [ { - "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", - "sensor_id": "", - "creation_date": "2019-05-01T00:00:00.000000000+02:00", - "update_date": "2019-10-01T00:00:00.000000000+02:00" + "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", + "temperature_value": "24.562", + "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+02:00", + "update_date": "2019-10-01T00:00:00+02:00" } -] \ No newline at end of file +] diff --git a/pkg/logfile/test/json/faultyTemperatures_04.json b/pkg/logfile/test/json/faultyTemperatures_04.json index c80fd1f..87d28a0 100644 --- a/pkg/logfile/test/json/faultyTemperatures_04.json +++ b/pkg/logfile/test/json/faultyTemperatures_04.json @@ -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", - "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" + "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", + "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+02:00", + "update_date": "2019-10-01T00:00:00+02:00" } -] \ No newline at end of file +] diff --git a/pkg/logfile/test/json/faultyTemperatures_05.json b/pkg/logfile/test/json/faultyTemperatures_05.json index 0443a79..eae9d02 100644 --- a/pkg/logfile/test/json/faultyTemperatures_05.json +++ b/pkg/logfile/test/json/faultyTemperatures_05.json @@ -1,11 +1,11 @@ [ { - "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", - "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" + "temperature_id": "", + "temperature_value": "24.562", + "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+02:00", + "update_date": "2019-10-01T00:00:00+02:00" } -] \ No newline at end of file +] diff --git a/pkg/logfile/test/json/validTemperatures_01.json b/pkg/logfile/test/json/validTemperatures_01.json index 4e51362..633715e 100644 --- a/pkg/logfile/test/json/validTemperatures_01.json +++ b/pkg/logfile/test/json/validTemperatures_01.json @@ -1,20 +1,20 @@ [ { - "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", - "temperature_value": "24.562", - "temperature_from_date": "2019-06-14T21:15:28.504051541+02:00", - "temperature_till_date": "2019-06-14T21:18:07.384104493+02:00", - "sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e", - "creation_date": "2019-06-14T21:18:07.465885864+02:00", - "update_date": "2019-06-14T21:18:07.46587076+02:00" + "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", + "temperature_value": "24.562", + "temperature_from_date": "2019-06-14T21:15:28.504051541+02:00", + "temperature_till_date": "2019-06-14T21:18:07.384104493+02:00", + "sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e", + "creation_date": "2019-06-14T21:18:07.465885864+02:00", + "update_date": "2019-06-14T21:18:07.46587076+02:00" }, { - "temperature_id": "5f119ba3-bcea-4c3b-aabb-0406ea70f7e1", - "temperature_value": "24.375", - "temperature_from_date": "2019-06-14T21:15:28.583856443+02:00", - "temperature_till_date": "2019-06-14T21:18:07.463893776+02:00", - "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", - "creation_date": "2019-06-14T21:18:07.465885864+02:00", - "update_date": "2019-06-14T21:18:07.46587701+02:00" + "temperature_id": "5f119ba3-bcea-4c3b-aabb-0406ea70f7e1", + "temperature_value": "24.375", + "temperature_from_date": "2019-06-14T21:15:28.583856443+02:00", + "temperature_till_date": "2019-06-14T21:18:07.463893776+02:00", + "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", + "creation_date": "2019-06-14T21:18:07.465885864+02:00", + "update_date": "2019-06-14T21:18:07.46587701+02:00" } - ] \ No newline at end of file +] diff --git a/pkg/logfile/test/json/validTemperatures_02.json b/pkg/logfile/test/json/validTemperatures_02.json index 24ad945..8014710 100644 --- a/pkg/logfile/test/json/validTemperatures_02.json +++ b/pkg/logfile/test/json/validTemperatures_02.json @@ -1,20 +1,20 @@ [ { - "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", - "temperature_value": "24.562", - "temperature_from_date": "2019-06-14T21:15:28.504051541+02:00", - "temperature_till_date": "2019-06-14T21:18:07.384104493+02:00", - "sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e", - "creation_date": "2019-06-14T21:18:07.465885864+02:00", - "update_date": "2019-06-14T21:18:07.46587076+02:00" + "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", + "temperature_value": "24.562", + "temperature_from_date": "2019-06-14T21:15:28.504051541+02:00", + "temperature_till_date": "2019-06-14T21:18:07.384104493+02:00", + "sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e", + "creation_date": "2019-06-14T21:18:07.465885864+02:00", + "update_date": "2019-06-14T21:18:07.46587076+02:00" }, { - "temperature_id": "5f119ba3-bcea-4c3b-aabb-0406ea70f7e1", - "temperature_value": "24.375", - "temperature_from_date": "2019-06-14T21:15:28.583856443+02:00", - "temperature_till_date": "2019-06-14T21:15:28.583856443+02:00", - "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", - "creation_date": "2019-06-14T21:18:07.465885864+02:00", - "update_date": null + "temperature_id": "5f119ba3-bcea-4c3b-aabb-0406ea70f7e1", + "temperature_value": "24.375", + "temperature_from_date": "2019-06-14T21:15:28.583856443+02:00", + "temperature_till_date": "2019-06-14T21:15:28.583856443+02:00", + "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", + "creation_date": "2019-06-14T21:18:07.465885864+02:00", + "update_date": null } -] \ No newline at end of file +]