public static CoderStat NewCoderStat(Coder coder, Round round)
        {
            CoderStat coderStat = new CoderStat();

            coderStat.handle = coder.handle;
            coderStat.id     = coder.id;
            coderStat.win    = new Dictionary <string, int>();
            coderStat.lose   = new Dictionary <string, int>();
            coderStat.deuce  = new Dictionary <string, int>();
            coderStat.UpdateStat(coder, round);
            return(coderStat);
        }
 public void DualWith(Coder me, Coder other)
 {
     if (!win.ContainsKey(other.id))
     {
         win.Add(other.id, 0);
         lose.Add(other.id, 0);
         deuce.Add(other.id, 0);
     }
     if (Convert.ToDouble(me.finalPoints) < Convert.ToDouble(other.finalPoints))
     {
         ++lose[other.id];
     }
     else if (Convert.ToDouble(me.finalPoints) > Convert.ToDouble(other.finalPoints))
     {
         ++win[other.id];
     }
     else
     {
         ++deuce[other.id];
     }
 }
示例#3
0
 public static Coder ParseCoderWithXML(XmlNode node)
 {
     try
     {
         Coder coder = new Coder();
         Dictionary <string, string> dict = XmlHelper.ParseXml(node);
         coder.handle          = dict["handle"];
         coder.room            = RoomStringToInt(dict["room_name"]);
         coder.advanced        = dict["advanced"];
         coder.succ_challenges = Convert.ToInt32(dict["challenges_made_successful"]);
         coder.fail_challenges = Convert.ToInt32(dict["challenges_made_failed"]);
         coder.division        = Convert.ToInt32(dict["division"]);
         coder.divRank         = Convert.ToInt32(dict["division_placed"]);
         coder.oldRating       = Convert.ToInt32(dict["old_rating"]);
         coder.newRating       = Convert.ToInt32(dict["new_rating"]);
         coder.vol             = Convert.ToInt32(dict["new_vol"]);
         coder.challengePoints = dict["challenge_points"];
         coder.finalPoints     = dict["final_points"];
         coder.newCoder        = dict["num_ratings"].Equals("1");
         if (coder.newCoder)
         {
             coder.colortype = Color.White;
             coder.oldRating = 1200;
         }
         else
         {
             if (coder.oldRating < 900)
             {
                 coder.colortype = Color.Gray;
             }
             else if (coder.oldRating < 1200)
             {
                 coder.colortype = Color.Green;
             }
             else if (coder.oldRating < 1500)
             {
                 coder.colortype = Color.Blue;
             }
             else if (coder.oldRating < 2200)
             {
                 coder.colortype = Color.Yellow;
             }
             else if (coder.oldRating < 3000)
             {
                 coder.colortype = Color.Red;
             }
             else
             {
                 coder.colortype = Color.Target;
             }
         }
         coder.problemStatus    = new String[3];
         coder.problemPoints    = new String[3];
         coder.problemStatus[0] = dict["level_one_status"];
         coder.problemStatus[1] = dict["level_two_status"];
         coder.problemStatus[2] = dict["level_three_status"];
         coder.problemPoints[0] = dict["level_one_final_points"];
         coder.problemPoints[1] = dict["level_two_final_points"];
         coder.problemPoints[2] = dict["level_three_final_points"];
         for (int i = 0; i < 3; ++i)
         {
             if (coder.problemStatus[i].Equals(String.Empty))
             {
                 coder.problemStatus[i] = "Unopened";
             }
         }
         return(coder);
     }
     catch (System.Exception)
     {
         return(null);
     }
 }
示例#4
0
 public static int CompareByRank(Coder coder1, Coder coder2)
 {
     return(coder1.divRank - coder2.divRank);
 }
