func whisperCreate(path string) ([]*whisper.TimeSeriesPoint, error) { ts := make([]*whisper.TimeSeriesPoint, 30) os.Remove(path) // Don't care if it fails retentions, err := whisper.ParseRetentionDefs("1m:30m") if err != nil { return ts, err } wsp, err := whisper.Create(path, retentions, whisper.Sum, 0.5) if err != nil { return ts, err } defer wsp.Close() rand.Seed(time.Now().Unix()) for i, _ := range ts { dur := fmt.Sprintf("-%dm", 29-i) tdur, _ := time.ParseDuration(dur) point := new(whisper.TimeSeriesPoint) point.Value = float64(rand.Intn(100)) point.Time = int(time.Now().Add(tdur).Unix()) ts[i] = point //log.Printf("WhisperCreate(): point -%dm is %.2f\n", 29-i, point.Value) } wsp.UpdateMany(ts) return ts, nil }
func whisperCreateNulls(path string) ([]*whisper.TimeSeriesPoint, error) { ts := make([]*whisper.TimeSeriesPoint, 30) os.Remove(path) // Don't care if it fails retentions, err := whisper.ParseRetentionDefs("1m:30m") if err != nil { return ts, err } wsp, err := whisper.Create(path, retentions, whisper.Sum, 0.5) if err != nil { return ts, err } defer wsp.Close() for i, _ := range ts { tdur, _ := time.ParseDuration(fmt.Sprintf("-%dm", 29-i)) j := rand.Intn(100) point := new(whisper.TimeSeriesPoint) if j < 65 { point.Value = math.NaN() point.Time = 0 } else { point.Value = float64(j) point.Time = int(time.Now().Add(tdur).Unix()) } ts[i] = point //log.Printf("WhisperNulls(): point -%dm is %.2f\n", 29-i, point.Value) if !math.IsNaN(point.Value) { err = wsp.Update(point.Value, point.Time) if err != nil { return ts, err } } } return ts, nil }