struct batch_options | |
{ | |
bool m_with_minimum; | |
bool m_with_average; | |
bool m_with_variations; | |
double m_limit; | |
std::function<bool (stock_update const&)> m_filter; | |
}; | |
struct batch_result | |
{ | |
double m_minimum; | |
double m_average; | |
int m_variation_count; | |
}; | |
batch_result terrible_design(std::vector<std::string> const& source, batch_options const& options) | |
{ | |
batch_result result; | |
result.m_minimum = std::numeric_limits<double>::max(); | |
result.m_average = 0.0; | |
result.m_variation_count = 0; | |
int count = 0; | |
double init_value = 0.0; | |
for (auto& msg: source) | |
{ | |
stock_update s = parse_message(msg); | |
if (!options.m_filter(s)) | |
continue; | |
if (count == 0) | |
init_value = s.m_value; | |
++count; | |
if (options.m_with_minimum) | |
result.m_minimum = std::min(result.m_minimum, s.m_value); | |
if (options.m_with_average) | |
result.m_average += s.m_value; | |
if (options.m_with_variations) | |
if (abs(s.m_value - init_value) > options.m_limit) | |
++result.m_variation_count; | |
} | |
if (count) | |
result.m_average /= count; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment