public double ForecastYieldCow(int idCow) { double forecastValue = 0; //Verifica se a vaca existe Cow cowValid = repoCow.GetCow(idCow); if (cowValid != null) { Lactation currentLact = cowValid.lactations.FirstOrDefault(l => l.finished == false); int numYields = currentLact.yields.ToList().Count; int minRecords = 0; int.TryParse(ConfigurationManager.AppSettings["minRecords"], out minRecords); //Verifica se existe registros suficientes if (numYields >= minRecords) { //Executa o script em R que calcula o valor de previsão forecastValue = ForecastValue(idCow); int goahead = int.Parse(ConfigurationManager.AppSettings["goahead"]); Prediction prediction = new Prediction { idLactation = currentLact.idLactation, yield = forecastValue, dayLactationPredicted = currentLact.yields.OrderByDescending(y => y.dayLactation).FirstOrDefault().dayLactation + goahead }; predictionRepo.Add(prediction); } else { //throw new Exception("Number of records is insufficient"); } //Task.Run(() => notificationService.ValidateDataCow(idCow, currentLact, forecastValue)); //CHAMA SERVIÇO DE NOTIFICAÇÃO notificationService.ValidateDataCow(idCow, currentLact, forecastValue); } return(forecastValue); }
public async Task <ActionResult <Prediction> > Post(Prediction entity) { await _repository.Add(entity); return(CreatedAtAction("Get", new { id = entity.Id }, entity)); }