private static void ExecutePredictionAndStore(IForecastRepository db, string date, Tuple <float[][], float[][]> values, float[][] latLons, String ModelName) { DateTime dateToAdd = DateTime.ParseExact(date, "yyyyMMdd", null); var predictions = PredictionUtilities.PredictDangerV1(values.Item2, ModelName); if (latLons.Length != predictions.Count()) { throw new Exception("Predictions don't have the same lenth as LatLon"); } var mappedPredictions = new List <ForecastPoint>(); var mappedPredictionsOnlyNorthWest = new List <ForecastPoint>(); for (int i = 0; i < latLons.Length; i++) { mappedPredictions.Add(new ForecastPoint(dateToAdd, ModelName, latLons[i][0], latLons[i][1], predictions[i])); if (latLons[i][0] > 42.0 && latLons[i][1] < -118.0) { mappedPredictionsOnlyNorthWest.Add(new ForecastPoint(dateToAdd, ModelName + "NW", latLons[i][0], latLons[i][1], predictions[i])); } } //upload the predictions to table storage var forecast = new Forecast(mappedPredictions); var forecastNw = new Forecast(mappedPredictionsOnlyNorthWest); db.SaveForecast(forecast); db.SaveForecast(forecastNw); db.SaveForecastDate(new ForecastDate(dateToAdd)); }
/// <summary> /// Main method to calculate predictions /// Created to be called via webapi /// </summary> /// <param name="db">Repository to use; if null we will use default repo</param> /// <param name="dateOfForecast">Date of forecast to create; if null we use use current date</param> public static void MakePredictions(IForecastRepository db, string dateOfForecast) { IForecastRepository theDb; if (db == null) { theDb = new AzureTableForecastRepository(); } else { theDb = db; } string localFileName = Path.GetTempFileName(); //CloudBlobContainer container = AzureUtilities.FeaturesBlobContainer; string cloudFileName = "V1Features" + dateOfForecast + ".csv"; var adlsClient = AzureUtilities.AdlsClient; adlsClient.FileSystem.DownloadFile( WebConfigurationManager.AppSettings["ADLSAccountName"], "/inputfeatures-csv-westus-v1/" + cloudFileName, localFileName, overwrite: true); var values = PredictionUtilities.CreatePredictionFormat(localFileName); var latLons = values.Item1; ExecutePredictionAndStore(theDb, dateOfForecast, values, latLons, Constants.ModelDangerAboveTreelineV1); ExecutePredictionAndStore(theDb, dateOfForecast, values, latLons, Constants.ModelDangerBelowTreelineV1); ExecutePredictionAndStore(theDb, dateOfForecast, values, latLons, Constants.ModelDangerNearTreelineV1); }