func (r *OldSerieRule) End() {
	var keys []string
	for k := range r.series {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	count := 0
	for _, key := range keys {
		maxTs := r.series[key]
		if maxTs <= r.unixNano {
			r.formater.format(r.out, key, maxTs)
			count++
		}
	}
	r.logger.Printf("Detected %d/%d series as old", count, len(keys))
}
End implements Rule interface
package rules
import (
	"encoding/json"
	"fmt"
	"io"
	"log"
	"os"
	"sort"
	"strings"
	"time"
	"github.com/Abc-Arbitrage/infix/logging"
	"github.com/Abc-Arbitrage/infix/storage"
	"github.com/influxdata/influxdb/tsdb/engine/tsm1"
)
type formater interface {
	format(iow io.Writer, serie string, timestamp int64) error
}
type textFormater struct {
	withTimestamp   bool
	timestampLayout string
}
func formatTimestamp(unixNano int64, layout string) string {
	if layout == "" {
		return fmt.Sprint(unixNano)
	}
	ts := time.Unix(0, unixNano)
	if strings.EqualFold(layout, "RFC3339") {
		return ts.Format(time.RFC3339)
	}
	return ts.Format(layout)
}
func (f *textFormater) format(iow io.Writer, serie string, timestamp int64) error {
	if f.withTimestamp {
		fmt.Fprintf(iow, "%s: %s\n", serie, formatTimestamp(timestamp, f.timestampLayout))
	} else {
		fmt.Fprintf(iow, "%s\n", serie)
	}
	return nil
}
type jsonFormater struct {
	withTimestamp   bool
	timestampLayout string
}
func (f *jsonFormater) format(iow io.Writer, serie string, timestamp int64) error {
	type jsonLine struct {
		serie     string
		timestamp int64
	}
	type jsonLineSerieOnly struct {
		serie string
	}
	data := map[string]interface{}{
		"Serie": serie,
	}
	if f.withTimestamp {
		data["Timestamp"] = formatTimestamp(timestamp, f.timestampLayout)
	}
	return f.formatLine(iow, data)
}
func (f *jsonFormater) formatLine(iow io.Writer, data map[string]interface{}) error {
	b, err := json.Marshal(data)
	if err != nil {
		return err
	}
	fmt.Fprintln(iow, string(b))
	return nil
}
type OldSerieRule struct {
	unixNano int64
	out      io.Writer
	byField bool
	series   map[string]int64
	formater formater
	logger *log.Logger
}
type OldSerieRuleConfig struct {
	Time            string
	ByField         bool
	Out             string
	Format          string
	Timestamp       bool
	TimestampLayout string
}
func newFormater(format string, withTimestamp bool, timestampLayout string) (formater, error) {
	switch format {
	case "text":
		return &textFormater{withTimestamp: withTimestamp, timestampLayout: timestampLayout}, nil
	case "json":
		return &jsonFormater{withTimestamp: withTimestamp, timestampLayout: timestampLayout}, nil
	default:
		return nil, fmt.Errorf("Unknown format %s", format)
	}
}
func NewOldSerieRule(t time.Time, byField bool, out io.Writer, format string) (*OldSerieRule, error) {
	formater, err := newFormater(format, false, "")
	if err != nil {
		return nil, err
	}
	return newOldSerieRule(t, byField, out, formater), nil
}
func newOldSerieRule(t time.Time, byField bool, out io.Writer, formater formater) *OldSerieRule {
	return &OldSerieRule{
		unixNano: t.UnixNano() / int64(time.Nanosecond),
		byField:  byField,
		out:      out,
		series:   make(map[string]int64),
		formater: formater,
		logger:   logging.GetLogger("OldSerieRule"),
	}
}
func (r *OldSerieRule) CheckMode(check bool) {
}
func (r *OldSerieRule) Flags() int {
	return TSMReadOnly
}
func (r *OldSerieRule) WithLogger(logger *log.Logger) {
}
func (r *OldSerieRule) FilterKey(key []byte) bool {
	return false
}
func (r *OldSerieRule) Start() {
}