<commit_before>package js

import (
	"errors"
	"fmt"
	"github.com/loadimpact/speedboat/stats"
	"github.com/robertkrimen/otto"
	"strings"
)

type InitAPI struct {
	r *Runtime
}

func (i InitAPI) NewMetric(it int, name string, isTime bool) *stats.Metric {
	t := stats.MetricType(it)
	vt := stats.Default
	if isTime {
		vt = stats.Time
	}

	if m, ok := i.r.Metrics[name]; ok {
		if m.Type != t {
			throw(i.r.VM, errors.New(fmt.Sprintf("attempted to redeclare %s with a different type (%s != %s)", name, m.Type, t)))
			return nil
		}
		if m.Contains != vt {
			throw(i.r.VM, errors.New(fmt.Sprintf("attempted to redeclare %s with a different kind of value (%s != %s)", name, m.Contains, vt)))
		}
		return m
	}

	m := stats.New(name, t)
	i.r.Metrics[name] = m
	return m
}<commit_msg>[fix] isTime ignored in JS-created metrics<commit_after>package js

import (
	"errors"
	"fmt"
	"github.com/loadimpact/speedboat/stats"
	"github.com/robertkrimen/otto"
	"strings"
)

type InitAPI struct {
	r *Runtime
}

func (i InitAPI) NewMetric(it int, name string, isTime bool) *stats.Metric {
	t := stats.MetricType(it)
	vt := stats.Default
	if isTime {
		vt = stats.Time
	}

	if m, ok := i.r.Metrics[name]; ok {
		if m.Type != t {
			throw(i.r.VM, errors.New(fmt.Sprintf("attempted to redeclare %s with a different type (%s != %s)", name, m.Type, t)))
			return nil
		}
		if m.Contains != vt {
			throw(i.r.VM, errors.New(fmt.Sprintf("attempted to redeclare %s with a different kind of value (%s != %s)", name, m.Contains, vt)))
		}
		return m
	}

	m := stats.New(name, t, vt)
	i.r.Metrics[name] = m
	return m
}
{'fraction_non_alphanumeric': 0.16050156739811913, 'fraction_numerical': 0.0, 'mean_word_length': 3.458100558659218, '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': '4374741', 'n_tokens_mistral': 664, 'n_tokens_neox': 625, 'n_words': 172}