Skip to content

Commit 0587ef7

Browse files
committed
feat: timeseries: add *.WriteJSON()
1 parent 3b7b6bd commit 0587ef7

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

data/timeseries/time_series_export.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package timeseries
22

33
import (
4+
"os"
45
"strconv"
56
"strings"
67
"time"
78

89
"github.com/grokify/gocharts/data/table"
10+
"github.com/grokify/simplego/io/ioutilmore"
911
"github.com/grokify/simplego/time/timeutil"
1012
)
1113

@@ -65,6 +67,12 @@ func (ts *TimeSeries) ToTable(tableName, dateColumnName, countColumnName string,
6567
return tbl
6668
}
6769

70+
// WriteJSON writes the data to a JSON file. To write a minimized JSON
71+
// file use an empty string for `prefix` and `indent`.
72+
func (ts *TimeSeries) WriteJSON(filename string, perm os.FileMode, prefix, indent string) error {
73+
return ioutilmore.WriteFileJSON(filename, ts, perm, prefix, indent)
74+
}
75+
6876
// WriteXLSX writes an XSLX file given a `TimeSeries`
6977
func (ts *TimeSeries) WriteXLSX(filename string, sheetName, dateColumnName, countColumnName string) error {
7078
tbl := ts.ToTable(sheetName, dateColumnName, countColumnName, nil)

data/timeseries/time_series_set_report.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package timeseries
22

33
import (
44
"fmt"
5+
"os"
56
"sort"
67
"strconv"
78
"strings"
89
"time"
910

1011
"github.com/grokify/gocharts/data/table"
12+
"github.com/grokify/simplego/io/ioutilmore"
1113
"github.com/grokify/simplego/time/timeslice"
1214
"github.com/grokify/simplego/time/timeutil"
1315
)
@@ -236,6 +238,13 @@ func (set *TimeSeriesSet) ToTable(opts *TimeSeriesSetTableOpts) (table.Table, er
236238
return tbl, nil
237239
}
238240

241+
// WriteJSON writes the TimeSeriesSet to a JSON file. To write a minimized JSON
242+
// file use an empty string for `prefix` and `indent`.
243+
func (set *TimeSeriesSet) WriteJSON(filename string, perm os.FileMode, prefix, indent string) error {
244+
return ioutilmore.WriteFileJSON(filename, set, perm, prefix, indent)
245+
}
246+
247+
// WriteXLSX writes the TimeSeriesSet as a XLSX spreadsheet file.
239248
func (set *TimeSeriesSet) WriteXLSX(filename string, opts *TimeSeriesSetTableOpts) error {
240249
tbl, err := set.ToTable(opts)
241250
if err != nil {

data/timeseries/time_series_sets.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package timeseries
22

33
import (
4+
"os"
45
"sort"
56

7+
"github.com/grokify/simplego/io/ioutilmore"
68
"github.com/grokify/simplego/time/timeutil"
79
"github.com/grokify/simplego/type/stringsutil"
810
)
@@ -54,3 +56,9 @@ func (sets *TimeSeriesSets) SeriesNames() []string {
5456
}
5557
return stringsutil.SliceCondenseSpace(seriesNames, true, true)
5658
}
59+
60+
// WriteJSON writes the data to a JSON file. To write a minimized JSON
61+
// file use an empty string for `prefix` and `indent`.
62+
func (sets *TimeSeriesSets) WriteJSON(filename string, perm os.FileMode, prefix, indent string) error {
63+
return ioutilmore.WriteFileJSON(filename, sets, perm, prefix, indent)
64+
}

0 commit comments

Comments
 (0)