Ejemplo n.º 1
0
 public Assessment(int id, Score score, Dive dive, Referee referee)
     : base(id)
 {
     Point = score;
     DiveId = dive.Id;
     RefereeId = referee.Id;
 }
Ejemplo n.º 2
0
        public static List<Dive> GetAllDiveByCompetitionId(int id)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            var sql = $"SELECT * FROM dive WHERE Competition = {id}";

            using (var sqlConnection = ConnectToDatabase())
            {
                var allDive = new List<Dive>();
                using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                {
                    Logger.Info("Running Query: \"{0}\"", sql);

                    var tableReader = sqlQuery.ExecuteReader();
                    while (tableReader.Read())
                    {
                        var dive = new Dive(
                            tableReader.GetInt32("ID"),
                            tableReader.GetFloat("Totalpoints"),
                            tableReader.GetInt32("diveOrder"),
                            tableReader.GetInt32("Diver"),
                            tableReader.GetInt32("Competition"),
                            GetDiveType(tableReader.GetString("Divetype"))
                            );
                        dive.Assessments = GetAssessments(dive.Id);
                        allDive.Add(dive);
                    }
                }

                Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
                return allDive;
            }
        }
Ejemplo n.º 3
0
        public void TestCalculateCompetitionPoints()
        {
            var diver = new Diver(3, "Johan", "Sweden", 23, "Man", 365);
            var dive1 = new Dive(1, 3.6f, 0, 1, diver.DiverId);
            var dive2 = new Dive(1, 6.2f, 0, 2, diver.DiverId);
            var dive3 = new Dive(1, 1.2f, 0, 3, diver.DiverId);
            var dive4 = new Dive(1, 3.0f, 0, 4, diver.DiverId);
            var dive5 = new Dive(1, 4.7f, 0, 5, diver.DiverId);
            diver.AddDive(dive1);
            diver.AddDive(dive2);
            diver.AddDive(dive3);
            diver.AddDive(dive4);
            diver.AddDive(dive5);

            Assert.AreEqual(5, diver.ListDive.Count);

            var score1 = new Score(5.5f);
            var score2 = new Score(2.5f);
            var score3 = new Score(8.0f);
            var score4 = new Score(5.0f);
            var score5 = new Score(2.5f);

            var allRefScores = new List<Score> { score1, score2, score3, score4, score5 };

            diver.ListDive[0].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[0].Type.Difficulty);
            diver.ListDive[1].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[1].Type.Difficulty);
            diver.ListDive[2].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[2].Type.Difficulty);
            diver.ListDive[3].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[3].Type.Difficulty);
            diver.ListDive[4].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[4].Type.Difficulty);

            diver.SummarizeDivePoints();

            //Assert.AreEqual(243.1, Math.Round(diver._competitionScore, 2));
        }
Ejemplo n.º 4
0
 public void AssessDive(Score score, Dive dive)
 {
     //Console.WriteLine($"Give points to dive {dive.DiveCode} by {dive.DiverId}");
     //var score = AddRefereeScore();
     var assessment = new Assessment(score, dive, this);
     var str = ClientNetworkHandler.SendAndReceive(assessment);
     //Console.WriteLine(str);
 }
Ejemplo n.º 5
0
        public void TestCreateDiver()
        {
            var diver = new Diver(3, "Johan", "Sweden", 23, "Man", 365);
            var dive1 = new Dive(1, 3.6f, 0, 1, diver.DiverId);
            var dive2 = new Dive(1, 6.2f, 0, 2, diver.DiverId);
            var dive3 = new Dive(1, 1.2f, 0, 3, diver.DiverId);
            var dive4 = new Dive(1, 3.0f, 0, 4, diver.DiverId);
            var dive5 = new Dive(1, 4.7f, 0, 5, diver.DiverId);
            diver.AddDive(dive1);
            diver.AddDive(dive2);
            diver.AddDive(dive3);
            diver.AddDive(dive4);
            diver.AddDive(dive5);

            Assert.AreEqual(5, diver.ListDive.Count);
        }
