TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
ResultsControllerExporter.cs
Go to the documentation of this file.
1 // TraceLab Component Library
2 // Copyright © 2012-2013 SEMERU
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using TraceLabSDK;
22 using TraceLabSDK.Types.Contests;
23 using System.ComponentModel;
24 using TraceLabSDK.Component.Config;
25 using TraceLab.Components.DevelopmentKit.Metrics;
26 using System.IO;
27 
28 namespace TraceLab.Components.Library.Metrics.Controller
29 {
30  [Component(Name = "(UI) Results Metrics Exporter",
31  Description = "Exports the metrics computed by previous metrics components to disk.",
32  Author = "SEMERU; Evan Moritz",
33  Version = "1.0.0.0",
34  ConfigurationType = typeof(ResultsControllerExporterConfig))]
35  [Tag("Metrics.Visualization")]
36  public class ResultsControllerExporter : BaseComponent
37  {
38  private ResultsControllerExporterConfig _config;
39 
40  public ResultsControllerExporter(ComponentLogger log)
41  : base(log)
42  {
43  _config = new ResultsControllerExporterConfig();
44  Configuration = _config;
45  }
46 
47  public override void Compute()
48  {
49  // get snapshot of entries in results
50  // data is stale as soon as it is retrieved,
51  // but there are no deletions
52  IEnumerable<string> techniques = ResultsController.Instance.Techniques;
53  IEnumerable<string> datasets = ResultsController.Instance.Datasets;
54  // iterate over datasets
55  foreach (string dataset in datasets)
56  {
57  Logger.Info("Exporting: " + dataset);
58  // iterate over techniques
59  foreach (string technique in techniques)
60  {
61  // iterate over metrics
62  foreach (IMetricComputation computation in ResultsController.Instance.GetResults(technique, dataset))
63  {
64  try
65  {
66  // export metric to disk
67  DevelopmentKit.IO.Metrics.Export(computation,
68  GenerateFileName(_config.OutputDir.Absolute, dataset, technique, computation.Name),
69  _config.GenerateSummary
70  );
71  }
72  catch (ComponentException e)
73  {
74  Logger.Debug(e.Message);
75  }
76  }
77  }
78  }
79  }
80 
84  private string GenerateFileName(string directory, string dataset, string technique, string computation)
85  {
86  return Path.Combine(directory, dataset + "." + technique + "." + computation);
87  }
88  }
89 
91  {
92  [DisplayName("Generate summaries?")]
93  [Description("Option to additionally generate summary data.")]
94  public bool GenerateSummary { get; set; }
95 
96  [DisplayName("Output directory")]
97  [Description("Directory to write results files")]
98  public DirectoryPath OutputDir { get; set; }
99  }
100 }