示例#5
0
        /*static List<Round> ReadRounds(Dictionary<String, Round> roundInfo)
         * {
         *  string roundsFileName = "NewRounds.txt";
         *  List<Round> rounds = new List<Round>();
         *  StreamReader reader = new StreamReader(roundsFileName);
         *  while (!reader.EndOfStream)
         *  {
         *      string s = reader.ReadLine();
         *      rounds.Add(roundInfo[s]);
         *  }
         *  reader.Close();
         *  return rounds;
         * }*/


        static void UpdateRound(Round round, Dictionary <String, String> ZJUers, List <Round> tour, List <Round> srm,
                                Dictionary <String, CoderStat> stats, List <Record> ratingRecordList, List <Record> challengeInfoList,
                                List <Record> volRecordList, List <Record> divWinnerList, List <Record> onsiteList, Dictionary <CoderStat, List <Record> > coderInfo)
        {
            string      URL = "http://www.topcoder.com/tc?module=BasicData&c=dd_round_results&rd=" + round.roundID;
            XmlDocument xml = XmlHelper.LoadXML(URL, round.roundID + ".xml");

            if (xml == null)
            {
                return;
            }
            XmlNode      rootNode = xml.LastChild;
            List <Coder> div1 = new List <Coder>(), div2 = new List <Coder>();

            foreach (XmlNode node in rootNode.ChildNodes)
            {
                Coder coder = Coder.ParseCoderWithXML(node);
                if (coder != null && ZJUers.Keys.Contains(coder.handle))
                {
                    coder.id = ZJUers[coder.handle];
                    CoderStat coderStat = null;
                    Record    record    = new Record();
                    record.coder = coder;
                    record.round = round;
                    if (stats.Keys.Contains(coder.id))
                    {
                        coderStat = stats[coder.id];
                        coderStat.UpdateStat(coder, round);
                        coderInfo[coderStat].Add(record);
                    }
                    else
                    {
                        coderStat = CoderStat.NewCoderStat(coder, round);
                        stats.Add(coder.id, coderStat);
                        coderInfo[coderStat] = new List <Record>();
                        coderInfo[coderStat].Add(record);
                    }
                    if (coder.division == 1)
                    {
                        foreach (Coder other in div1)
                        {
                            coderStat.DualWith(coder, other);
                            stats[other.id].DualWith(other, coder);
                        }
                        div1.Add(coder);
                    }
                    else
                    {
                        foreach (Coder other in div2)
                        {
                            coderStat.DualWith(coder, other);
                            stats[other.id].DualWith(other, coder);
                        }
                        div2.Add(coder);
                    }
                    if (Convert.ToDouble(coder.challengePoints) > 0)
                    {
                        challengeInfoList.Add(record);
                    }
                    if (ratingRecordList.Count == 0 || coder.newRating > ratingRecordList.Last().coder.newRating)
                    {
                        ratingRecordList.Add(record);
                    }
                    if (coder.vol >= 600)
                    {
                        volRecordList.Add(record);
                    }
                    if (coder.divRank == 1)
                    {
                        divWinnerList.Add(record);
                    }
                    if (IsOnsite(round.name))
                    {
                        onsiteList.Add(record);
                    }
                }
            }
            if (div1.Count != 0 || div2.Count != 0)
            {
                div1.Sort(new Comparison <Coder>(Coder.CompareByRank));
                div2.Sort(new Comparison <Coder>(Coder.CompareByRank));
                HTMLGenerator.GenerateHTMLForRound(round, div1, div2);
                if (round.type.Equals("Single Round Match"))
                {
                    srm.Add(round);
                }
                else
                {
                    tour.Add(round);
                }
            }
        }
        public void UpdateStat(Coder coder, Round round)
        {
            total_challenges += coder.fail_challenges + coder.succ_challenges;
            succ_challenges += coder.succ_challenges;
            rating = coder.newRating;
            maxrating = Math.Max(maxrating, coder.newRating);
            vol = coder.vol;
            chaPoints += Convert.ToDouble(coder.challengePoints);

            myLastDate = round.date;
            ++events;
            if (!HTMLGenerator.RatingToString(coder.oldRating, coder.newCoder).Equals(HTMLGenerator.RatingToString(coder.newRating, false)))
            {
                ++colorChangeTimes;
            }
            if (DateTime.Parse(round.date).AddYears(1) >= DateTime.Now)
            {
                ++eventsLastYear;
            }
            for (int i = 0; i < 3; ++i)
            {
                if (coder.problemStatus[i].Equals("Challenge Succeeded") || coder.problemStatus[i].Equals("Failed System Test"))
                {
                    ++submits;
                }
                else if (coder.problemStatus[i].Equals("Passed System Test"))
                {
                    ++submits;
                    ++solves;
                }
            }
        }
 public void DualWith(Coder me, Coder other)
 {
     if (!win.ContainsKey(other.id))
     {
         win.Add(other.id, 0);
         lose.Add(other.id, 0);
         deuce.Add(other.id, 0);
     }
     if (Convert.ToDouble(me.finalPoints) < Convert.ToDouble(other.finalPoints))
     {
         ++lose[other.id];
     }
     else if (Convert.ToDouble(me.finalPoints) > Convert.ToDouble(other.finalPoints))
     {
         ++win[other.id];
     }
     else
     {
         ++deuce[other.id];
     }
 }
 public static CoderStat NewCoderStat(Coder coder, Round round)
 {
     CoderStat coderStat = new CoderStat();
     coderStat.handle = coder.handle;
     coderStat.id = coder.id;
     coderStat.win = new Dictionary<string, int>();
     coderStat.lose = new Dictionary<string, int>();
     coderStat.deuce = new Dictionary<string, int>();
     coderStat.UpdateStat(coder, round);
     return coderStat;
 }
 public static Coder ParseCoderWithXML(XmlNode node)
 {
     try
     {
         Coder coder = new Coder();
         Dictionary<string, string> dict = XmlHelper.ParseXml(node);
         coder.handle = dict["handle"];
         coder.room = RoomStringToInt(dict["room_name"]);
         coder.advanced = dict["advanced"];
         coder.succ_challenges = Convert.ToInt32(dict["challenges_made_successful"]);
         coder.fail_challenges = Convert.ToInt32(dict["challenges_made_failed"]);
         coder.division = Convert.ToInt32(dict["division"]);
         coder.divRank = Convert.ToInt32(dict["division_placed"]);
         coder.oldRating = Convert.ToInt32(dict["old_rating"]);
         coder.newRating = Convert.ToInt32(dict["new_rating"]);
         coder.vol = Convert.ToInt32(dict["new_vol"]);
         coder.challengePoints = dict["challenge_points"];
         coder.finalPoints = dict["final_points"];
         coder.newCoder = dict["num_ratings"].Equals("1");
         if (coder.newCoder)
         {
             coder.colortype = Color.White;
             coder.oldRating = 1200;
         }
         else
         {
             if (coder.oldRating < 900)
             {
                 coder.colortype = Color.Gray;
             }
             else if (coder.oldRating < 1200)
             {
                 coder.colortype = Color.Green;
             }
             else if (coder.oldRating < 1500)
             {
                 coder.colortype = Color.Blue;
             }
             else if (coder.oldRating < 2200)
             {
                 coder.colortype = Color.Yellow;
             }
             else if (coder.oldRating < 3000)
             {
                 coder.colortype = Color.Red;
             }
             else
             {
                 coder.colortype = Color.Target;
             }
         }
         coder.problemStatus = new String[3];
         coder.problemPoints = new String[3];
         coder.problemStatus[0] = dict["level_one_status"];
         coder.problemStatus[1] = dict["level_two_status"];
         coder.problemStatus[2] = dict["level_three_status"];
         coder.problemPoints[0] = dict["level_one_final_points"];
         coder.problemPoints[1] = dict["level_two_final_points"];
         coder.problemPoints[2] = dict["level_three_final_points"];
         for (int i = 0; i < 3; ++i)
         {
             if (coder.problemStatus[i].Equals(String.Empty))
             {
                 coder.problemStatus[i] = "Unopened";
             }
         }
         return coder;
     }
     catch (System.Exception)
     {
         return null;
     }
 }
示例#10
0
 public static int CompareByRank(Coder coder1, Coder coder2)
 {
     return coder1.divRank - coder2.divRank;
 }