<commit_before>package parameter

import (
	"encoding/json"
	"errors"
	"io"
)

type Parameter struct{}

type ParameterJson struct {
	Name    string  `json:"name"`
	Value   float32 `json:"value"`
	Measure string  `json:"measure"`
}

func (s *Parameter) Store(body io.ReadCloser) (string, error) {
	param, err := decodeJson(body)
	if err != nil {
		return "", err
	}
	err = validateParameterFields(param)
	if err != nil {
		return "", err
	}
	return "", err
}

func validateParameterFields(param ParameterJson) error {
	if param.Name == "" {
		return errors.New("field name is required")
	}
	if param.Measure == "" {
		return errors.New("field measure is required")
	}
	return nil
}

func decodeJson(body io.ReadCloser) (ParameterJson, error) {
	d := json.NewDecoder(body)
	var param ParameterJson
	err := d.Decode(&param)
	if err != nil {
		return ParameterJson{}, err
	}
	defer body.Close()
	return param, err
}

func NewParameter() *Parameter {
	return &Parameter{}
}<commit_msg>call store func in parameter logic<commit_after>package parameter

import (
	"encoding/json"
	"errors"
	"io"
)

type Storer interface {
	Store(interface{}) error
}

type Parameter struct {
	s Storer
}

type ParameterJson struct {
	Name    string  `json:"name"`
	Value   float32 `json:"value"`
	Measure string  `json:"measure"`
}

func (param *Parameter) Put(body io.ReadCloser) (string, error) {
	paramJson, err := decodeJson(body)
	if err != nil {
		return "", err
	}
	err = validateParameterFields(paramJson)
	if err != nil {
		return "", err
	}
	err = param.s.Store(paramJson)
	if err != nil {
		return "", err
	}
	return "", err
}

func validateParameterFields(param ParameterJson) error {
	if param.Name == "" {
		return errors.New("field name is required")
	}
	if param.Measure == "" {
		return errors.New("field measure is required")
	}
	return nil
}

func decodeJson(body io.ReadCloser) (ParameterJson, error) {
	d := json.NewDecoder(body)
	var param ParameterJson
	err := d.Decode(&param)
	if err != nil {
		return ParameterJson{}, err
	}
	defer body.Close()
	return param, err
}

func NewParameter(storer Storer) *Parameter {
	return &Parameter{
		s: storer,
	}
}
{'fraction_non_alphanumeric': 0.13283790060380865, 'fraction_numerical': 0.0018578727357176034, 'mean_word_length': 4.104265402843602, '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': '1965396', 'n_tokens_mistral': 736, 'n_tokens_neox': 720, 'n_words': 208}