private void doRanking(int roundNumber)
        {
            DataRow[] foundRows          = m_computedScoresTable.Select("", "Score_After_Round_" + roundNumber + " DESC, Tiebreaker_After_Round_" + roundNumber + " DESC");
            int       rank               = 1;
            double    previousValue      = 0;
            double    previousTiebreaker = 0;
            string    rankColumnName     = "Rank_After_Round_" + roundNumber;
            int       count              = 0;

            for (int i = 0; i < foundRows.Length; ++i)
            {
                DataRow dRow = foundRows[i];
                if (LocalUtilities.hasWithdrawn(m_databaseFileName, getIntValue(dRow, "Team_Number"), roundNumber))
                {
                    dRow[rankColumnName] = -1;
                }
                else
                {
                    double currentValue      = getDoubleValue(dRow, "Score_After_Round_" + roundNumber);
                    double currentTiebreaker = getDoubleValue(dRow, "Tiebreaker_After_Round_" + roundNumber);
                    if (count > 0 && (currentValue != previousValue || currentTiebreaker != previousTiebreaker))
                    {
                        rank = count + 1;
                    }
                    previousValue        = currentValue;
                    previousTiebreaker   = currentTiebreaker;
                    dRow[rankColumnName] = rank;
                    count++;
                }
            }
        }
示例#2
0
        private void knockoutScoresDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv              = sender as DataGridView;
            string       columnName       = dgv.Columns[e.ColumnIndex].Name;
            int          roundNumber      = knockoutRoundsCombobox.SelectedIndex + 1;
            DataTable    sessionsTable    = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.KnockoutSessions);
            DataRow      dRow             = sessionsTable.Rows.Find(roundNumber);
            int          numberOfSessions = (int)dRow["Number_Of_Sessions"];

            if (columnName.Contains("Session") || columnName == "Carryover")
            {
                double total = 0;
                Object value = dgv.Rows[e.RowIndex].Cells["Carryover"].Value;
                total += (value == DBNull.Value) ? 0 : (double)value;
                for (int i = 1; i <= numberOfSessions; ++i)
                {
                    value  = dgv.Rows[e.RowIndex].Cells["Session_" + i + "_Score"].Value;
                    total += (value == DBNull.Value) ? 0 : (double)value;
                }
                dgv.Rows[e.RowIndex].Cells["Total"].Value = total;
            }
            else if (columnName == "Team_Number")
            {
                dgv.Rows[e.RowIndex].Cells["Team_Name"].Value = LocalUtilities.getTeamName(m_databaseFileName, Constants.TableName.KnockoutTeams, (int)dgv.Rows[e.RowIndex].Cells["Team_Number"].Value);
            }
        }
        private void getTeamsScoreWise()
        {
            string sort = "Rank_After_Round_" + m_scoreRoundNumber + " ASC, Tiebreaker_After_Round_" + m_scoreRoundNumber + " DESC";

            DataRow[] dRows = m_computedScoresTable.Select("", sort);
            int       count = 0;

            foreach (DataRow dRow in dRows)
            {
                int team = AccessDatabaseUtilities.getIntValue(dRow, "Team_Number");
                if (!LocalUtilities.hasWithdrawn(m_databaseFileName, team, m_drawRoundNumber))
                {
                    count++;
                }
            }
            m_teamNumber    = new int[count + 1];
            m_teamNumber[0] = 0;
            m_assigned      = new bool[count + 1];
            count           = 1;
            foreach (DataRow dRow in dRows)
            {
                int team = AccessDatabaseUtilities.getIntValue(dRow, "Team_Number");
                if (!LocalUtilities.hasWithdrawn(m_databaseFileName, team, m_drawRoundNumber))
                {
                    m_teamNumber[count] = team;
                    m_assigned[count]   = false;
                    count++;
                }
            }
        }
        private void createDraw()
        {
            m_numberOfTeamsLeft       = LocalUtilities.teamsLeft(m_databaseFileName, m_drawRoundNumber);
            m_numberOfTeamsOriginal   = m_swissTeamEventInfo.NumberOfTeams;
            m_numberOfMatchesLeft     = (m_numberOfTeamsLeft / 2) + m_numberOfTeamsLeft % 2;
            m_numberOfMatchesOriginal = (m_numberOfTeamsOriginal / 2) + m_numberOfTeamsOriginal % 2;
            string filter = "Round_Number = " + m_drawRoundNumber;
            string sort   = "Table_Number ASC";

            m_dataRows = m_scoresTable.Select(filter, sort);
            Debug.Assert(m_dataRows.Length == m_numberOfMatchesOriginal, "Number of matches for round number " + m_drawRoundNumber + " is " + m_dataRows.Length + " but it should be " + m_numberOfMatchesOriginal);
            assignLeftTeams();
            assignWithDrawnTeams();
        }
        private void createRoundScoresTable(int roundNumber)
        {
            List <DatabaseField> fields = new List <DatabaseField>();

            fields.Add(new DatabaseField("Match_Number", "INTEGER"));
            fields.Add(new DatabaseField("Team_Number", "INTEGER"));
            fields.Add(new DatabaseField("Team_Name", "TEXT", 255));
            fields.Add(new DatabaseField("Carryover", "NUMBER"));
            fields.Add(new DatabaseField("Total", "NUMBER"));
            DataTable table            = AccessDatabaseUtilities.getDataTable(m_databaseFileName, Constants.TableName.KnockoutSessions);
            DataRow   dRow             = table.Rows.Find(roundNumber);
            int       numberOfSessions = (int)dRow["Number_Of_Sessions"];

            m_oldNumberOfSessions[roundNumber] = numberOfSessions;
            for (int i = 1; i <= numberOfSessions; ++i)
            {
                fields.Add(new DatabaseField("Session_" + i + "_Score", "NUMBER"));
            }
            List <string> primaryKeys = new List <string>();

            primaryKeys.Add("Match_Number");
            primaryKeys.Add("Team_Number");
            DataTable scoresTable     = AccessDatabaseUtilities.createTable(m_databaseFileName, Constants.TableName.KnockoutScores + "_" + roundNumber, fields, primaryKeys);
            int       numberOfMatches = Convert.ToInt32(Math.Pow(2, roundNumber - 1));

            for (int i = 1; i <= numberOfMatches; ++i)
            {
                DataRow dScoresRow = scoresTable.NewRow();
                dScoresRow["Match_Number"] = i;
                int teamNumber = i;
                dScoresRow["Team_Number"] = i;
                dScoresRow["Team_Name"]   = LocalUtilities.getTeamName(m_databaseFileName, Constants.TableName.KnockoutTeams, i);
                scoresTable.Rows.Add(dScoresRow);
                dScoresRow = scoresTable.NewRow();
                dScoresRow["Match_Number"] = i;
                teamNumber = 2 * numberOfMatches - (i - 1);
                dScoresRow["Team_Number"] = teamNumber;
                dScoresRow["Team_Name"]   = LocalUtilities.getTeamName(m_databaseFileName, Constants.TableName.KnockoutTeams, teamNumber);
                scoresTable.Rows.Add(dScoresRow);
            }
            AccessDatabaseUtilities.saveTableToDatabase(m_databaseFileName, Constants.TableName.KnockoutScores + "_" + roundNumber);
        }
