public void CalculateTotalScore_5of5_Scored()
        {
            var cont = new RoundContestant();

            cont.EnsureListsAreInitialized();
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 2, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 4, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 6, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 8, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 9, RunNo = 1
            });

            cont.CalculateTotalScore(5, 1);

            Assert.AreEqual(5.8M, cont.TotalScore);
        }
Esempio n. 2
0
        public void RunEquals_RunNoDiffers_false()
        {
            var crit = new JudgingCriterion()
            {
                Id = 5
            };
            var judge = new Judge()
            {
                Id = 8
            };
            var rc = new RoundContestant()
            {
                Id = 7
            };

            var j1 = new RunJudging(rc, judge, crit, 1, 7M);
            var j2 = new RunJudging(rc, judge, crit, 2, 6M);

            j1.Id = 1;
            j2.Id = 2;

            var result = j1.RunEquals(j2);

            Assert.IsFalse(result);
        }
        public void CalculateTotalScore_4of5_notScored()
        {
            var cont = new RoundContestant();

            cont.EnsureListsAreInitialized();
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 5, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 6, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 6, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 5, RunNo = 1
            });

            cont.CalculateTotalScore(5, 1);

            Assert.AreEqual(null, cont.TotalScore);
        }
        /// <summary>
        /// Replaces ALL runJudgings for all contestants represented in the list passed in. Recalculates totals.
        /// This means that if only judgements for 3 of 5 criteria are sent in for a given contestant,
        /// all 5 existing will still be deleted.
        /// </summary>
        public virtual void ReplaceAllRunJudgings(List <RunJudging> list, Tournament tourney)
        {
            var expectedJudgeEntriesPerRun = tourney.GetExpectedJudgementCountPerRun();
            // Delete the ones we're replacing
            var rcIds         = list.Select(p => p.RoundContestantId).Distinct().ToList();
            var oldJudgements = RunJudgings.Where(p => rcIds.Contains(p.RoundContestantId)).ToList();

            foreach (var old in oldJudgements)
            {
                RunJudgings.Remove(old);
            }

            // Insert new ones
            foreach (var score in list)
            {
                RunJudgings.Add(score);
            }

            // Update total score for all round contestants
            foreach (long rcId in rcIds)
            {
                RoundContestant contestant = GetRoundContestantGuarded(rcId);
                contestant.CalculateTotalScore(expectedJudgeEntriesPerRun, contestant.Round.RoundNo, contestant.Round.RunsPerContestant);
            }
            SaveChanges();
        }
        public void CalculateTotalScore_5of5butOneNull_ScoredAndCorrectAverage()
        {
            var cont = new RoundContestant();

            cont.EnsureListsAreInitialized();
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 5, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 6, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 6, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 5, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = null, RunNo = 1
            });

            cont.CalculateTotalScore(5, 1);

            Assert.AreEqual(5.5M, cont.TotalScore);
        }
        public void ReplaceRunJudging_NewItem_Added()
        {
            var crit1 = new JudgingCriterion()
            {
                Id = 5
            };
            var crit2 = new JudgingCriterion()
            {
                Id = 9
            };
            var judge = new Judge()
            {
                Id = 8
            };
            var rc = new RoundContestant()
            {
                Id = 7
            };

            rc.EnsureListsAreInitialized();
            var j1 = new RunJudging()
            {
                Id              = 1,
                Criterion       = crit1,
                Judge           = judge,
                Score           = 7,
                RoundContestant = rc,
                RunNo           = 1
            };

            rc.ReplaceRunJudging(j1);

            Assert.AreEqual(1, rc.RunJudgings.Count);
            Assert.AreSame(j1, rc.RunJudgings.First());
        }
        public void GetRunScore_2runsRun2()
        {
            var cont = new RoundContestant();

            cont.EnsureListsAreInitialized();
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 5, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 10, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 8, RunNo = 2
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 10, RunNo = 2
            });

            var score = cont.GetRunScore(2, 2);

            Assert.AreEqual(9M, score);
        }
        public void IsJudgedBy_Run1Judge2NotExists()
        {
            var j1 = new Judge()
            {
                Id = 1
            };
            var j2 = new Judge()
            {
                Id = 2
            };
            var rc = new RoundContestant()
            {
                Id = 3
            };
            var crit = new JudgingCriterion()
            {
                Id = 6
            };

            rc.EnsureListsAreInitialized();
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 1, Score = 3, Judge = j1, Criterion = crit, JudgeId = j1.Id
            });

            var result = rc.IsJudgedBy(j2, 1, 1);

            Assert.IsFalse(result);
        }
        public void IsJudgedBy_Run1Judge1With2Criteras()
        {
            var j1 = new Judge()
            {
                Id = 1
            };
            var rc = new RoundContestant()
            {
                Id = 3
            };
            var crit1 = new JudgingCriterion()
            {
                Id = 6
            };
            var crit2 = new JudgingCriterion()
            {
                Id = 7
            };

            rc.EnsureListsAreInitialized();
            rc.ReplaceRunJudging(new RunJudging(rc, j1, crit1, 1, 3.0M));
            rc.ReplaceRunJudging(new RunJudging(rc, j1, crit2, 1, 3.0M));

            var result = rc.IsJudgedBy(j1, 1, 2);

            Assert.IsTrue(result);
        }
        public void GetAsRunJudgings_2Scores_MappedCorrectly()
        {
            var inList = new List <RunJudging>();
            var crit1  = new JudgingCriterion()
            {
                Id = 1, Title = "A"
            };
            var crit2 = new JudgingCriterion()
            {
                Id = 2, Title = "B"
            };
            var rc = new RoundContestant {
                Id = 6
            };
            var judge = new Judge {
                Id = 15
            };

            inList.Add(new RunJudging(rc, judge, crit1, 1, 7.5M));
            inList.Add(new RunJudging(rc, judge, crit2, 1, 5.5M));
            var target = new RunJudgementViewModel(inList);

            var result = target.GetAsRunJudgings(new List <JudgingCriterion>()
            {
                crit1, crit2
            });

            Assert.IsTrue(result[0].RunEquals(inList[0]), "0");
            Assert.IsTrue(result[1].RunEquals(inList[1]), "1");
        }
        public void GetScoreFromJudge_Run2_CorrectValue()
        {
            var cont = new RoundContestant();

            cont.EnsureListsAreInitialized();
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 5, RunNo = 1, JudgeId = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = null, RunNo = 1, JudgeId = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 10, RunNo = 1, JudgeId = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 8, RunNo = 1, JudgeId = 2
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 10, RunNo = 2, JudgeId = 1
            });
            var res = cont.GetScoreFromJudgeRun(judgeId: 1L, runNo: 2);

            Assert.AreEqual(10M, res);
        }
