public override bool AddExperiment(Experiment experiment, int segments) { var numberAvailable = AvailableSeqments.Count; if (numberAvailable < segments || ActiveExperiments.ContainsKey(experiment.Name)) { return(false); } var assigment = new Assignment(Name); assigment.Set("sampled_segments", new SampleBuilder(new Dictionary <string, object>() { { "choices", AvailableSeqments }, { "draws", segments } }, new Dictionary <string, object>() { { "experiment_name", experiment.Name } })); var sample = (List <int>)assigment.Get("sampled_segments"); foreach (int segment in sample) { AllocationMap[segment] = experiment.Name; var index = AvailableSeqments.IndexOf(segment); AvailableSeqments.RemoveAt(index); numberAvailable -= 1; } ActiveExperiments[experiment.Name] = experiment; return(true); }
public override bool RemoveExperiment(string name) { if (!ActiveExperiments.ContainsKey(name)) { return(false); } var keysToRemove = (from segmentAllocation in AllocationMap where segmentAllocation.Value == name select segmentAllocation.Key).ToList(); foreach (var key in keysToRemove) { AllocationMap.Remove(key); AvailableSeqments.Add(key); } return(true); }