示例#6
0
        private void createRoundPage(int roundNumber)
        {
            printMessage("Creating Round Page for Round Number : " + roundNumber);
            m_prefix = "../";
            StreamWriter sw = new StreamWriter(Path.Combine(m_webpagesRootDirectory, "rounds", "round" + roundNumber + "score.html"));

            sw.WriteLine("<html><head></head><body>");
            int numberOfTeamsLeft   = LocalUtilities.teamsLeft(m_databaseFileName, roundNumber);
            int numberOfMatchesLeft = (numberOfTeamsLeft / 2) + numberOfTeamsLeft % 2;

            DataRow[] foundRows      = getTable(Constants.TableName.EventScores).Select("Round_Number = " + roundNumber + " AND Table_Number <= " + numberOfMatchesLeft, "Table_Number ASC");
            DataRow   dRow           = (foundRows.Length > 0)?foundRows[0]:null;
            string    headerTemplate = "<h2>Scores for Round " + roundNumber + "</h2>" + "<br/>[_commonPageHeader]";

            sw.WriteLine(applyTemplate_(headerTemplate, dRow));
            if (roundNumber > m_roundsCompleted)
            {
                if (roundNumber <= m_drawsCompleted)
                {
                    sw.WriteLine(Utilities.makeTablePreamble_() + "<thead><tr>");
                    ArrayList tableHeader = new ArrayList();
                    tableHeader.Clear();
                    tableHeader.Add("Round " + roundNumber + " Draw");
                    sw.WriteLine(Utilities.makeTableHeader_(tableHeader) + "</tr></thead><tbody>");
                    sw.WriteLine("<tr><td>");
                    sw.WriteLine(createRoundTable(roundNumber, foundRows, false));
                    sw.WriteLine("</td></tr></tbody></table>");
                    sw.WriteLine("</tbody></table>");
                }
                else
                {
                    sw.WriteLine("<h2>No Draw or Score published yet!</h2>");
                }
            }
            else
            {
                sw.WriteLine(Utilities.makeTablePreamble_() + "<thead><tr>");
                ArrayList tableHeader = new ArrayList();
                tableHeader.Clear();
                tableHeader.Add("Round " + roundNumber + " Score");
                tableHeader.Add("Cumulative Score and Ranking after Round " + roundNumber);
                sw.WriteLine(Utilities.makeTableHeader_(tableHeader) + "</tr></thead><tbody>");
                sw.WriteLine("<tr><td>");
                sw.WriteLine(createRoundTable(roundNumber, foundRows));
                sw.WriteLine("</td><td>");
                m_currentRound = roundNumber;
                Utilities.HTMLTableParameters parameters = new Utilities.HTMLTableParameters("");
                parameters.columns.Add("Rank", "{Rank_After_Round_" + roundNumber + "}");
                //parameters.columns.Add("Qualified", "Qualified");
                parameters.columns.Add("No.", "[_makeTeamNumberLink]");
                parameters.columns.Add("Name", "[_makeTeamNameLink]");
                parameters.columns.Add("VPs", "{Score_After_Round_" + roundNumber + "}");
                parameters.columns.Add("Tiebreaker Quotient", "{Tiebreaker_After_Round_" + roundNumber + "}");
                parameters.sortCriteria   = "Rank_After_Round_" + roundNumber + " ASC";
                parameters.filterCriteria = "Rank_After_Round_" + roundNumber + " > -1";
                parameters.headerTemplate = headerTemplate;
                parameters.tableName      = Constants.TableName.EventComputedScores;

                sw.WriteLine(createTable_(parameters));
                sw.WriteLine("</td></tr></tbody></table>");
                sw.WriteLine("</tbody></table>");
            }
            sw.WriteLine("</body></html>");
            sw.Close();
            reportProgress("Created Round " + roundNumber + " Score Page");
        }