Ejemplo n.º 6
0
        public void TestCalculateTotalPoints()
        {
            var dive = new Dive(1, new DiveType(1, "100a", 1.5f), -1, 4, 3);
            Assert.AreEqual(dive.TotalPoints.Value, -1.0f);

            for (var i = 0; i < 5; i++)
            {
                var assessment = new Assessment(i, new Score(5.0f + i), dive, new Referee());
                dive.Assessments.Add(assessment);
            }

            Assert.IsNotEmpty(dive.Assessments);
            Assert.AreEqual(dive.Assessments.Count, 5);

            var scores = dive.Assessments.Select(assessment => assessment.Point).ToList();

            dive.TotalPoints.CalculateCompleteScore(scores, dive.Type.Difficulty);

            /* Points in assessment-list
             5, 6, 7, 8, 9 -> lowest(5) and highest(9) gets removed. Left: 6, 7, 8.
             Totalpoints = 6 + 7 + 8 * 1.5f = 31.5 points
             */
            Assert.AreEqual(dive.TotalPoints.Value, 31.5f);
        }
Ejemplo n.º 7
0
        public void TestFullCompetition()
        {
            var competitionObject = new Competition(1, "Örebro Mästerskapen", "20160217", "Örebro", "DM", 3);

            var diver = new Diver(4, "Klas", "Uganda", 59, "Man", 3);
            var diver2 = new Diver(5, "Susanna", "Sweden", 27, "Kvinna", 12);
            var diver3 = new Diver(2, "Klas-Göran", "Sweden", 22, "Man", 321);
            competitionObject.AddDiver(diver);
            competitionObject.AddDiver(diver2);
            competitionObject.AddDiver(diver3);

            Assert.AreEqual(3, competitionObject.ListDiver.Count);

            var dive1 = new Dive(1, 3.6f, 0, 1, diver.DiverId);
            var dive2 = new Dive(2, 6.2f, 0, 2, diver.DiverId);
            var dive3 = new Dive(3, 1.2f, 0, 3, diver.DiverId);
            diver.AddDive(dive1);
            diver.AddDive(dive2);
            diver.AddDive(dive3);

            var dive4 = new Dive(4, 2.6f, 0, 1, diver2.DiverId);
            var dive5 = new Dive(5, 3.7f, 0, 2, diver2.DiverId);
            var dive6 = new Dive(6, 9.2f, 0, 3, diver2.DiverId);
            diver2.AddDive(dive4);
            diver2.AddDive(dive5);
            diver2.AddDive(dive6);

            var dive7 = new Dive(7, 4.9f, 0, 1, diver3.DiverId);
            var dive8 = new Dive(8, 6.2f, 0, 2, diver3.DiverId);
            var dive9 = new Dive(9, 1.2f, 0, 3, diver3.DiverId);
            diver3.AddDive(dive7);
            diver3.AddDive(dive8);
            diver3.AddDive(dive9);

            if (competitionObject.CheckIfSameAmountOfDives())
            {
                var allRefScores = new List<Score>();
                var score1 = new Score(5.5f);
                var score2 = new Score(2.5f);
                var score3 = new Score(8.0f);
                var score4 = new Score(5.0f);
                var score5 = new Score(2.5f);
                allRefScores.Add(score1);
                allRefScores.Add(score2);
                allRefScores.Add(score3);
                allRefScores.Add(score4);
                allRefScores.Add(score5);
                for (var i = 0; i < competitionObject.Rounds; i++)
                {
                    foreach (var contestant in competitionObject.ListDiver)
                    {
                        contestant.ListDive[i].TotalPoints.CalculateCompleteScore(allRefScores, contestant.ListDive[i].Type.Difficulty);
                    }
                }
                foreach (var contestant in competitionObject.ListDiver)
                {
                    contestant.SummarizeDivePoints();
                }
                Assert.AreEqual("Susanna", competitionObject.GetWinner());
            }
        }
Ejemplo n.º 8
0
 private static void AddDives(Diver tempDiver, int rounds)
 {
     WriteLine("Enter details of dives for {0}:", tempDiver.Name);
     for (var i = 1; i <= rounds; i++)
     {
         var dive = new Dive();
         WriteLine($"Dive number {i}:");
         WriteLine("Dive code: ");
         dive.Type.Code = ReadLine();
         try
         {
             if (!tempDiver.ListDive.Contains(dive))
                 tempDiver.AddDive(dive);
             else
             {
                 i--;
                 throw new ListObjectAlreadyExistsException("Dive already added!");
             }
         }
         catch (ListObjectAlreadyExistsException e)
         {
             WriteLine(e.Message);
         }
     }
     TempCompetition.AddDiver(tempDiver);
     WriteLine("Diver {0} added!", tempDiver.Name);
     Thread.Sleep(2000);
 }
