<commit_before>package common

import (
	"encoding/json"
	"fmt"
	"time"
)

// check interface
var _ Series = (*SeriesMeta)(nil)
var _ Series = (*RawSeries)(nil)
var _ Series = (*IntSeries)(nil)
var _ Series = (*DoubleSeries)(nil)

const (
	_ = iota
	TypeIntSeries
	TypeDoubleSeries
	TypeBoolSeries
	TypeStringSeries
)

type Series interface {
	Hashable
	GetSeriesType() int
	// NOTE: series decoded from JSON has 0 as SeriesID, so the implementation would recalculate the Hash
	GetSeriesID() SeriesID
}

type SeriesMeta struct {
	id         SeriesID
	Name       string            `json:"name"`
	Tags       map[string]string `json:"tags"`
	SeriesType int               `json:"type"`
	Precision  time.Duration     `json:"precision"`
}

type RawSeries struct {
	id         SeriesID
	Name       string            `json:"name"`
	Tags       map[string]string `json:"tags"`
	SeriesType int               `json:"type"`
	Precision  time.Duration     `json:"precision"`
	Points     json.RawMessage   `json:"points"`
}

type IntSeries struct {
	id         SeriesID
	Name       string            `json:"name"`
	Tags       map[string]string `json:"tags"`
	SeriesType int               `json:"type,omitempty"`
	Precision  time.Duration     `json:"precision,omitempty"`
	Points     []IntPoint        `json:"points"`
}

type DoubleSeries struct {
	id         SeriesID
	Name       string            `json:"name"`
	Tags       map[string]string `json:"tags"`
	SeriesType int               `json:"type,omitempty"`
	Precision  time.Duration     `json:"precision,omitempty"`
	Points     []DoublePoint     `json:"points"`
}

// TODO: int series of other precision, maybe we should add millisecond to the default function as well
func NewIntSeries(name string) *IntSeries {
	return &IntSeries{
		Name:       name,
		Tags:       make(map[string]string, 1),
		SeriesType: TypeIntSeries,
		Precision:  time.Millisecond,
	}
}

func NewDoubleSeries(name string) *DoubleSeries {
	return &DoubleSeries{
		Name:       name,
		Tags:       make(map[string]string, 1),
		SeriesType: TypeDoubleSeries,
		Precision:  time.Millisecond,
	}
}

func (series *SeriesMeta) GetName() string {
	return series.Name
}

func (series *SeriesMeta) GetTags() map[string]string {
	return series.Tags
}

func (series *SeriesMeta) GetSeriesType() int {
	return series.SeriesType
}

func (series *SeriesMeta) GetSeriesID() SeriesID {
	if series.id == 0 {
		series.id = Hash(series)
	}
	return series.id
}

func (series *RawSeries) GetName() string {
	return series.Name
}

func (series *RawSeries) GetTags() map[string]string {
	return series.Tags
}

func (series *RawSeries) GetSeriesType() int {
	return series.SeriesType
}

func (series *RawSeries) GetSeriesID() SeriesID {
	if series.id == 0 {
		series.id = Hash(series)
	}
	return series.id
}

func (series *IntSeries) GetName() string {
	return series.Name
}

func (series *IntSeries) GetTags() map[string]string {
	return series.Tags
}

func (series *IntSeries) GetSeriesType() int {
	// TODO: do we still need the variable if we return constant, and should we check consistency for that
	return TypeIntSeries
}

func (series *IntSeries) GetSeriesID() SeriesID {
	if series.id == 0 {
		series.id = Hash(series)
	}
	return series.id
}

func (series *DoubleSeries) GetName() string {
	return series.Name
}

func (series *DoubleSeries) GetTags() map[string]string {
	return series.Tags
}

func (series *DoubleSeries) GetSeriesType() int {
	return TypeDoubleSeries
}

func (series *DoubleSeries) GetSeriesID() SeriesID {
	if series.id == 0 {
		series.id = Hash(series)
	}
	return series.id
}

func SeriesTypeString(seriesType int) string {
	switch seriesType {
	case TypeIntSeries:
		return "int"
	case TypeDoubleSeries:
		return "double"
	case TypeBoolSeries:
		return "bool"
	case TypeStringSeries:
		return "string"
	default:
		return fmt.Sprintf("unknown: %d", seriesType)
	}
}
<commit_msg>[common][series] Use SeriesMeta as anonymous field<commit_after>package common

import (
	"encoding/json"
	"fmt"
	"time"
)

// check interface
var _ Series = (*SeriesMeta)(nil)
var _ Series = (*RawSeries)(nil)
var _ Series = (*IntSeries)(nil)
var _ Series = (*DoubleSeries)(nil)

const (
	_ = iota
	TypeIntSeries
	TypeDoubleSeries
	TypeBoolSeries
	TypeStringSeries
)

type Series interface {
	Hashable
	GetSeriesType() int
	// NOTE: series decoded from JSON has 0 as SeriesID, so the implementation would recalculate the Hash
	GetSeriesID() SeriesID
}

type SeriesMeta struct {
	id         SeriesID
	Name       string            `json:"name"`
	Tags       map[string]string `json:"tags"`
	SeriesType int               `json:"type"`
	Precision  time.Duration     `json:"precision"`
}

type RawSeries struct {
	SeriesMeta
	Points json.RawMessage `json:"points"`
}

type IntSeries struct {
	SeriesMeta
	Points []IntPoint `json:"points"`
}

type DoubleSeries struct {
	SeriesMeta
	Points []DoublePoint `json:"points"`
}

// TODO: int series of other precision, maybe we should add millisecond to the default function as well
func NewIntSeries(name string) *IntSeries {
	// return &IntSeries{
	// 	Name:       name,
	// 	Tags:       make(map[string]string, 1),
	// 	SeriesType: TypeIntSeries,
	// 	Precision:  time.Millisecond,
	// }

	s := IntSeries{}
	s.Name = name
	s.Tags = map[string]string{}
	s.SeriesType = TypeIntSeries
	s.Precision = time.Millisecond
	return &s
}

func NewDoubleSeries(name string) *DoubleSeries {
	// return &DoubleSeries{
	// 	Name:       name,
	// 	Tags:       make(map[string]string, 1),
	// 	SeriesType: TypeDoubleSeries,
	// 	Precision:  time.Millisecond,
	// }
	s := DoubleSeries{}
	s.Name = name
	s.Tags = map[string]string{}
	s.SeriesType = TypeDoubleSeries
	s.Precision = time.Millisecond
	return &s
}

func (series *SeriesMeta) GetName() string {
	return series.Name
}

func (series *SeriesMeta) GetTags() map[string]string {
	return series.Tags
}

func (series *SeriesMeta) GetSeriesType() int {
	return series.SeriesType
}

func (series *SeriesMeta) GetSeriesID() SeriesID {
	if series.id == 0 {
		series.id = Hash(series)
	}
	return series.id
}

func SeriesTypeString(seriesType int) string {
	switch seriesType {
	case TypeIntSeries:
		return "int"
	case TypeDoubleSeries:
		return "double"
	case TypeBoolSeries:
		return "bool"
	case TypeStringSeries:
		return "string"
	default:
		return fmt.Sprintf("unknown: %d", seriesType)
	}
}

{'fraction_non_alphanumeric': 0.11130325420531363, 'fraction_numerical': 0.0017292878478226694, 'mean_word_length': 3.613488034807832, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4399500', 'n_tokens_mistral': 2091, 'n_tokens_neox': 2034, 'n_words': 575}