func NewAvgProcessorState() AvgCompState {
	return AvgCompState{
		Sums:   make(map[dagger.Timestamp]float64),
		Counts: make(map[dagger.Timestamp]int),
	}
}
NewAvgProcessorState initializes state struct
package main
import (
	"encoding/json"
	"fmt"
	"os"
	"os/signal"
	"strconv"
	log "github.com/Sirupsen/logrus"
	"github.com/nsaje/dagger/computations"
	"github.com/nsaje/dagger/dagger"
	"github.com/twinj/uuid"
)
type AvgProcessor struct {
	state AvgCompState
}
type AvgCompState struct {
	Sums   map[dagger.Timestamp]float64
	Counts map[dagger.Timestamp]int
}
type AvgCompStateJSON struct {
	Buckets []dagger.Timestamp
	Sums    []float64
	Counts  []int
}
func (c *AvgProcessor) GetState() ([]byte, error) {
	stateJSON := NewAvgProcessorStateJSON()
	for bucket := range c.state.Sums {
		stateJSON.Buckets = append(stateJSON.Buckets, bucket)
		stateJSON.Sums = append(stateJSON.Sums, c.state.Sums[bucket])
		stateJSON.Counts = append(stateJSON.Counts, c.state.Counts[bucket])
	}
	log.Println("returning stateJSON:", stateJSON)
	return json.Marshal(stateJSON)
}
func (c *AvgProcessor) SetState(state []byte) error {
	newState := NewAvgProcessorState()
	newStateJSON := NewAvgProcessorStateJSON()
	err := json.Unmarshal(state, &newStateJSON)
	if err != nil {
		return fmt.Errorf("Error setting plugin state: %s", err)
	}
	for i, bucket := range newStateJSON.Buckets {
		newState.Sums[bucket] = newStateJSON.Sums[i]
		newState.Counts[bucket] = newStateJSON.Counts[i]
	}
	c.state = newState
	log.Println("[avg] new state:", c.state)
	return nil
}
func (c *AvgProcessor) ProcessBucket(bucket dagger.Timestamp, t *dagger.Record) error {
	log.Println("[avg] processing", t)
	value, _ := strconv.ParseFloat(t.Data.(string), 64)
	c.state.Counts[bucket]++
	c.state.Sums[bucket] += value
	return nil
}
func (c *AvgProcessor) FinalizeBucket(bucket dagger.Timestamp) *dagger.Record {
	log.Println("[avg] finalizing", bucket)
	new := &dagger.Record{
		Data:      c.state.Sums[bucket] / float64(c.state.Counts[bucket]),
		Timestamp: bucket,
		ID:        uuid.NewV4().String(),
	}
	delete(c.state.Sums, bucket)
	delete(c.state.Counts, bucket)
	log.Println("[avg] finalization finished", bucket)
	return new
}