plot_regression_test_generator.h
Go to the documentation of this file.
1 
9 #pragma once
10 #include <vector>
13 
14 namespace illumina { namespace interop { namespace unittest
15 {
16 
20  template<class PlotData>
22  {
24  typedef typename parent_t::base_t base_type;
25  public:
31  plot_regression_test_generator(const std::string& test_dir, const constants::plot_types plot_type) :
32  parent_t(test_dir), m_plot_type(plot_type)
33  {
34  //regression_test_data::instance().add_subdir(test_dir);
35  }
42  plot_regression_test_generator(const std::string& run_folder,
43  const std::string& test_dir,
44  const constants::plot_types plot_type) :
45  parent_t(run_folder, test_dir), m_plot_type(plot_type)
46  {
47  m_metric_iterator.reset(parent_t::m_run_folder, plot_type);
48  }
49 
50  public:
55  std::string baseline()const
56  {
57  return parent_t::baseline()+"_"+name();
58  }
59 
60  protected:
67  bool generate_actual(const std::string& run_folder, PlotData& actual)const
68  {
69  model::metrics::run_metrics& actual_metrics = get_metrics(run_folder);
70  if( actual_metrics.empty() )return false;
71  try
72  {
73  m_metric_iterator.plot(actual_metrics, actual);
74  }
75  catch(const std::exception& ex)
76  {
77  std::cerr << "generate_actual: " << ex.what() << std::endl;
78  throw;
79  }
80  return !actual.empty();
81  }
86  void write(std::ostream& out)const
87  {
88  out << io::basename(parent_t::m_run_folder) << " -> " << name();
89  }
94  bool advance()
95  {
96  return m_metric_iterator.advance();
97  }
102  base_type clone() const
103  {
104  return new plot_regression_test_generator(*this);
105  }
110  base_type clone(const std::string& run_folder) const
111  {
112  return new plot_regression_test_generator(run_folder, parent_t::m_test_dir, m_plot_type);
113  }
120  bool read_expected(const std::string& baseline_file, PlotData& expected)const
121  {
122  std::ifstream fin(baseline_file.c_str());
123  if( !fin.good() ) return false;
124  try
125  {
126  fin >> expected;
127  }
128  catch(const std::exception& ex)
129  {
130  std::cerr << "Failed with exception: " << ex.what() << std::endl;
131  return false;
132  }
133  if( fin.eof() ) return !expected.empty();
134  return !fin.fail() && !expected.empty();
135  }
141  bool write_actual(const std::string& baseline_file, const PlotData& actual)const
142  {
143  std::ofstream fout(baseline_file.c_str());
144  fout << actual;
145  return fout.good();
146  }
147 
148  private:
149  static model::metrics::run_metrics& get_metrics(const std::string& run_folder)
150  {
151  static std::string current;
152  static model::metrics::run_metrics actual_metrics;
153  if( current != run_folder )
154  {
155  actual_metrics.clear();
156  current = run_folder;
157  read_metrics_safe(actual_metrics, run_folder);
158  }
159 
160  return actual_metrics;
161  }
162 
163  private:
164  std::string name()const
165  {
166  return constants::to_string(m_plot_type) + "_"
167  + "_Metric_" + constants::to_string(m_metric_iterator.metric())
168  + "_" + util::lexical_cast<std::string>(m_metric_iterator.options());
169  }
170 
171  private:
172  constants::plot_types m_plot_type;
173  metric_filter_iterator m_metric_iterator;
174  };
175 
176 
177 }}}
Definition: plot_regression_test_generator.h:21
Definition: enum_description.h:15
void write(std::ostream &out) const
Definition: plot_regression_test_generator.h:86
void plot(model::metrics::run_metrics &run, model::plot::plot_data< model::plot::candle_stick_point > &data) const
Definition: metric_filter_iterator.h:72
std::string basename(std::string const &source)
Definition: filesystem.cpp:95
plot_types
Definition: enums.h:339
plot_regression_test_generator(const std::string &run_folder, const std::string &test_dir, const constants::plot_types plot_type)
Definition: plot_regression_test_generator.h:42
std::string baseline() const
Definition: plot_regression_test_generator.h:55
void read(const std::string &run_folder, const size_t thread_count=1) INTEROP_THROW_SPEC((xml void read(const std::string &run_folder, const std::vector< unsigned char > &valid_to_load, const size_t thread_count=1, const bool skip_loaded=false) INTEROP_THROW_SPEC((xml size_t read_xml(const std::string &run_folder) INTEROP_THROW_SPEC((io void read_run_info(const std::string &run_folder) INTEROP_THROW_SPEC((xml size_t read_run_parameters(const std::string &run_folder, const bool force_load=false) INTEROP_THROW_SPEC((io void finalize_after_load(size_t count=std::numeric_limits< size_t >::max()) INTEROP_THROW_SPEC((model bool empty() const
Definition: run_metrics.h:223
void clear()
Definition: run_metrics.cpp:557
base_type clone(const std::string &run_folder) const
Definition: plot_regression_test_generator.h:110
bool advance()
Definition: plot_regression_test_generator.h:94
bool read_expected(const std::string &baseline_file, PlotData &expected) const
Definition: plot_regression_test_generator.h:120
void reset(const std::string &run_info_filename, const constants::plot_types plot_type)
Definition: metric_filter_iterator.h:57
constants::metric_type metric() const
Definition: metric_filter_iterator.h:197
bool generate_actual(const std::string &run_folder, PlotData &actual) const
Definition: plot_regression_test_generator.h:67
virtual std::string baseline() const
Definition: abstract_regression_test_generator.h:114
bool advance()
Definition: metric_filter_iterator.h:217
const model::plot::filter_options & options() const
Definition: metric_filter_iterator.h:208
plot_regression_test_generator(const std::string &test_dir, const constants::plot_types plot_type)
Definition: plot_regression_test_generator.h:31
abstract_generator< PlotData >::parent_type base_t
Definition: abstract_regression_test_generator.h:26
void read_metrics_safe(model::metrics::run_metrics &metrics, const std::string &run_folder)
Definition: abstract_regression_test_generator.h:158
std::string m_run_folder
Definition: abstract_regression_test_generator.h:148
Definition: abstract_regression_test_generator.h:22
std::string m_test_dir
Definition: abstract_regression_test_generator.h:150
bool write_actual(const std::string &baseline_file, const PlotData &actual) const
Definition: plot_regression_test_generator.h:141
std::string to_string(Enum value)
Definition: enums.h:43
base_type clone() const
Definition: plot_regression_test_generator.h:102