public async Task <PostGameViewModel> SubmitGameForEvaluation([FromBody] GameAnswersViewModel model) { return(await _playedGameRepository.CalculateScore(model)); //return await _playedGameRepository.CalculateScore(model, "2ABBCA73-1E06-4F1F-9105-71B97E84451A"); //this.RequestContext.Principal.Identity.GetUserId()); }
private static double CalculateScore(Games game, GameAnswersViewModel answers) { var score = 0.0; var tempScore = GetTempScore(game.Question1Id, answers, 0); score += tempScore; tempScore = GetTempScore(game.Question2Id, answers, 1); score += tempScore; tempScore = GetTempScore(game.Question3Id, answers, 2); score += tempScore; tempScore = GetTempScore(game.Question4Id, answers, 3); score += tempScore; tempScore = GetTempScore(game.Question5Id, answers, 4); score += tempScore; tempScore = GetTempScore(game.Question6Id, answers, 5); score += tempScore; tempScore = GetTempScore(game.Question7Id, answers, 6); score += tempScore; tempScore = GetTempScore(game.Question8Id, answers, 7); score += tempScore; tempScore = GetTempScore(game.Question9Id, answers, 8); score += tempScore; tempScore = GetTempScore(game.Question10Id, answers, 9); score += tempScore; return(score); }
private static double GetTempScore(Guid questionId, GameAnswersViewModel answers, int questionIndex) { var _questionRepository = new QuestionRepository(); var question = _questionRepository.GetById(questionId); var tempScore = CostFunction(DegreeDifferenceToKmDifference(question.Latitude, question.Longitude, answers.Latitudes[questionIndex], answers.Longitudes[questionIndex])); if (answers.Hints2Used[questionIndex]) { tempScore *= 0.25; } else if (answers.Hints1Used[questionIndex]) { tempScore *= 0.5; } return(tempScore); }
public async Task <PostGameViewModel> CalculateScore(GameAnswersViewModel answers) { var userInfoRepository = new UserInfoRepository(); var userGuid = Guid.NewGuid(); await userInfoRepository.CreateUserInfoFromUser(userGuid.ToString(), answers.Username); var newUser = userInfoRepository.GetById(userGuid); var game = _gameRepository.GetById(Guid.Parse(answers.GameId)); var playedGame = new PlayedGames() { PlayedGameId = Guid.NewGuid(), DatePlayed = DateTime.Now, GameId = game.GameId, Score = CalculateScore(game, answers), UserInfoId = newUser.UserInfoId }; Insert(playedGame); newUser.TotalScore += playedGame.Score; if (newUser.HighScore < playedGame.Score) { newUser.HighScore = playedGame.Score; } userInfoRepository.Update(newUser); var usersAchievements = await userInfoRepository.GetEarnedAchievements(newUser.UserInfoId.ToString()); var achievements = await GetNewAchievements(usersAchievements, playedGame.Score, newUser.UserInfoId); return(new PostGameViewModel() { Score = playedGame.Score, NewAchievements = achievements }); }
public async Task <PostGameViewModel> SubmitGameForEvaluationTest([FromUri] GameAnswersViewModel model) { return(await _playedGameRepository.CalculateScore(model)); }