private MatchPredictionType GetMatchPredictionType(Match match, MatchPrediction matchPrediction) { MatchPredictionType predictionType; if (match.HomeTeamScore.MatchResult.Value == matchPrediction.HomeTeamScore.MatchResult.Value && match.AwayTeamScore.MatchResult.Value == matchPrediction.AwayTeamScore.MatchResult.Value) { predictionType = MatchPredictionType.Exact; } else if (match.GoalDifference == matchPrediction.GoalDifference) { predictionType = MatchPredictionType.GoalDifference; } else if (match.MatchWinner != null && matchPrediction.MatchWinner != null && match.MatchWinner.Id == matchPrediction.MatchWinner.Id) { predictionType = MatchPredictionType.MatchWinner; } else if (match.MatchResultType.Value == MatchResultType.Withdraw && match.MatchResultType == matchPrediction.MatchResultType) { predictionType = MatchPredictionType.MatchWinner; } else { predictionType = MatchPredictionType.Wrong; } return(predictionType); }
private IList <MatchPrediction> GetMatchPredictions(Worksheet predictionSheet) { var matchPredictions = new List <MatchPrediction>(); const int startRow = 11; var matchId = 1; for (int currentRow = startRow; currentRow <= 40; currentRow++) { if (predictionSheet.Range["A" + currentRow].Value == null || predictionSheet.Range["A" + currentRow].Value == "" || predictionSheet.Range["A" + currentRow].Value.ToString().Contains("Group")) { continue; } var matchPrediction = new MatchPrediction { MatchId = matchId, HomeTeam = new Team { Name = predictionSheet.Range["A" + currentRow].Value }, AwayTeam = new Team { Name = predictionSheet.Range["B" + currentRow].Value }, HomeGoals = Convert.ToInt32(predictionSheet.Range["C" + currentRow].Value), AwayGoals = Convert.ToInt32(predictionSheet.Range["D" + currentRow].Value) }; matchPredictions.Add(matchPrediction); matchId += 1; // GROUP E-H matchPrediction = new MatchPrediction { MatchId = matchId, HomeTeam = new Team { Name = predictionSheet.Range["G" + currentRow].Value }, AwayTeam = new Team { Name = predictionSheet.Range["H" + currentRow].Value }, HomeGoals = Convert.ToInt32(predictionSheet.Range["I" + currentRow].Value), AwayGoals = Convert.ToInt32(predictionSheet.Range["J" + currentRow].Value) }; matchPredictions.Add(matchPrediction); matchId += 1; } return(matchPredictions); }
double score) CalculateMatchScore(Match match, MatchPrediction matchPrediction) { if (!match.MatchHasStarted) { return(null, null, 0); } if (match.HomeTeamScore.MatchResult is null || match.AwayTeamScore.MatchResult is null) { return(null, null, 0); } if (matchPrediction == null) { return(null, null, 0); } if (matchPrediction.HomeTeamScore.MatchResult is null || matchPrediction.AwayTeamScore.MatchResult is null) { return(null, null, 0); } var matchPredictionType = GetMatchPredictionType(match, matchPrediction); var penaltyPredictionType = GetPenaltyPredictionType(match, matchPrediction); if (matchPrediction.MatchResultType != match.MatchResultType) { return(matchPredictionType, penaltyPredictionType, 0); } if (matchPrediction.MatchWinner?.Id != match.MatchWinner?.Id) { return(matchPredictionType, penaltyPredictionType, 0); } var matchRule = GetPredictionRule(match); var score = 0.0; if (matchRule.UseFormulaForComputingScore) { score = matchRule.GetScoreBasedOnFormula(match, matchPrediction, penaltyPredictionType); } else { score = matchRule.GetScoreOfPredictionType(matchPredictionType, penaltyPredictionType); } return(matchPredictionType, penaltyPredictionType, score); }
private PenaltyPredictionType GetPenaltyPredictionType(Match match, MatchPrediction matchPrediction) { PenaltyPredictionType predictionType; if (match.PenaltyWinner != null && matchPrediction.PenaltyWinner != null && match.PenaltyWinner.Id == matchPrediction.PenaltyWinner.Id) { predictionType = PenaltyPredictionType.Correct; } else { predictionType = PenaltyPredictionType.Wrong; } return(predictionType); }
public string AddPrediction(MatchPrediction matchPrediction) { string res = "Failed"; try { QLEntities objEntity = new QLEntities(); using (var connection = objEntity.Database.Connection) { if (connection.State != ConnectionState.Open) { connection.Open(); } SqlCommand command = new SqlCommand("SP_QL_AddMatchPrediction"); command.Connection = (SqlConnection)(connection); command.CommandType = CommandType.StoredProcedure; //command.CommandText = string.Format("exec SP_QL_UpdateAnswerByTeam"); command.Parameters.AddWithValue("@NT_ID", matchPrediction.NT_ID); command.Parameters.AddWithValue("@Stage1WinnerTeam", matchPrediction.Stage1WinnerTeam); command.Parameters.AddWithValue("@Stage2WinnerTeam", matchPrediction.Stage2WinnerTeam); command.Parameters.AddWithValue("@Stage3WinnerTeam", matchPrediction.Stage3WinnerTeam); command.Parameters.AddWithValue("@WinnerTeam", matchPrediction.WinnerTeam); var result = Convert.ToInt32(command.ExecuteScalar()); if (result == 0) { res = "Success"; } } } catch (Exception ex) { res = ex.ToString(); } return(res); }
public async Task <IActionResult> PredictMatch([FromBody] MatchPredictionCommand command) { var userBetGroup = await GetCurrentUserBetGroup(command.BetGroupId); var match = await GetMatchWithId(command.MatchId); if (match.DateTime.LocalDateTime < DateTime.Now) { return(Unauthorized()); } var prediction = await _dbContext.MatchPredictions .SingleOrDefaultAsync(q => q.MatchId == command.MatchId && q.UserBetGroupId == userBetGroup.Id); if (prediction == null) { prediction = new MatchPrediction() { MatchId = command.MatchId, UserBetGroupId = userBetGroup.Id, AwayTeamScore = new TeamScore() { TeamId = match.AwayTeamScore.TeamId, MatchResult = command.AwayMatchResult }, HomeTeamScore = new TeamScore() { TeamId = match.HomeTeamScore.TeamId, MatchResult = command.HomeMatchResult } }; if (command.AwayMatchResult == command.HomeMatchResult && !command.PenaltyWinnerTeamId.HasValue) { return(BadRequest()); } if (command.AwayMatchResult == command.HomeMatchResult && command.PenaltyWinnerTeamId.HasValue) { prediction.HomeTeamScore.PenaltyResult = (short)( (command.PenaltyWinnerTeamId == prediction.HomeTeamScore.TeamId) ? 1 : 0); prediction.AwayTeamScore.PenaltyResult = (short)( (command.PenaltyWinnerTeamId == prediction.AwayTeamScore.TeamId) ? 1 : 0); } _dbContext.Add(prediction); } else { prediction.HomeTeamScore.MatchResult = command.HomeMatchResult; prediction.AwayTeamScore.MatchResult = command.AwayMatchResult; prediction.HomeTeamScore.PenaltyResult = null; prediction.AwayTeamScore.PenaltyResult = null; if (command.AwayMatchResult == command.HomeMatchResult && !command.PenaltyWinnerTeamId.HasValue) { return(BadRequest()); } if (command.AwayMatchResult == command.HomeMatchResult && command.PenaltyWinnerTeamId.HasValue) { prediction.HomeTeamScore.PenaltyResult = (short)( (command.PenaltyWinnerTeamId == prediction.HomeTeamScore.TeamId) ? 1 : 0); prediction.AwayTeamScore.PenaltyResult = (short)( (command.PenaltyWinnerTeamId == prediction.AwayTeamScore.TeamId) ? 1 : 0); } } await _dbContext.SaveChangesAsync(); return(Ok()); }