// A bakery's daily sales for six weeks (busy weekends, slowly growing): next week forecast with
// Holt-Winters (a 7-day season), the model chosen automatically against the others, simpler
// forecasts for comparison, and how accurate last week's forecast was.
//
//   quillo run forecast.qwe      then open http://localhost:8080/next_week

use "forecast.qwer"

let SALES = [83.0, 89.4, 95.8, 102.5, 125.2, 164.2, 68.9, 86.4, 98.8, 105.8, 118.0, 137.8, 175.0, 75.7, 94.8, 113.2, 115.8, 123.5, 150.4, 190.8, 87.5, 103.2, 117.7, 125.8, 134.0, 168.0, 206.5, 89.3, 111.6, 127.2, 140.8, 144.5, 175.6, 222.2, 96.2, 125.0, 136.6, 145.7, 155.0, 188.2, 243.0, 103.0]

route GET /next_week {
    let hw = forecast_holt_winters(SALES, 7, "multiplicative", {}, 7)?
    { forecast: hw.forecast, low_95: hw.lower_95, high_95: hw.upper_95, params: hw.params, rmse: hw.rmse }
}

route GET /auto {
    let best = forecast_auto(SALES, 7, 7, 7)?
    { model: best.model, compared: best.compared, forecast: best.forecast }
}

route GET /simple = {
    average: forecast_moving_average(SALES, 7, 3)?.forecast,
    ses: forecast_ses(SALES, null, 3)?.params,
    holt: forecast_holt(SALES, 0.3, 0.1, true, 3)?.forecast,
    accuracy: forecast_accuracy([120.0, 130.0, 0.0, 150.0], [118.0, 135.0, 2.0, 140.0])?,
}
