candle_stick_point.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <vector>
11 #include "interop/util/math.h"
13 
14 namespace illumina { namespace interop { namespace model { namespace plot
15 {
16 
19  class candle_stick_point : public data_point<float, float>
20  {
21  public:
23  typedef std::vector<float> float_vector_t;
24  public:
36  candle_stick_point(const float x = 0,
37  const float p25 = 0,
38  const float p50 = 0,
39  const float p75 = 0,
40  const float lower = std::numeric_limits<y_type>::quiet_NaN(),
41  const float upper = std::numeric_limits<y_type>::quiet_NaN(),
42  const size_t data_point_count = 0,
43  const float_vector_t &outliers = float_vector_t()) : data_point<float, float>(x, p50),
44  m_p25(p25),
45  m_p75(p75),
46  m_lower(lower),
47  m_upper(upper),
48  m_data_point_count(data_point_count),
49  m_outliers(outliers)
50  { }
51 
52  public:
65  float max_value() const
66  {
67  return std::isnan(upper()) ? y() : upper();
68  }
69 
74  float min_value() const
75  {
76  return std::isnan(lower()) ? y() : lower();
77  }
78 
83  float p25() const
84  {
85  return m_p25;
86  }
87 
92  float p50() const
93  {
94  return y();
95  }
96 
101  float p75() const
102  {
103  return m_p75;
104  }
105 
110  float lower() const
111  {
112  return m_lower;
113  }
114 
119  float upper() const
120  {
121  return m_upper;
122  }
123 
128  const float_vector_t &outliers() const
129  {
130  return m_outliers;
131  }
132 
137  size_t data_point_count() const
138  {
139  return m_data_point_count;
140  }
143  public:
144  friend std::ostream& operator<<(std::ostream& out, const candle_stick_point& data)
145  {
146  const size_t precision = 10;
147  out << static_cast< const data_point<float, float>& > (data);
148  out << std::setprecision(precision) << io::table::handle_nan(data.m_p25) << ",";
149  out << std::setprecision(precision) << io::table::handle_nan(data.m_p75) << ",";
150  out << std::setprecision(precision) << io::table::handle_nan(data.m_lower) << ",";
151  out << std::setprecision(precision) << io::table::handle_nan(data.m_upper) << ",";
152  out << data.m_data_point_count << ",";
153  out << data.m_outliers.size() << ",";
154  io::table::write_csv(out, data.m_outliers.begin(), data.m_outliers.end(), ',');
155  return out;
156  }
157  friend std::istream& operator>>(std::istream& in, candle_stick_point& data)
158  {
159  in >> static_cast< data_point<float, float>& > (data);
160  std::string tmp;
161 
162  io::table::read_value(in, data.m_p25, tmp);
163  io::table::read_value(in, data.m_p75, tmp);
164  io::table::read_value(in, data.m_lower, tmp);
165  io::table::read_value(in, data.m_upper, tmp);
166  io::table::read_value(in, data.m_data_point_count, tmp);
167  const size_t num_outliers = io::table::read_value<size_t>(in, tmp);
168  data.m_outliers.resize(num_outliers);
169  io::table::read_csv(in, data.m_outliers.begin(), data.m_outliers.end());
170  return in;
171  }
172 
173  private:
174  y_type m_p25;
175  y_type m_p75;
176  y_type m_lower;
177  y_type m_upper;
178  size_t m_data_point_count;
179  float_vector_t m_outliers;
180  };
181 
182 
183 }}}}
184 
T read_value(std::istream &in, std::string &buf, const char delim=',')
Definition: csv_format.h:43
size_t data_point_count() const
Definition: candle_stick_point.h:137
Definition: enum_description.h:15
float upper() const
Definition: candle_stick_point.h:119
const float_vector_t & outliers() const
Definition: candle_stick_point.h:128
float p25() const
Definition: candle_stick_point.h:83
void write_csv(std::ostream &out, I beg, I end, const char eol, const size_t precision=10)
Definition: csv_format.h:117
Definition: candle_stick_point.h:19
float y() const
Definition: data_point.h:58
friend std::istream & operator>>(std::istream &in, candle_stick_point &data)
Definition: candle_stick_point.h:157
const T & handle_nan(const T &val)
Definition: csv_format.h:84
float x() const
Definition: data_point.h:50
float min_value() const
Definition: candle_stick_point.h:74
float p50() const
Definition: candle_stick_point.h:92
float p75() const
Definition: candle_stick_point.h:101
float max_value() const
Definition: candle_stick_point.h:65
candle_stick_point(const float x=0, const float p25=0, const float p50=0, const float p75=0, const float lower=std::numeric_limits< y_type >::quiet_NaN(), const float upper=std::numeric_limits< y_type >::quiet_NaN(), const size_t data_point_count=0, const float_vector_t &outliers=float_vector_t())
Definition: candle_stick_point.h:36
friend std::ostream & operator<<(std::ostream &out, const candle_stick_point &data)
Definition: candle_stick_point.h:144
void read_csv(std::istream &in, I beg, I end, const char delim=',')
Definition: csv_format.h:69
std::vector< float > float_vector_t
Definition: candle_stick_point.h:23
float lower() const
Definition: candle_stick_point.h:110