internal void SaveResult(DateTime predict_date, SP_Predict_AnimalList_Result item, double prob_calving, double missing_gaps) { int bolus_id = item.bolus_id; Prediction pr = new Prediction(); pr.bolus_id = bolus_id; pr.analysis_date = predict_date; pr.prob_calving = prob_calving; pr.prop_missing = 1 - missing_gaps; pr.confidence = missing_gaps; pr.date_stamp = DateTime.UtcNow; try { using (DB_A4A060_csEntities context = new DB_A4A060_csEntities()) { context.Predictions.Add(pr); context.SaveChanges(); } } catch (Exception ex) { throw; } }
public void Write(string note) { Log lg = new Log { user_id = "Admin", page = "http://193.27.73.63/Predict/CPStart.html", function_query = "Predict", error = "", note = note, datestamp = DateTime.UtcNow, recipient = Properties.Settings.Default.emails }; try { using (DB_A4A060_csEntities context = new DB_A4A060_csEntities()) { context.Logs.Add(lg); context.SaveChanges(); } } catch (Exception ex) { EmailBox em = new EmailBox(); em.SendEmail("*****@*****.**", Properties.Settings.Default.UserName, "Predict - " + ex.Message, "Predict error"); throw; } }
internal List <Prediction> ReadData() { List <Prediction> result = new List <Prediction>(); try { using (DB_A4A060_csEntities context = new DB_A4A060_csEntities()) { result = context.Predictions.OrderByDescending(x => x.date_stamp).ToList(); } } catch (Exception ex) { result = null; } return(result); }
private static double GetLastProb(int bolus_id) { double result = 0; try { using (DB_A4A060_csEntities context = new DB_A4A060_csEntities()) { result = context.Predictions.OrderByDescending(t => t.id).Where(x => x.bolus_id == bolus_id).Take(1).SingleOrDefault().prob_calving; } } catch (Exception) { result = -1; } return(result); }
private static string GetFarmNameByBolusID(int bolus_id) { string result = string.Empty; try { using (DB_A4A060_csEntities context = new DB_A4A060_csEntities()) { result = context.SP_Farm_GetNameByBolus_ID(bolus_id).SingleOrDefault().Name; ; } } catch (Exception) { result = "N/A"; } return(result); }
internal double MissingGapsProc(int bolus_id, DateTime predict_date) { double result = 0; try { using (DB_A4A060_csEntities context = new DB_A4A060_csEntities()) { result = context.SP_Predict_GetGapsStatByAnimalID(bolus_id, predict_date).SingleOrDefault().gaps.Value; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("GetMeasDataByAnimalId : " + ex.Message); result = -1; } return(result); }
//1. Extract the temperature data from the database for the specified animal_id // and for datetime from 0:00 on dat-2 to 18:00 on dat. internal double GetMeasDataByAnimalId(int bolus_id, DateTime predict_date) { List <SP_Predict_GetTempByAnimalID_Result> result = new List <SP_Predict_GetTempByAnimalID_Result>(); List <SP_Predict_GetGapsInInterval_Result> factors = new List <SP_Predict_GetGapsInInterval_Result>(); try { using (DB_A4A060_csEntities context = new DB_A4A060_csEntities()) { result = context.SP_Predict_GetTempByAnimalID(bolus_id, predict_date).ToList(); factors = context.SP_Predict_GetGapsInInterval(bolus_id, predict_date).ToList(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("GetMeasDataByAnimalId : " + ex.Message); } //1.1 check if last 3 factors = 0 if (Check3Lastfactors(result)) { return(-103); } //2. calculate probability double prob = Intercept; int i = 0; double TempInterval = 0; foreach (var item in result) { //System.Diagnostics.Debug.WriteLine("result="+ item.MaxValue.Value); TempInterval = item.MaxValue; if (factors[i].factor == 0 || factors[i].factor > Properties.Settings.Default.FactorMax) { TempInterval = TempVal[i]; } prob += Coeff[i] * TempInterval; i++; } //3. finish prob = 1.0 / (1 + Math.Exp(-prob)); return(prob); }
private static List <SP_Predict_AnimalList_Result> GetAnimalIdList() { List <SP_Predict_AnimalList_Result> result = new List <SP_Predict_AnimalList_Result>(); //1. Define predict date DateTime predict_date = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "Eastern Standard Time").Date; // get animal_id list from database try { using (DB_A4A060_csEntities context = new DB_A4A060_csEntities()) { result = context.SP_Predict_AnimalList(predict_date, Properties.Settings.Default.PredictInterval).ToList(); if (result.Count == 0) { result = null; } } } catch (Exception) { result = null; } return(result); }