| 543 | } |
| 544 | |
| 545 | double smmax(double x, const std::string_view& variable, const std::weak_ptr<Payload> payload) { |
| 546 | const auto p = std::dynamic_pointer_cast<PayloadExpressionParser>(payload.lock()); |
| 547 | if (!p) { |
| 548 | assert(p); // Debug build |
| 549 | return NAN; |
| 550 | } |
| 551 | |
| 552 | for (int i = 0; i < p->vars->length(); i++) { |
| 553 | if (p->vars->at(i).compare(QLatin1String(variable)) == 0) { |
| 554 | const int N = x; |
| 555 | DEBUG("N = " << N) |
| 556 | if (N < 1) |
| 557 | break; |
| 558 | // calculate max of last n points |
| 559 | double max = -INFINITY; |
| 560 | const int row = p->row; |
| 561 | for (int index = std::max(0, row - N + 1); index <= row; index++) { |
| 562 | const double v = p->xVectors->at(i)->at(index); |
| 563 | if (v > max) |
| 564 | max = v; |
| 565 | } |
| 566 | return max; |
| 567 | } |
| 568 | } |
| 569 | return NAN; |
| 570 | } |
| 571 | |
| 572 | double sma(double x, const std::string_view& variable, const std::weak_ptr<Payload> payload) { |
| 573 | const auto p = std::dynamic_pointer_cast<PayloadExpressionParser>(payload.lock()); |