Beispiel #1
0
        public static PushUpStats GetPushUpSumAndElo(long userID)
        {
            using var conSelect = new NpgsqlConnection(ConnectionString);
            conSelect.Open();

            string sqlSelect = $"SELECT SUM(count) FROM SEB_History WHERE userID = '{userID}'";

            using var cmdSelect = new NpgsqlCommand(sqlSelect, conSelect);

            long PushUpSum;

            if ((cmdSelect.ExecuteScalar() == DBNull.Value) || (cmdSelect.ExecuteScalar() == null))
            {
                PushUpSum = 0;
            }
            else
            {
                PushUpSum = (long)cmdSelect.ExecuteScalar();
            }
            conSelect.Close();

            using var conSelect2 = new NpgsqlConnection(ConnectionString);
            conSelect2.Open();

            string sqlSelect2 = $"SELECT elo FROM SEB_users WHERE userID = '{userID}'";

            using var cmdSelect2 = new NpgsqlCommand(sqlSelect2, conSelect2);

            int ELO;

            if ((cmdSelect2.ExecuteScalar() == DBNull.Value) || (cmdSelect2.ExecuteScalar() == null))
            {
                return(null);
            }
            else
            {
                ELO = (int)cmdSelect2.ExecuteScalar();
            }
            conSelect2.Close();

            var tmpObject = new PushUpStats((int)userID, PushUpSum, ELO);

            return(tmpObject);
        }
Beispiel #2
0
        public static void IncreaseELOafterTournament()
        {
            using var conSelect = new NpgsqlConnection(ConnectionString);
            conSelect.Open();

            string sqlSelect = $"SELECT SEB_users.userid, SUM(count) as count, elo  FROM SEB_History INNER JOIN SEB_Users ON SEB_History.userID = SEB_Users.userID WHERE tournamentID = (SELECT MAX(tournamentID) FROM SEB_History) GROUP BY SEB_users.userid";

            using var cmdSelect = new NpgsqlCommand(sqlSelect, conSelect);

            using var reader = cmdSelect.ExecuteReader();

            var ParticipantList = new List <PushUpStats>();

            while (reader.Read())
            {
                int tempUserID = reader.GetInt32(reader.GetOrdinal("userid"));
                int tempCount  = reader.GetInt32(reader.GetOrdinal("count"));
                int tempELO    = reader.GetInt32(reader.GetOrdinal("elo"));

                var tempObject = new PushUpStats(tempUserID, tempCount, tempELO);
                ParticipantList.Add(tempObject);
            }

            var WinnerList = new List <PushUpStats>();

            WinnerList.Add(ParticipantList[0]);

            bool firstIteration = true;

            foreach (var Participant in ParticipantList)
            {
                if (!firstIteration)
                {
                    if (Participant.Count == WinnerList[0].Count)
                    {
                        WinnerList.Add(Participant);
                    }

                    if (Participant.Count > WinnerList[0].Count)
                    {
                        WinnerList.Clear();
                        WinnerList.Add(Participant);
                    }
                }
                else
                {
                    firstIteration = false;
                }
            }



            foreach (var Participant in WinnerList)
            {
                ParticipantList.Remove(Participant);
            }

            if (WinnerList.Count() > 1)
            {
                foreach (var Participant in WinnerList)
                {
                    Participant.ELO += 1;
                }
            }
            else if (WinnerList.Count() == 1)
            {
                WinnerList[0].ELO += 2;
            }

            foreach (var Participant in ParticipantList)
            {
                Participant.ELO -= 1;
            }

            updateELO(WinnerList, ParticipantList);
        }