Ejemplo n.º 9
0
        public static void UpdateDiveTotalPoints(Dive dive)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            const string sql = "UPDATE dive set TotalPoints = @totalpoints WHERE id = @id";
            using (var sqlConnection = ConnectToDatabase())
            {
                int result;
                using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                {
                    Logger.Info("Running Query: \"{0}\"", sql);

                    sqlQuery.Parameters.AddWithValue("@id", dive.Id);
                    sqlQuery.Parameters.AddWithValue("@totalpoints", dive.TotalPoints.Value);

                    result = sqlQuery.ExecuteNonQuery();
                    Logger.Info("{0} rows affected", result);
                }
                Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
            }
        }
Ejemplo n.º 10
0
        public static Dive GetDive(int id)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            var sql = $"SELECT * FROM dive WHERE id = {id}";

            using (var sqlConnection = ConnectToDatabase())
            {
                var dive = new Dive();
                using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                {
                    Logger.Info("Running Query: \"{0}\"", sql);

                    var tableReader = sqlQuery.ExecuteReader();
                    while (tableReader.Read())
                    {
                        var tempDive = new Dive(
                            tableReader.GetInt32("ID"),
                            GetDiveType(tableReader.GetString("Divetype")),
                            tableReader.GetFloat("TotalPoints"),
                            tableReader.GetInt32("DiveOrder"),
                            tableReader.GetInt32("Diver"));
                        dive = tempDive;
                    }
                }
                dive.Assessments = GetAssessments(dive.Id);
                Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
                return dive;
            }
        }
Ejemplo n.º 11
0
        private void SendOutDives(object tDives)
        {
            var divesCount = ((List<Dive>)tDives).Count;
            for (var index = 0; index < divesCount; index++)
            {
                var dive = ((List<Dive>)tDives)[index];
                Console.WriteLine("Press enter to begin dive {0}", dive.Id);
                Console.ReadLine();
                var msg = SendToServer(dive);
                Console.WriteLine(msg);
                while (true)
                {
                    var statusMessage = SendToServer("IsCurrentDiveDone");
                    if (statusMessage != null && CurrentDive != (Dive)statusMessage)
                    {
                        CurrentDive = (Dive)statusMessage;
                        if (CurrentDive.Assessments.Count == 1)
                        {
                            break;
                        }
                    }

                    Thread.Sleep(3000);
                }
            }

            var completemsg = SendToServer("CompetitionComplete");
            Console.WriteLine(completemsg);
        }
Ejemplo n.º 12
0
 public static void SetCurrentDive(Dive dive)
 {
     CurrentDive = dive;
 }
Ejemplo n.º 13
0
 /// <summary>
 ///     Lägger till ett hopp för dykaren
 /// </summary>
 /// <param name="dive"></param>
 public void AddDive(Dive dive)
 {
     ListDive.Add(dive);
 }
Ejemplo n.º 14
0
 public Assessment(Score score, Dive dive, Referee referee)
 {
     this.Point = score;
     this.DiveId = dive.Id;
     this.RefereeId = referee.Id;
 }
Ejemplo n.º 15
0
 private void OnEventClickSendButton(object sender, EventArgs e)
 {
     try
     {
         if (RefereeAssessment.refScoreTextBox.Text.Length == 0)
             throw new FormatException();
         var dialogResult = MessageBox.Show(
             $"Skicka {RefereeAssessment.refScoreTextBox.Text} poäng?",
                 "Skicka poäng", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             var refScore = RefereeAssessment.refScoreTextBox.Text;
             var judgeScore = float.Parse(refScore, CultureInfo.InvariantCulture.NumberFormat);
             var score = new Score(judgeScore);
             var dive = new Dive();
             var assessment = new Assessment(score, dive, LoggedInUser);
             var str = ClientNetworkHandler.SendAndReceive(assessment);
             MessageBox.Show($"{judgeScore} poäng skickad", "Meddelande");
         }
     }
     catch (FormatException)
     {
         ErrorMessageBox("Ogiltig inmatning", "Ange poäng!");
     }
     RefereeAssessment.RefSendScoreButton.Enabled = false;
     var tDive = WaitForDiveToJudge();
     RefereeAssessment.RefereeCurrentDiveInfoLabel.Text = tDive.ToString();
     SystemSounds.Beep.Play();
     RefereeAssessment.RefSendScoreButton.Enabled = true;
 }
Ejemplo n.º 16
0
 public void AddDivetoDiver(Diver diver, Dive dive)
 {
     foreach (var dvr in ListDiver.Where(dvr => dvr == diver))
     {
         dvr.AddDive(dive);
         break;
     }
 }