<commit_before>// Copyright (c) 2015, <NAME>. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.

package main

import (
	"errors"
	"fmt"
	"net/url"
	"strconv"
	"strings"
	"time"
)

type Measurement struct {
	UnixTime    int64
	Temperature float32
	Humidity    float32
}

func (x *Measurement) Update(lag float32, m Measurement) {
	x.UnixTime = m.UnixTime
	x.Temperature = (1-lag)*x.Temperature + lag*m.Temperature
	x.Humidity = (1-lag)*x.Humidity + lag*m.Humidity
}

func (x Measurement) String() string {
	t := time.Unix(x.UnixTime, 0).Format(time.Stamp)
	return fmt.Sprintf("%v: %.1f \u2103C at %.1f%% humidity", t, x.Temperature, x.Humidity)
}

func (x Measurement) Record() []string {
	return []string{time.Unix(x.UnixTime, 0).Format("2006-01-02 15:04:05"),
		strconv.FormatFloat(float64(x.Temperature), 'f', 1, 32),
		strconv.FormatFloat(float64(x.Humidity), 'f', 1, 32),
	}
}

func (m *Measurement) FromRecord(rs []string) error {
	if len(rs) != 3 {
		return errors.New("invalid record length")
	}

	var err error
	m.UnixTime, err = strconv.ParseInt(rs[0], 10, 64)
	if err != nil {
		return err
	}
	f, err := strconv.ParseFloat(rs[1], 32)
	if err != nil {
		return err
	}
	m.Temperature = float32(f)
	f, err = strconv.ParseFloat(rs[2], 32)
	if err != nil {
		return err
	}
	m.Humidity = float32(f)
	return nil
}

func (x Measurement) Marshal(v url.Values) string {
	t := v.Get("type")
	switch t {
	case "csv":
		return strings.Join(x.Record(), ",")
	case "string":
		return x.String()
	case "tabular":
		fallthrough
	default:
		r := x.Record()
		return fmt.Sprintf("time:        %s\ntemperature: %s\nhumidity:    %s", r[0], r[1], r[2])
	}
}

func (x Measurement) Same(y Measurement) bool {
	return x.Temperature == y.Temperature && x.Humidity == y.Humidity
}<commit_msg>Bugfix: time not read correctly<commit_after>// Copyright (c) 2015, <NAME>. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.

package main

import (
	"errors"
	"fmt"
	"net/url"
	"strconv"
	"strings"
	"time"
)

const measurementTimeFormat = "2006-01-02 15:04:05"

type Measurement struct {
	UnixTime    int64
	Temperature float32
	Humidity    float32
}

func (x *Measurement) Update(lag float32, m Measurement) {
	x.UnixTime = m.UnixTime
	x.Temperature = (1-lag)*x.Temperature + lag*m.Temperature
	x.Humidity = (1-lag)*x.Humidity + lag*m.Humidity
}

func (x Measurement) String() string {
	t := time.Unix(x.UnixTime, 0).Format(time.Stamp)
	return fmt.Sprintf("%v: %.1f \u2103C at %.1f%% humidity", t, x.Temperature, x.Humidity)
}

func (x Measurement) Record() []string {
	return []string{time.Unix(x.UnixTime, 0).Format(measurementTimeFormat),
		strconv.FormatFloat(float64(x.Temperature), 'f', 1, 32),
		strconv.FormatFloat(float64(x.Humidity), 'f', 1, 32),
	}
}

func (m *Measurement) FromRecord(rs []string) error {
	if len(rs) != 3 {
		return errors.New("invalid record length")
	}

	t, err := time.Parse(measurementTimeFormat, rs[0])
	if err != nil {
		return err
	}
	m.UnixTime = t.Unix()
	f, err := strconv.ParseFloat(rs[1], 32)
	if err != nil {
		return err
	}
	m.Temperature = float32(f)
	f, err = strconv.ParseFloat(rs[2], 32)
	if err != nil {
		return err
	}
	m.Humidity = float32(f)
	return nil
}

func (x Measurement) Marshal(v url.Values) string {
	t := v.Get("type")
	switch t {
	case "csv":
		return strings.Join(x.Record(), ",")
	case "string":
		return x.String()
	case "tabular":
		fallthrough
	default:
		r := x.Record()
		return fmt.Sprintf("time:        %s\ntemperature: %s\nhumidity:    %s", r[0], r[1], r[2])
	}
}

func (x Measurement) Same(y Measurement) bool {
	return x.Temperature == y.Temperature && x.Humidity == y.Humidity
}
{'fraction_non_alphanumeric': 0.16118769883351008, 'fraction_numerical': 0.03340402969247084, 'mean_word_length': 3.8621134020618557, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, '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': '2231565', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1449, 'n_words': 381}