diff --git a/charts/wchart/data_series_set_simple_set.go b/charts/wchart/data_series_set_simple_set.go index 0bb2197..fb30d06 100644 --- a/charts/wchart/data_series_set_simple_set.go +++ b/charts/wchart/data_series_set_simple_set.go @@ -30,7 +30,7 @@ func DSSToChart(data statictimeseries.DataSeriesSet, opts ChartOptions) chart.Ch } times := timeutil.TimeSeriesSlice( timeutil.Month, - statictimeseries.DataSeriesItemTimes(&series)) + series.ItemTimes()) ts.XValues = times yvalues := []float64{} for _, t := range times { diff --git a/data/statictimeseries/data_series.go b/data/statictimeseries/data_series.go index 1d89b33..2a27e39 100644 --- a/data/statictimeseries/data_series.go +++ b/data/statictimeseries/data_series.go @@ -211,7 +211,7 @@ func (ds *DataSeries) DeleteByTime(dt time.Time) { delete(ds.ItemMap, dt.Format(time.RFC3339)) } -func (ds *DataSeries) ToMonth() DataSeries { +func (ds *DataSeries) ToMonth(inflate bool) DataSeries { newDataSeries := DataSeries{ SeriesName: ds.SeriesName, ItemMap: map[string]DataItem{}, @@ -225,16 +225,29 @@ func (ds *DataSeries) ToMonth() DataSeries { Value: item.Value, ValueFloat: item.ValueFloat}) } + if inflate { + timeSeries := timeutil.TimeSeriesSlice( + timeutil.Month, + newDataSeries.ItemTimes()) + for _, dt := range timeSeries { + newDataSeries.AddItem(DataItem{ + SeriesName: newDataSeries.SeriesName, + Time: dt, + IsFloat: newDataSeries.IsFloat, + Value: 0, + ValueFloat: 0.0}) + } + } return newDataSeries } -func (ds *DataSeries) ToMonthCumulative(timesInput ...time.Time) (DataSeries, error) { +func (ds *DataSeries) ToMonthCumulative(inflate bool, timesInput ...time.Time) (DataSeries, error) { newDataSeries := DataSeries{ SeriesName: ds.SeriesName, ItemMap: map[string]DataItem{}, IsFloat: ds.IsFloat, Interval: timeutil.Month} - dsMonth := ds.ToMonth() + dsMonth := ds.ToMonth(inflate) var min time.Time var max time.Time var err error @@ -335,9 +348,9 @@ func (ds *DataSeries) WriteXLSX(filename, sheetname, col1, col2 string) error { Rows: rows}) } -func AggregateSeries(s1 DataSeries) DataSeries { +func AggregateSeries(series DataSeries) DataSeries { aggregate := NewDataSeries() - sortedItems := s1.ItemsSorted() + sortedItems := series.ItemsSorted() sum := int64(0) for _, atomicItem := range sortedItems { aggregateItem := DataItem{ @@ -351,11 +364,11 @@ func AggregateSeries(s1 DataSeries) DataSeries { return aggregate } -func DataSeriesTimeSeries(series *DataSeries, interval timeutil.Interval) []time.Time { - return timeutil.TimeSeriesSlice(interval, DataSeriesItemTimes(series)) +func (series *DataSeries) TimeSeries(interval timeutil.Interval) []time.Time { + return timeutil.TimeSeriesSlice(interval, series.ItemTimes()) } -func DataSeriesItemTimes(series *DataSeries) []time.Time { +func (series *DataSeries) ItemTimes() []time.Time { times := []time.Time{} for _, item := range series.ItemMap { times = append(times, item.Time) @@ -363,12 +376,14 @@ func DataSeriesItemTimes(series *DataSeries) []time.Time { return times } +/* func DataSeriesMinMaxTimes(series *DataSeries) (time.Time, time.Time) { return timeutil.SliceMinMax(DataSeriesItemTimes(series)) } +*/ func (series *DataSeries) MinMaxTimes() (time.Time, time.Time) { - return DataSeriesMinMaxTimes(series) + return timeutil.SliceMinMax(series.ItemTimes()) } func (ds *DataSeries) Stats() point.PointSet { diff --git a/data/statictimeseries/data_series_set_mod.go b/data/statictimeseries/data_series_set_mod.go index 4756362..41f3793 100644 --- a/data/statictimeseries/data_series_set_mod.go +++ b/data/statictimeseries/data_series_set_mod.go @@ -6,7 +6,7 @@ import ( "github.com/grokify/simplego/time/timeutil" ) -func (set *DataSeriesSet) ToMonth() DataSeriesSet { +func (set *DataSeriesSet) ToMonth(inflate bool) DataSeriesSet { newDss := DataSeriesSet{ Name: set.Name, Series: map[string]DataSeries{}, @@ -14,13 +14,13 @@ func (set *DataSeriesSet) ToMonth() DataSeriesSet { Interval: timeutil.Month, Order: set.Order} for name, ds := range set.Series { - newDss.Series[name] = ds.ToMonth() + newDss.Series[name] = ds.ToMonth(inflate) } newDss.Times = newDss.GetTimeSlice(true) return newDss } -func (set *DataSeriesSet) ToMonthCumulative(popLast bool) (DataSeriesSet, error) { +func (set *DataSeriesSet) ToMonthCumulative(popLast, inflate bool) (DataSeriesSet, error) { newDss := DataSeriesSet{ Name: set.Name, Series: map[string]DataSeries{}, @@ -28,7 +28,7 @@ func (set *DataSeriesSet) ToMonthCumulative(popLast bool) (DataSeriesSet, error) Interval: timeutil.Month, Order: set.Order} for name, ds := range set.Series { - newDs, err := ds.ToMonthCumulative(newDss.Times...) + newDs, err := ds.ToMonthCumulative(inflate, newDss.Times...) if err != nil { return newDss, err }