public async Task <string> PredictStockQuantity(string selectcategory, string selectdepartment, int month, int year) { using (var client = new HttpClient()) { PredictViewModel predModel = new PredictViewModel(); predModel.CategoryName = selectcategory; predModel.Departmentname = selectdepartment; predModel.Month = month; predModel.Year = year; HttpResponseMessage res = await client.PostAsJsonAsync("http://127.0.0.1:5000/", predModel); if (res.IsSuccessStatusCode) { string predicted = res.Content.ReadAsStringAsync().Result; Debug.WriteLine("PREDICTION : " + predicted); return(predicted); } else { Debug.WriteLine("ERROR"); return("error"); } } }
public PredictWine() { InitializeComponent(); BindingContext = viewModel = new PredictViewModel(); MessagingCenter.Subscribe <PredictViewModel, string>(this, "Predict", async(obj, prediction) => await DisplayAlert("Prediction", $"Wine quality: {prediction}", "OK")); }
public async Task <ActionResult> Index(PredictViewModel viewModel) { if (!ModelState.IsValid) { return(RedirectToAction("Index", new { gameweek = viewModel.GameWeek.Id })); } await predictionService.SavePredictions(viewModel.Predictions, User.Identity.Name); return(Redirect("~/")); }
public IActionResult Predict(SpamInput input) { var predictVm = new PredictViewModel(); var result = predictVm.IsTrue(input); if (!ModelState.IsValid) { return(View()); } if (result) { ModelState.AddModelError("Message", "Invalid text found"); input.Message = ""; return(View(input)); } return(View()); }
public async Task <ActionResult> Index(string gameweek) { if (string.IsNullOrEmpty(gameweek)) { return(Redirect("~/")); } var gw = await gameWeekService.GetGameWeekById(Guid.Parse(gameweek)); var predictions = await predictionService.GetPredictionsForGameWeek(gw, User.Identity.Name); var table = await leagueService.GetPremierLeagueTable(); var viewModel = new PredictViewModel { GameWeek = gw, Predictions = predictions, LeagueTable = table }; return(View(viewModel)); }
public async Task <ActionResult> PlaceOrder (string supplier, List <PredictViewModel> predModel, string sessionId) { if (Sessions.IsValidSession(sessionId)) { ViewData["sessionId"] = sessionId; Supplier supplier1 = new Supplier(); List <Products> products = new List <Products>(); ViewData["SupplierName"] = supplier; //fetch largest PO number from database, and generate next for displaying var maxPO = 1; if ((from c in db.Orders select c).Any()) { maxPO = (from c in db.Orders select c).Max(c => c.POnumber); maxPO++; } else { ViewData["maxPO"] = maxPO; } //fetch list of products from Supplier //var quest = from a in db.Suppliers // join b in db.Products // on a.SupplierId equals b.Supplier1 // where a.SupplierName == supplier // select b; if (supplier == null) { var quest = from a in db.Suppliers join b in db.Products on a.SupplierId equals b.SupplierId select b; products = quest.ToList(); } else { var quest = from a in db.Suppliers join b in db.Products on a.SupplierId equals b.SupplierId where a.SupplierId == supplier select b; products = quest.ToList(); } supplier1.Products = products; using (var client = new HttpClient()) { //Machine learning: predModel = new List <PredictViewModel>(); foreach (Products p in products) { PredictViewModel element = new PredictViewModel { ItemCode = int.Parse((p.ItemCode[0] % 32).ToString() + p.ItemCode.Substring(1, p.ItemCode.Length - 1)), //ItemCode = int.Parse(p.ItemCode.Substring(1, p.ItemCode.Length - 1)), Month = DateTime.Now.Month, }; predModel.Add(element); } HttpResponseMessage res = await client.PostAsJsonAsync("http://127.0.0.1:5000/", predModel); if (res.IsSuccessStatusCode) { // pass the result by setting the Viewdata property // have to read as string for the data in response.body ViewData["Message"] = res.Content.ReadAsStringAsync().Result; //to deserialize the message in to string array string message = res.Content.ReadAsStringAsync().Result; Debug.WriteLine(message); string[] split = message.Split(new Char[] { '"', '[', ']', ',' }); split = split.Where(x => !string.IsNullOrEmpty(x)).ToArray(); split = split.Where(x => x != "\n").ToArray(); Debug.WriteLine(split.Length); List <string> outcomes = new List <string>(); foreach (string s in split) { Debug.WriteLine("it is: " + s); outcomes.Add(s); } ViewData["outcomes"] = outcomes; supplier1.Products = products; return(View(supplier1)); } else { return(View("Error")); } } } else { return(RedirectToAction("Login", "Login")); } }