private List <Product> ConvertOffers(IEnumerable <Offer> offers, int shopWeight) { var calculation = new RatingCalculation(shopWeight); var products = new ProductConverter(_dbHelper, calculation).GetProductsContainer(offers); SetProgress(80); AddMessage("Convert to products complete"); return(products); }
private void CalculateRating(string result, User white, User black) { double scoreWhite = result.Equals("1/2") ? 0.5 : result.Equals("1 : 0") ? 1 : 0; double scoreBlack = result.Equals("1/2") ? 0.5 : result.Equals("1 : 0") ? 0 : 1; int whiteRating = white.PlayingRating; int blackRating = black.PlayingRating; white.PlayingRating += (int)RatingCalculation.CalculateElo(whiteRating, blackRating, scoreWhite); black.PlayingRating += (int)RatingCalculation.CalculateElo(whiteRating, blackRating, scoreBlack); userRepository.UpdateUser(white); userRepository.UpdateUser(black); }
public JsonResult CheckMove(string move, int moveNumber, int id) { var position = positionRepository.FindPositionById(id); if (position == null) { return(Json(new { result = false, message = Resources.DefaultErrorMessage })); } var userSolution = userSolutionRepository.FindUserSolutionByIdentifiers(WebSecurity.CurrentUserId, id); if (userSolution.IsSolved) { return(Json(new { result = false, message = Resources.SolvedProblemMessage, attempt = string.Format(Resources.NumberOfAttemptsMessage, userSolution.NumberOfAttempts) })); } if (CheckSolution.CheckMove(move, moveNumber, position.Solution)) { userSolution.CurrentMove = moveNumber; userSolution.DateUpdated = DateTime.Now; userSolution.IsSolved = (moveNumber + 1) == position.Solution.Count; if (userSolution.IsSolved) { userSolution.NumberOfAttempts++; userSolution.User.ProblemRating = RatingCalculation.CalculateRatingProblem(userSolution.User.ProblemRating, (int)position.Difficulty - userSolution.NumberOfAttempts / 10); } userSolutionRepository.UpdateUserSolution(userSolution); return(Json(new { result = true, message = userSolution.IsSolved ? Resources.SolvedProblemMessage : Resources.CorrectMoveMessage, attempt = string.Format(Resources.NumberOfAttemptsMessage, userSolution.NumberOfAttempts) })); } else { userSolution.DateUpdated = DateTime.Now; userSolution.NumberOfAttempts++; userSolutionRepository.UpdateUserSolution(userSolution); return(Json(new { result = false, message = Resources.IncorrectMoveMessage, attempt = string.Format(Resources.NumberOfAttemptsMessage, userSolution.NumberOfAttempts) })); } }
public ProductConverter(DbHelper dbHelper, RatingCalculation calculation) { _dbHelper = dbHelper; _calculation = calculation; }