Esempio n. 12
0
        public void RunEquals_AllButIdAndScoreEqual_true()
        {
            var crit = new JudgingCriterion()
            {
                Id = 5
            };
            var judge = new Judge()
            {
                Id = 8
            };
            var rc = new RoundContestant()
            {
                Id = 7
            };

            var j1 = new RunJudging(rc, judge, crit, 1, 7M);
            var j2 = new RunJudging(rc, judge, crit, 1, 6M);

            j1.Id = 1;
            j2.Id = 2;

            var result = j1.RunEquals(j2);

            Assert.IsTrue(result);
        }
        public void CalculateTotalScore_2runs_BestRunTaken()
        {
            var cont = new RoundContestant();

            cont.EnsureListsAreInitialized();
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 5, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 10, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 8, RunNo = 2
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 10, RunNo = 2
            });

            cont.CalculateTotalScore(2, 2);

            Assert.AreEqual(9M, cont.TotalScore);
        }
        public void IsJudgedTest_blank_no()
        {
            var rc = new RoundContestant();

            rc.EnsureListsAreInitialized();
            bool result = rc.IsJudged(12);

            Assert.IsFalse(result);
        }
        public void GetScoreFromJudge_NoData_Null()
        {
            var cont = new RoundContestant();

            cont.EnsureListsAreInitialized();
            var res = cont.GetScoreFromJudgeRun(0, 0);

            Assert.IsNull(res);
        }
        public virtual RoundContestant GetRoundContestantGuarded(long roundContestantId)
        {
            RoundContestant contestant = RoundContestants.FirstOrDefault(p => p.Id == roundContestantId);

            if (contestant == null)
            {
                throw new ArgumentException(String.Format("Could not find RoundContestant with ID {0}", roundContestantId));
            }
            return(contestant);
        }
        /// <summary>
        /// Replaces list of runJudging scores as well as calculates total on RoundContestant if done.
        /// Less optimized than ReplaceRunJudgings(ContestantRunViewModel model), as it fetches roundContestant for each runJudging line
        /// </summary>
        public virtual void ReplaceRunJudgings(List <RunJudging> list, Tournament tourney)
        {
            var expectedJudgeEntriesPerRun = tourney.GetExpectedJudgementCountPerRun();

            foreach (var score in list)
            {
                RunJudgings.Replace(score);
                RoundContestant contestant = GetRoundContestantGuarded(score.RoundContestantId);
                contestant.CalculateTotalScore(expectedJudgeEntriesPerRun, contestant.Round.RunsPerContestant);
            }
            SaveChanges();
        }
        public void GetRunScore_NullJudgement_NullAvgScore()
        {
            var cont = new RoundContestant();

            cont.EnsureListsAreInitialized();
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = null, RunNo = 1
            });
            var result = cont.GetRunScore(1, 1);

            Assert.IsNull(result);
        }
        /// <summary>
        /// Replaces list of runJudging scores for a single round consteants. Calculates total on RoundContestant if all scores registerd.
        /// </summary>
        public virtual void ReplaceRunJudgings(long tournamentId, long roundContestantId, List <RunJudging> runJudgings)
        {
            Tournament      tourney    = GetTournamentGuarded(tournamentId);
            RoundContestant contestant = GetRoundContestantGuarded(roundContestantId);

            foreach (var score in runJudgings)
            {
                RunJudgings.Replace(score);
            }
            var expectedJudgeEntriesPerRun = tourney.GetExpectedJudgementCountPerRun();

            contestant.CalculateTotalScore(expectedJudgeEntriesPerRun, contestant.Round.RoundNo, contestant.Round.RunsPerContestant);
            SaveChanges();
        }
        /// <summary>
        /// Replaces list of runJudging scores as well as calculates total on RoundContestant if done
        /// </summary>
        /// <param name="model"></param>
        public virtual void ReplaceRunJudgings(ContestantRunViewModel model)
        {
            Tournament      tourney    = GetTournamentGuarded(model.TournamentId);
            RoundContestant contestant = GetRoundContestantGuarded(model.RoundContestantId);

            foreach (var score in model.Scores)
            {
                RunJudgings.Replace(score);
            }
            var expectedJudgeEntriesPerRun = tourney.GetExpectedJudgementCountPerRun();

            contestant.CalculateTotalScore(expectedJudgeEntriesPerRun, contestant.Round.RunsPerContestant);
            SaveChanges();
        }
        /// Not allowing this to be called directly since it may result in database access
        public ContestantRoundResultViewModel(RoundContestant rc)
        {
            RunScore   = new List <decimal?>();
            Name       = rc.Contestant.Name;
            TotalScore = rc.TotalScore;
            if (rc.Round == null || rc.Round.Tournament == null)
            {
                throw new ArgumentException("Navigation properties Round and Tournament must be set on roundContestant");
            }
            var round   = rc.Round;
            var tourney = round.Tournament;
            int expectedJudgementCountPerRun = tourney.GetExpectedJudgementCountPerRun();

            RunScore = rc.GetRunScores(expectedJudgementCountPerRun, round.RunsPerContestant);
        }
