18 using System.Collections.Generic;
21 using TraceLab.Components.DevelopmentKit.Metrics;
23 using TraceLabSDK.Types.Contests;
25 namespace TraceLab.Components.Library.Metrics.Controller
29 #region Singleton utilities
65 #region Class definition
69 private Object _lock =
new Object();
76 _techniques =
new HashSet<string>();
77 _datasets =
new HashSet<string>();
78 _results =
new Dictionary<string, List<IMetricComputation>>();
81 private HashSet<string> _techniques;
82 private HashSet<string> _datasets;
83 private Dictionary<string, List<IMetricComputation>> _results;
88 public IEnumerable<string> Techniques
94 return new HashSet<string>(_techniques);
102 public IEnumerable<string> Datasets
108 return new HashSet<string>(_datasets);
124 if (String.IsNullOrWhiteSpace(technique))
126 throw new ComponentException(
"Technique name cannot be empty.");
128 if (String.IsNullOrWhiteSpace(dataset))
130 throw new ComponentException(
"Dataset name cannot be empty.");
132 if (computation == null)
134 throw new ComponentException(
"Computation cannot be null.");
138 _techniques.Add(technique);
139 _datasets.Add(dataset);
140 string key = ComputeKey(technique, dataset);
141 if (!_results.ContainsKey(key))
143 _results.Add(key,
new List<IMetricComputation>());
145 _results[key].Add(computation);
156 public IEnumerable<IMetricComputation>
GetResults(
string technique,
string dataset)
158 if (String.IsNullOrWhiteSpace(technique))
160 throw new ComponentException(
"Technique name cannot be empty.");
162 if (String.IsNullOrWhiteSpace(dataset))
164 throw new ComponentException(
"Dataset name cannot be empty.");
168 if (!_techniques.Contains(technique))
170 throw new ComponentException(
"Collection does not contain technique \"" + technique +
"\"");
172 if (!_datasets.Contains(dataset))
174 throw new ComponentException(
"Collection does not contain dataset \"" + dataset +
"\"");
176 List<IMetricComputation> list = null;
177 string key = ComputeKey(technique, dataset);
178 _results.TryGetValue(key, out list);
181 throw new ComponentException(
"Could not retrieve data from collection: (" + technique +
", " + dataset +
")");
183 return new List<IMetricComputation>(list);
196 TLExperimentsResultsCollection ExperimentsResultsCollection =
new TLExperimentsResultsCollection();
198 foreach (
string technique
in _techniques)
200 TLExperimentResults TechniqueResults =
new TLExperimentResults(technique);
202 foreach (
string dataset
in _datasets)
205 List<IMetricComputation> list = null;
206 string key = ComputeKey(technique, dataset);
207 _results.TryGetValue(key, out list);
210 DatasetResults data =
new DatasetResults(dataset);
221 if (data.Metrics.Count() > 0)
223 TechniqueResults.AddDatasetResult(data);
228 if (TechniqueResults.DatasetsResults.Count() > 0)
230 ExperimentsResultsCollection.Add(TechniqueResults);
233 return ExperimentsResultsCollection;
243 private string ComputeKey(
string technique,
string dataset)
245 return technique +
"_" + dataset;