Esempio n. 1
0
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
}
Esempio n. 2
0
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
}
Esempio n. 3
0
func fetchFromFile(path string) ([]*whisper.TimeSeriesPoint, error) {
	// Init the datastructure we will load values into
	tsp := make([]*whisper.TimeSeriesPoint, 30)
	for i, _ := range tsp {
		point := new(whisper.TimeSeriesPoint)
		point.Value = math.NaN()
		tsp[i] = point
	}

	// Try to open the file
	wsp, err := whisper.Open(path)
	if err != nil {
		return tsp, err
	}
	defer wsp.Close()

	// Parse and fetch data from it
	ts, err := wsp.Fetch(0, int(time.Now().Unix()))
	if err != nil {
		return tsp, err
	}

	return ts.Points(), nil
}