public static decimal SumValues(QBRRequest request) { decimal passAttempts = request.PassesAttempted; decimal first = WeightedValueCpA(request.PassesCompleted, passAttempts); decimal second = WeightedValueAYGpA(request.PassingYards, passAttempts); decimal third = WeightedValueTDP(request.TouchdownPasses, passAttempts); decimal fourth = WeightedValueInterceptions(request.Interceptions, passAttempts); decimal QBR = (first + second + third + fourth) / 6 * 100; return(Math.Round(QBR, 1)); }
public static QBRResponse CalculateQBR(QBRRequest request) { QBRResponse response = InputValidation.VaidateStats(request); if (response.ValidInput) { response.Name = request.Name; response.Rating = SumValues(request); response.Message = $"{response.Name}'s QB Rating is: {response.Rating}"; return(response); } else { return(response); } }
public static QBRResponse VaidateStats(QBRRequest request) { QBRResponse response = new QBRResponse(); if (request.PassesCompleted < 0 || request.PassesAttempted < 0 || request.TouchdownPasses < 0 || request.Interceptions < 0) { response.Message = "QB stats cannot be negative (with the exception of passing yards)."; response.ValidInput = false; return(response); } if (request.PassesAttempted == 0) { response.Message = "QB Rating is undefined for players with zero pass attempts."; response.ValidInput = false; return(response); } if (request.PassesCompleted > request.PassesAttempted) { response.Message = "Passes completed must be less than or equal to passes attempted."; response.ValidInput = false; return(response); } if (request.TouchdownPasses > request.PassesCompleted) { response.Message = "Touchdowns must be less than or equal to completions."; response.ValidInput = false; return(response); } if (request.Interceptions > request.PassesAttempted - request.PassesCompleted) { response.Message = "Interceptions must be less than or equal to the number of incompletions"; response.ValidInput = false; return(response); } if (request.TouchdownPasses + request.Interceptions >= request.PassesAttempted) { response.Message = "Touchdown passes plus interceptions must be less than passes attempted."; response.ValidInput = false; return(response); } response.ValidInput = true; return(response); }