<commit_before>package repositories

import (
	"github.com/vlad-doru/experimento/data"
	// "golang.org/x/net/context"
	// "google.golang.org/grpc"
	// "fmt"
)

type ImmutableRepository struct {
	experiments map[string]data.Experiment
}

func NewImmutableRepository() *ImmutableRepository {
	experiments := make(map[string]data.Experiment)
	return &ImmutableRepository{experiments}
}

// CreateExperiment saves an experiment with the given description in the repository.
// func (repository *MemoryRepository) CreateExperiment(exp data.Experiment) error {
// 	_, ok := repository.experiments[exp.Info.Id]
// 	if ok == true {
// 		return fmt.Errorf("There is already an experiment with the given id: %s", exp.Info.Id)
// 	}
// 	repository.experiments[exp.Info.Id] = exp
// 	return nil
// }
//
// // GetExperiment returns the experiment description of the experiment with the
// // specified experiment id.
// func (repository *MemoryRepository) GetExperiment(expID string) (data.Experiment, error) {
// 	exp, ok := repository.experiments[expID]
// 	if ok == false {
// 		return data.Experiment{}, fmt.Errorf("The experiment with id %s does not exist.", expID)
// 	}
// 	return exp, nil
// }
//
// // DestroyExperiment removes the experiment with the given id from the repository.
// func (repository *MemoryRepository) DestroyExperiment(expID string) {
// 	delete(repository.experiments, expID)
// }
//
// // GetExperiments returns all the current experiments form the memory.
// func (repository *MemoryRepository) GetExperiments() (map[string]data.Experiment, error) {
// 	return repository.experiments, nil
// }<commit_msg>Implemented the interfaces for the server.<commit_after>package repositories

import (
	"github.com/vlad-doru/experimento/data"
	"golang.org/x/net/context"
)

type ImmutableRepository struct {
	experiments map[string]data.Experiment
}

func NewImmutableRepository() *ImmutableRepository {
	experiments := make(map[string]data.Experiment)
	return &ImmutableRepository{experiments}
}

func (repository *ImmutableRepository) SaveExperiment(c context.Context, exp *data.Experiment) (*data.Response, error) {
	_, ok := repository.experiments[exp.Info.Id]
	if ok == true {
		return &data.Response{
			Ok:    false,
			Error: "There is already an experiment with the given id!",
		}, nil
	}
	repository.experiments[exp.Info.Id] = *exp
	return &data.Response{
		Ok: true,
	}, nil
}

func (repository *ImmutableRepository) DropExperiment(c context.Context, info *data.ExperimentInfo) (*data.Response, error) {
	delete(repository.experiments, info.Id)
	return &data.Response{
		Ok: true,
	}, nil
}

func (repository *ImmutableRepository) GetExperiments(context.Context, *data.Void) (*data.Experiments, error) {
	result := &data.Experiments{Experiments: make(map[string]*data.Experiment)}
	for key, value := range repository.experiments {
		result.Experiments[key] = &value
	}
	return result, nil
}
{'fraction_non_alphanumeric': 0.13019580900034353, 'fraction_numerical': 0.0, 'mean_word_length': 4.52561669829222, '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': '3502004', 'n_tokens_mistral': 919, 'n_tokens_neox': 895, 'n_words': 227}