Exemplo n.º 1
0
        private string GetFormulaString(ScoreCode codeDef)
        {
            var returnString = new StringBuilder();

            switch (codeDef.Formula.ToUpperInvariant())
            {
            case "COD":
                returnString.Append($"Scored like {codeDef.ScoreLike}");
                break;

            case "FIN+":
                returnString.Append("Number of boats that finished race");
                returnString.Append(GetNumberIfExists(codeDef));
                break;

            case "SER+":
                returnString.Append("Number of boats entered in series");
                returnString.Append(GetNumberIfExists(codeDef));
                break;

            case "CTS+":
                returnString.Append("Number of boats that came to starting area");
                returnString.Append(GetNumberIfExists(codeDef));
                break;

            case "AVE":
                returnString.Append("Average of results");
                break;

            case "AVE ND":
                returnString.Append("Average of non-discarded results");
                break;

            case "AVE P":
                returnString.Append("Average of results in prior races");
                break;

            case "PLC%":
                returnString.Append($"Place + penalty ({codeDef.FormulaValue}% of DNF score)");
                break;

            case "MAN":
                returnString.Append($"Manually entered value");
                break;

            case "FIX":
                returnString.Append($"Fixed at {codeDef.FormulaValue}");
                break;

            case "TIE":
                returnString.Append($"Average of tied places");
                break;
            }

            if (!(codeDef.Discardable ?? true))
            {
                returnString.Append("; not excludable");
            }
            return(returnString.ToString());
        }
Exemplo n.º 2
0
        private static string GetScoreCodeValue(ScoreCode code)
        {
            // 17 pipe separated values
            //"RET|Score like|DNF|Yes|Yes||spare|spare|spare|spare|spare|Yes|No|No|5||Retired"
            string spare = "spare";

            var strings = new List <string>();

            strings.Add(code.Code);  // 0
            strings.Add(code.Method);
            strings.Add(code.Value);
            strings.Add(Utilities.BoolToYesNo(code.Discardable));
            strings.Add(Utilities.BoolToYesNo(code.CameToStartArea)); //4
            strings.Add(string.Empty);
            strings.Add(spare);
            strings.Add(spare);
            strings.Add(spare);//8
            strings.Add(spare);
            strings.Add(spare);
            strings.Add(Utilities.BoolToYesNo(code.Started)); // 11
            strings.Add(Utilities.BoolToYesNo(code.Finished));
            strings.Add(Utilities.BoolToYesNo(code.RuleA6d2Applies));
            strings.Add(code.ScoringSystemId.ToString());
            strings.Add(code.Format);
            strings.Add(code.Description); //16

            return(String.Join("|", strings));
        }
Exemplo n.º 3
0
        private string GetNumberIfExists(ScoreCode codeDef)
        {
            if ((codeDef.FormulaValue ?? 0) == 0)
            {
                return(string.Empty);
            }

            return($" + {codeDef.FormulaValue}");
        }
        protected override decimal?GetPenaltyScore(CalculatedScore score, Race race, ScoreCode scoreCode)
        {
            var dnfScore          = GetDnfScore(race) ?? 0;
            var fleetSize         = race.Scores.Where(s => CameToStart(s)).Count();
            var percentAdjustment = Convert.ToDecimal(scoreCode?.FormulaValue ?? 20);
            var percent           = Math.Round(fleetSize * percentAdjustment / 100m, MidpointRounding.AwayFromZero);

            return(Math.Max(dnfScore, (score.ScoreValue ?? 0) - percent));
        }
Exemplo n.º 5
0
        public static FileRow GetRow(ScoreCode code)
        {
            var returnRow = new FileRow
            {
                Name  = "scrcode",
                Value = GetScoreCodeValue(code)
            };

            return(returnRow);
        }
Exemplo n.º 6
0
        public async Task SaveScoreCodeAsync_NewCode_SavesToDb()
        {
            // Arrange
            var system = await _context.ScoringSystems.FirstAsync();

            var code = new ScoreCode
            {
                Name            = "FIFO",
                ScoringSystemId = system.Id
            };
            // Act
            await _service.SaveScoreCodeAsync(code);

            // Assert
            Assert.Contains(_context.ScoreCodes, sc => sc.Name == "FIFO");
        }
Exemplo n.º 7
0
        public async Task SaveScoreCodeAsync(ScoreCode scoreCode)
        {
            if (scoreCode.Id != default)
            {
                Db.ScoreCode dbObject = await _dbContext
                                        .ScoreCodes
                                        .Where(sc => sc.Id == scoreCode.Id)
                                        .SingleAsync()
                                        .ConfigureAwait(false);

                _mapper.Map(scoreCode, dbObject);
            }
            else
            {
                Db.ScoreCode dbObject = _mapper.Map <Db.ScoreCode>(scoreCode);
                dbObject.Id = Guid.NewGuid();
                _dbContext.ScoreCodes.Add(dbObject);
            }
            await _dbContext.SaveChangesAsync()
            .ConfigureAwait(false);
        }
Exemplo n.º 8
0
        // rows should come in filtered for a single race.
        public static ScoreCode GetCode(FileRow row)
        {
            if (!row.Name.Equals("scrcode", StringComparison.InvariantCultureIgnoreCase))
            {
                return(null);
            }
            ScoreCode code     = new ScoreCode();
            var       elements = row.Value.Split('|');

            code.Code            = elements[0];
            code.Method          = elements[1];
            code.Value           = elements[2];
            code.Discardable     = Utilities.GetBool(elements[3]) ?? false;
            code.CameToStartArea = Utilities.GetBool(elements[4]) ?? false;
            code.Started         = Utilities.GetBool(elements[11]) ?? false;
            code.Finished        = Utilities.GetBool(elements[12]) ?? false;
            code.RuleA6d2Applies = Utilities.GetBool(elements[13]) ?? false;
            code.ScoringSystemId = Utilities.GetInt(elements[14]) ?? 1;
            code.Format          = elements[15];
            code.Description     = elements[16];

            return(code);
        }