// GET: MyTasks public async Task <IActionResult> Index(string myTaskTag, string location) { if (UsersController.logged_user == null) { return(RedirectToAction("Privacy", "Home")); } IQueryable <MyTask.TagType> tagsQuery = from m in _context.MyTask orderby m.Tag select m.Tag; var myTasks = from m in _context.MyTask select m; myTasks = myTasks.Where(asgn => asgn.Asignee == null); if (!string.IsNullOrEmpty(location)) { myTasks = myTasks.Where(s => s.Location.Contains(location)); } if (!string.IsNullOrEmpty(myTaskTag)) { MyTask.TagType tag = (MyTask.TagType)Enum.Parse(typeof(MyTask.TagType), myTaskTag); myTasks = myTasks.Where(x => x.Tag == tag); } var myTaskAsigneeVM = new MyTaskAsigneeViewModel { Tags = new SelectList(await tagsQuery.Distinct().ToListAsync()), MyTasks = await myTasks.ToListAsync() }; return(View(myTaskAsigneeVM)); }
public LocationWeights(int id, float w1_1, float b1_1, string location, MyTask.TagType tag) { this.Id = id; this.w1_1 = w1_1; this.b1 = b1_1; this.location = location; this.tag = tag; }
public Weights(int id, float w0_0, float w0_1, float w0_2, float w0_3, float b0, MyTask.TagType tag) { this.Id = id; this.w0_0 = w0_0; this.w0_1 = w0_1; this.w0_2 = w0_2; this.w0_3 = w0_3; this.b0 = b0; this.tag = tag; }
public void BackPropagation(float b0_t0, float b1_t0, float w0_0_t0, float w0_1_t0, float w0_2_t0, float w0_3_t0, float w1_1_t0, float actual_price, string location, MyPlannerContext _context, int weights_id, int weights_location_id, MyTask.TagType tag) { float suggested_price = this.SuggestedPrice(b0_t0, b1_t0, w0_0_t0, w0_1_t0, w0_2_t0, w0_3_t0, w1_1_t0); float b0_t1 = b0_t0; //updated biases float b1_t1 = b1_t0; float w0_0_t1 = w0_0_t0; //updated weights; float w0_1_t1 = w0_1_t0; float w0_2_t1 = w0_2_t0; float w0_3_t1 = w0_3_t0; float w1_1_t1 = w1_1_t0; int n = 0; float temp_correction_b0 = 0; actual_price = actual_price / Duration; //Derivative of cost with respect to weights for second layer if (w1_1_t0 * a1 + b1_t0 > 0) { w1_1_t1 -= (learning_rate * 2 * (w1_1_t0 * a1 + b1_t0 - actual_price) * a1); } // Derivative of cost with respect to biases for second layer if (w1_1_t0 * a1 + b1_t0 > 0) { b1_t1 -= (learning_rate * 2 * (w1_1_t0 * a1 + b1_t0 - actual_price)); } //Derivative of cost with respect to weights for first layer if (w0_0_t0 * x1 + b0_t0 > 0) { float correction = (learning_rate * 2 * (w0_0_t0 * x0 + b0_t0 - ((actual_price - b1_t0) / w1_1_t0) * x0 * w1_1_t0)); w0_0_t1 -= correction; } if (w0_1_t0 * x1 + b0_t0 > 0) { float correction = (learning_rate * 2 * ((w0_1_t0 * x1 + b0_t0 - (actual_price - b1_t0) / w1_1_t0) * x1 * w1_1_t0)); w0_1_t1 -= correction; } if (w0_2_t0 * x2 + b0_t0 > 0) { float correction = (learning_rate * 2 * ((w0_2_t0 * x2 + b0_t0 - (actual_price - b1_t0) / w1_1_t0) * x2 * w1_1_t0)); w0_2_t1 -= correction; } if (w0_3_t0 * x3 + b0_t0 > 0) { float correction = (learning_rate * 2 * ((w0_3_t0 * x3 + b0_t0 - (actual_price - b1_t0) / w1_1_t0) * x3 * w1_1_t0)); w0_3_t1 -= correction; } // Derivative of cost with respect to biases for first layer if (w0_0_t0 * x0 + b0_t0 > 0) { temp_correction_b0 -= (learning_rate * 2 * (w0_0_t0 * x1 + b0_t0 - (actual_price - b1_t0) / w1_1_t0)); n += 1; } if (w0_1_t0 * x1 + b0_t0 > 0) { temp_correction_b0 -= (learning_rate * 2 * (w0_1_t0 * x1 + b0_t0 - (actual_price - b1_t0) / w1_1_t0)); n += 1; } if (w0_2_t0 * x2 + b0_t0 > 0) { temp_correction_b0 -= (learning_rate * 2 * (w0_2_t0 * x2 + b0_t0 - (actual_price - b1_t0) / w1_1_t0)); n += 1; } if (w0_3_t0 * x3 + b0_t0 > 0) { temp_correction_b0 -= (learning_rate * 2 * (w0_3_t0 * x3 + b0_t0 - (actual_price - b1_t0) / w1_1_t0)); n += 1; } b0_t1 += temp_correction_b0 / n; Weights weights_t1 = new Weights(weights_id + 1, w0_0_t1, w0_1_t1, w0_2_t1, w0_3_t1, b0_t1, tag); LocationWeights location_weights_t1 = new LocationWeights(weights_location_id + 1, w1_1_t1, b1_t1, location, tag); _context.Add(weights_t1); _context.Add(location_weights_t1); }
public async Task <IActionResult> Edit(Guid id, string Description, DateTime Due_Date, string Owner, string Location, RatingType Rating, RatingType RatingOwn, MyTask.FakeBoolType Transfer, int Duration, MyTask.FakeBoolType Physical_Effort, MyTask.TagType Tag, string Asignee, MyTask.StatusType Status, float Price) { var myTask = _context.MyTask.Find(id); bool msg_err = false; if (id != myTask.Id) { return(NotFound()); } if (ModelState.IsValid) { var user_asgn = _context.User.FirstOrDefault(m => m.username == Asignee); string asgn_name = null; if (user_asgn != null) { asgn_name = user_asgn.username; } else { if (!string.IsNullOrEmpty(Asignee)) { ViewBag.Message = string.Format("User does not exist"); return(View(myTask)); } } var user_own = await _context.User.FirstOrDefaultAsync(n => n.username == Owner); string own_name = null; if (user_own != null) { own_name = user_own.username; } else { ViewBag.Message = string.Format("User does not exist"); return(View(myTask)); } if (UsersController.logged_user.username == asgn_name || UsersController.logged_user.username == own_name) { if (Description != myTask.Description) { myTask.Description = Description; } if (Due_Date != myTask.Due_Date) { myTask.Due_Date = Due_Date; } if (Owner != myTask.Owner) { myTask.Owner = Owner; } if (Location != myTask.Location) { myTask.Location = Location; } if (Tag != myTask.Tag) { myTask.Tag = Tag; } if (Asignee != myTask.Asignee) { myTask.Asignee = Asignee; } if (Status != myTask.Status) { myTask.Status = Status; } if (Rating != RatingType.NoRating && user_asgn != null) { myTask.Rating = Rating; myTask.RatingInt = (int)Rating; user_asgn.rating_float = (user_asgn.no_ratings * user_asgn.rating_float + (int)Rating) / (user_asgn.no_ratings + 1); user_asgn.rating_float = (float)Math.Round(user_asgn.rating_float, 2); user_asgn.no_ratings = user_asgn.no_ratings + 1; } /* else * { * ViewBag.Message = string.Format("Rating cannot be changed"); * msg_err = true; * }*/ if (RatingOwn != RatingType.NoRating && user_own != null) { myTask.RatingOwn = RatingOwn; myTask.RatingOwnInt = (int)RatingOwn; user_own.rating_float = (user_own.no_ratings * user_own.rating_float + (int)RatingOwn) / (user_own.no_ratings + 1); user_own.rating_float = (float)Math.Round(user_own.rating_float, 2); user_own.no_ratings = user_own.no_ratings + 1; } /* else * { * ViewBag.Message = string.Format("Rating cannot be changed"); * msg_err = true; * } */ if (Transfer != myTask.Transfer) { myTask.Transfer = Transfer; } if (Duration != myTask.Duration) { myTask.Duration = Duration; } if (Physical_Effort != myTask.Physical_Effort) { myTask.Physical_Effort = Physical_Effort; } if (Price != 0) { myTask.Price = Price; Weights weights; LocationWeights location_weights; IQueryable <Weights> weightsQuery = from w in _context.Weights select w; var temp_weights = new List <Weights>(await weightsQuery.ToListAsync()); weights = temp_weights.Last(cat => cat.tag == myTask.Tag); IQueryable <LocationWeights> l_weightsQuery = from l_w in _context.LocationWeights select l_w; var temp_l_weights = new List <LocationWeights>(await l_weightsQuery.ToListAsync()); var loc_weights_list = temp_l_weights.Where(loc => loc.location == myTask.Location); location_weights = loc_weights_list.Last(cat => cat.tag == myTask.Tag); IQueryable <Weights> last_w_query = from lw in _context.Weights select lw; var temp_last_w = new List <Weights>(await last_w_query.ToListAsync()); int last_w_id = temp_last_w.Last().Id; //get last id for saving new weights IQueryable <LocationWeights> last_loc_w_query = from loc_w in _context.LocationWeights select loc_w; var temp_last_loc_w = new List <LocationWeights>(await last_loc_w_query.ToListAsync()); int last_loc_w_id = temp_last_loc_w.Last().Id; //get last id for saving new location weights myTask.BackPropagation(weights.b0, location_weights.b1, weights.w0_0, weights.w0_1, weights.w0_2, weights.w0_3, location_weights.w1_1, myTask.Price, location_weights.location, _context, last_w_id, last_loc_w_id, myTask.Tag); } try { if (user_asgn != null) { _context.Update(user_asgn); } _context.Update(myTask); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MyTaskExists(myTask.Id)) { return(NotFound()); } else { throw; } } } else { msg_err = true; } //return RedirectToAction("Dashboard", "Users", UsersController.logged_user); //return RedirectToAction("Index"); if (!msg_err) { return(RedirectToAction("Dashboard", "Users", UsersController.logged_user)); } else { ViewBag.Message = string.Format("You are not allowed to change this information"); return(View(myTask)); } } else { throw new System.Web.Http.HttpResponseException(System.Net.HttpStatusCode.BadRequest); } }