Esempio n. 22
0
 public static Round WithContestants(this Round round, int count, bool withTotalScore)
 {
     round.ContestantEntries = new HashSet <RoundContestant>();
     for (int i = 0; i < count; i++)
     {
         var contestant = new Contestant("C" + i);
         var rc         = new RoundContestant  {
             Contestant = contestant,
             Round      = round,
             TotalScore = withTotalScore ? (decimal?)i : null
         };
         round.ContestantEntries.Add(rc);
         rc.EnsureListsAreInitialized();
     }
     return(round);
 }
        public void IsJudgedTest_3by2yields6withOneNullScore_true()
        {
            var j1 = new Judge()
            {
                Id = 1
            };
            var j2 = new Judge()
            {
                Id = 2
            };
            var rc = new RoundContestant()
            {
                Id = 3
            };
            var crit = new JudgingCriterion()
            {
                Id = 6
            };

            rc.EnsureListsAreInitialized();
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 1, Score = 3, Judge = j1, Criterion = crit
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 1, Score = 3, Judge = j2, Criterion = crit
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 2, Score = 4, Judge = j1, Criterion = crit
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 2, Score = null, Judge = j2, Criterion = crit
            }.SetIdFromObjects());                                                                                                                   // Null score = concious "no score"-mark
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 3, Score = 5, Judge = j1, Criterion = crit
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 3, Score = 1, Judge = j2, Criterion = crit
            }.SetIdFromObjects());
            foreach (var rj in rc.RunJudgings)
            {
                rj.SetIdFromObjects();
            }
            bool result = rc.IsJudged(6);

            Assert.IsTrue(result);
        }
        public void CalculateTotalScore_2of2_Scored()
        {
            var cont = new RoundContestant();

            cont.EnsureListsAreInitialized();
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 5, RunNo = 1
            });
            cont.RunJudgings.Add(new RunJudging()
            {
                Score = 10, RunNo = 1
            });

            cont.CalculateTotalScore(2, 1);

            Assert.AreEqual(7.5M, cont.TotalScore);
        }
        public void IsJudgedTest_1by2butonly1_true()
        {
            var j1 = new Judge()
            {
                Id = 7
            };
            var rc = new RoundContestant()
            {
                Id = 5
            };

            rc.EnsureListsAreInitialized();
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 1, Score = 3, Judge = j1
            });
            bool result = rc.IsJudged(1);

            Assert.IsTrue(result);
        }
        public void IsJudgedTest_OnlyOneOfTwoCriterion_false()
        {
            var j1 = new Judge()
            {
                Id = 4
            };
            var j2 = new Judge()
            {
                Id = 1
            };
            var rc = new RoundContestant()
            {
                Id = 7
            };
            var crit = new JudgingCriterion()
            {
                Id = 65
            };

            rc.EnsureListsAreInitialized();
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 1, Score = 3, Judge = j1, Criterion = crit
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 1, Score = 3, Judge = j2, Criterion = crit
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 2, Score = 4, Judge = j1, Criterion = crit
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 2, Score = 5, Judge = j2, Criterion = crit
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 3, Score = 5, Judge = j1, Criterion = crit
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 3, Score = 1, Judge = j2, Criterion = crit
            }.SetIdFromObjects());
            bool result = rc.IsJudged(12);

            Assert.IsFalse(result);
        }
        public RunJudgementViewModel(List <RunJudging> runJudgings, NordicArenaDomainModels.Models.Judge judge = null, RoundContestant roundContestant = null, int?runNo = null)
            : this()
        {
            if ((roundContestant == null || runNo == null || judge == null) && (runJudgings == null || runJudgings.Count == 0))
            {
                throw new ArgumentException("No entries in list or list null, while not supplied judge, roundContestant and runNo explicitly");
            }
            if (roundContestant == null)
            {
                roundContestant = runJudgings[0].RoundContestant;
            }
            if (runNo == null)
            {
                runNo = runJudgings[0].RunNo;
            }
            if (judge == null)
            {
                judge = runJudgings[0].Judge;
            }

            ContestantName    = roundContestant.Contestant != null ? roundContestant.Contestant.Name : "(not set)";
            RunNo             = runNo.Value;
            JudgeName         = judge.Name;
            RoundContestantId = roundContestant.Id;
            JudgeId           = judge.Id;
            RunJudgeScore     = roundContestant.GetScoreFromJudgeRun(judge.Id, runNo.Value);
            foreach (var rj in runJudgings)
            {
                if (rj.RunNo != runNo)
                {
                    throw new ArgumentException(String.Format("Expected all runJudgements to be from run {0}, but one is from run {1}", runNo, rj.RunNo));
                }
                if (rj.RoundContestantId != roundContestant.Id)
                {
                    throw new ArgumentException(String.Format("Expected all runJudgements to be from roundContestantId {0}, but one is from {1}", roundContestant.Id, rj.RoundContestantId));
                }
                if (rj.JudgeId != judge.Id)
                {
                    throw new ArgumentException(String.Format("Expected all runJudgements to be from judgeId {0}, but one is from {1}", judge.Id, rj.JudgeId));
                }
                Scores.Add(rj.Score);
            }
        }
