protected override DataStreamUnit[] _Execute(DataStreamUnit[] source) { try { if (!_initialized) { _forecast = new Forecast() { ForecastModelId = this.ForecastModelId }; _measurement = repository.FirstOrDefault(x => x.MeasurementId == this.MeasurementId); if (_measurement == null) { _measurement = new Measurement {MeasurementId = this.MeasurementId}; } _measurement.Forecasts.Add(_forecast); _initialized = true; } var data = source.ToList(); var result = new ForecastResult(); if (data[0].Values.ContainsKey("MAPE")) { result.Error = data[0].Values["MAPE"] as double?; } result.TimeStamp = (DateTime)data[0].Values["TimeStamp"]; result.RealValue = data[0].Values["Value"] as double?; result.PredictedValue = data[0].Values["PredictedValue"] as double?; _forecast.Error = result.Error; _forecast.Results.Add(result); repository.Update(_measurement); } catch (Exception e) { Logging.Info(e.Message); } return source; }
private ChartViewModel GetChart(Forecast forecast) { var model = new ChartViewModel(); model.ChartName = forecast.ForecastModelId; var results = forecast.Results; var values = GetValuesForChart(results); model.ChartData = JsonConvert.SerializeObject(values); var lastDate = forecast.Results.LastOrDefault().TimeStamp; //lastDate = lastDate.AddHours(12).Date; //округляем до ближайшего дня model.Error = CalculateMAPE(forecast.Results.SkipWhile(x => x.TimeStamp < testStartDateProvider.GetTimestampOfTestStart(lastDate))); return model; }