/// <summary> /// Build an in-memory CLR dictionary of month-prediction /// </summary> /// <returns>Success of building model</returns> public bool BuildPredictionModel() { bool success = false; try { IList <WeatherData> weatherData = excelClient.RetrieveAllFromSheet(Constants.ExcelSheetIndex); rainfallPredictionModel = new Dictionary <int, RainfallResult>(); foreach (var weatherDataPoint in weatherData) { int month = weatherDataPoint.Month; float prcp = weatherDataPoint.Prcp; if (!rainfallPredictionModel.ContainsKey(month)) { rainfallPredictionModel[month] = new RainfallResult(); } rainfallPredictionModel[month].PrcpList.Add(prcp); } success = true; } catch (Exception ex) { throw ex; } return(success); }
public IHttpActionResult Get(string dateSource) { DateTime validDate; bool canParseDate = DateTime.TryParse(dateSource, out validDate); if (canParseDate) { RainfallResult model = null; try { model = _weatherEngine.GetRainfallPrediction(validDate); } catch (Exception ex) { BadRequest(ex.Message); } return(Ok(new RainfallResultViewModel { MeanPrcp = model.MeanPrcp, StdDev = model.StdDev })); } return(BadRequest("Invalid date format supplied by user")); }