Esempio n. 28
0
 public NextContestantViewModel(RoundContestant rc)
 {
     Name       = rc.Contestant.Name;
     Contestant = rc.Contestant;
     TotalScore = rc.TotalScore;
 }
        public void IsJudgedTest_3by2by2_true()
        {
            var c1 = new JudgingCriterion()
            {
                Id = 7
            };
            var c2 = new JudgingCriterion()
            {
                Id = 8
            };
            var j1 = new Judge()
            {
                Id = 1
            };
            var j2 = new Judge()
            {
                Id = 2
            };
            var rc = new RoundContestant()
            {
                Id = 10
            };

            rc.EnsureListsAreInitialized();
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 1, Score = 3, Judge = j1, Criterion = c1
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 1, Score = 3, Judge = j2, Criterion = c1
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 2, Score = 4, Judge = j1, Criterion = c1
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 2, Score = 5, Judge = j2, Criterion = c1
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 3, Score = 5, Judge = j1, Criterion = c1
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 3, Score = 1, Judge = j2, Criterion = c1
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 1, Score = 3, Judge = j1, Criterion = c2
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 1, Score = 3, Judge = j2, Criterion = c2
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 2, Score = 4, Judge = j1, Criterion = c2
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 2, Score = 5, Judge = j2, Criterion = c2
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 3, Score = 5, Judge = j1, Criterion = c2
            }.SetIdFromObjects());
            rc.ReplaceRunJudging(new RunJudging {
                RoundContestant = rc, RunNo = 3, Score = 1, Judge = j2, Criterion = c2
            }.SetIdFromObjects());
            foreach (var rj in rc.RunJudgings)
            {
                rj.SetIdFromObjects();
            }
            bool result = rc.IsJudged(12);

            Assert.IsTrue(result);
        }
Esempio n. 30
0
        internal static List <JudgeHasScoredTuple> GetJudgeStatusListFor(Tournament t, RoundContestant rc, int runNo)
        {
            var list = new List <JudgeHasScoredTuple>();

            if (rc != null)
            {
                int criteriaCount = t.JudgingCriteria.Count;
                foreach (var judge in t.Judges)
                {
                    var tuplet = new JudgeHasScoredTuple();
                    tuplet.JudgeName = judge.Name;
                    tuplet.HasJudged = rc.IsJudgedBy(judge, runNo, criteriaCount);
                    list.Add(tuplet);
                }
            }
            return(list);
        }