public static int CompareByChallengeSuccRate(CoderStat coder1, CoderStat coder2)
 {
     if (coder1.total_challenges < 20 && coder2.total_challenges < 20)
     {
         return(0);
     }
     else if (coder2.total_challenges < 20)
     {
         return(-1);
     }
     else if (coder1.total_challenges < 20)
     {
         return(1);
     }
     else
     {
         if (coder1.succ_challenges * coder2.total_challenges == coder2.succ_challenges * coder1.total_challenges)
         {
             return(coder2.succ_challenges - coder1.succ_challenges);
         }
         else
         {
             return(coder2.succ_challenges * coder1.total_challenges - coder1.succ_challenges * coder2.total_challenges);
         }
     }
 }
 public static int CompareBySubmissionSuccRate(CoderStat coder1, CoderStat coder2)
 {
     if (coder1.submits < 20 && coder2.submits < 20)
     {
         return(0);
     }
     else if (coder2.submits < 20)
     {
         return(-1);
     }
     else if (coder1.submits < 20)
     {
         return(1);
     }
     else
     {
         if (coder1.solves * coder2.submits == coder2.solves * coder1.submits)
         {
             return(coder2.solves - coder1.solves);
         }
         else
         {
             return(coder2.solves * coder1.submits - coder1.solves * coder2.submits);
         }
     }
 }
 public static int CompareByChallengeSuccRate(CoderStat coder1, CoderStat coder2)
 {
     if (coder1.total_challenges < 20 && coder2.total_challenges < 20)
     {
         return 0;
     }
     else if (coder2.total_challenges < 20)
     {
         return -1;
     }
     else if (coder1.total_challenges < 20)
     {
         return 1;
     }
     else
     {
         if (coder1.succ_challenges * coder2.total_challenges == coder2.succ_challenges * coder1.total_challenges)
         {
             return coder2.succ_challenges - coder1.succ_challenges;
         }
         else
         {
             return coder2.succ_challenges * coder1.total_challenges - coder1.succ_challenges * coder2.total_challenges;
         }
     }
 }
        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 int CompareByMaxRatingActive(CoderStat coder1, CoderStat coder2)
 {
     if (!coder2.active && !coder1.active)
     {
         return(0);
     }
     else if (!coder2.active)
     {
         return(-1);
     }
     else if (!coder1.active)
     {
         return(1);
     }
     return(coder2.maxrating - coder1.maxrating);
 }
 public static int CompareByAverageChallengePoints(CoderStat coder1, CoderStat coder2)
 {
     if (coder1.total_challenges < 20 && coder2.total_challenges < 20)
     {
         return(0);
     }
     else if (coder2.total_challenges < 20)
     {
         return(-1);
     }
     else if (coder1.total_challenges < 20)
     {
         return(1);
     }
     else
     {
         return(Convert.ToInt32(1000 * (coder2.chaPoints / coder2.events - coder1.chaPoints / coder1.events)));
     }
 }
 public static int CompareByChallengePoints(CoderStat coder1, CoderStat coder2)
 {
     if (coder1.total_challenges < 20 && coder2.total_challenges < 20)
     {
         return 0;
     }
     else if (coder2.total_challenges < 20)
     {
         return -1;
     }
     else if (coder1.total_challenges < 20)
     {
         return 1;
     }
     else
     {
         return Convert.ToInt32(coder2.chaPoints - coder1.chaPoints);
     }
 }
 public static int CompareByColorChangeTimes(CoderStat coder1, CoderStat coder2)
 {
     return(coder2.colorChangeTimes - coder1.colorChangeTimes);
 }
 public static int CompareByEventsLastYear(CoderStat coder1, CoderStat coder2)
 {
     return coder2.eventsLastYear - coder1.eventsLastYear;
 }
        public static void GenerateHTMLForCoder(CoderStat coderStat, List<Record> coderHistory, Dictionary<String, CoderStat> stats)
        {
            string dire = Directory.GetCurrentDirectory();
            string rankFile = dire + "\\member\\" + coderStat.id + ".html";
            FileStream stream = new FileStream(rankFile, FileMode.Create);
            StreamWriter writer = new StreamWriter(stream);
            writer.WriteLine("<html><body>");
            writer.WriteLine("<head><meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">");
            writer.WriteLine("<title>" + coderStat.handle + "</title><link rel=\"stylesheet\" href=\"member.css\" type=\"text/css\" /></head>");
            writer.WriteLine("<h1><a href=\"http://www.topcoder.com/tc?module=MemberProfile&cr=" + coderStat.id + "\" class=\"" + RatingToString(coderStat.rating, false) + "\">" + coderStat.handle + "</a></h1>");

            writer.WriteLine("<div class=\"statDualDiv\">");
            writer.WriteLine("<div class=\"statDiv\">");
            writer.WriteLine("<h2>Personal statistics</h2>");

            writer.WriteLine("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tbody>");
            writer.WriteLine("\t<tr class=\"titleLine\">");
            writer.WriteLine("\t\t<td><span>Handle</span></td>");
            writer.WriteLine("\t\t<td><span># events</span></td>");
            writer.WriteLine("\t\t<td><span># events last year</td>");
            writer.WriteLine("\t</tr>");
            writer.WriteLine("\t<tr>");
            writer.WriteLine("\t\t<td><a href=\"http://www.topcoder.com/tc?module=MemberProfile&cr=" + coderStat.id + "\" class=\"" + RatingToString(coderStat.rating, false) + "\">" + coderStat.handle + "</a></td>");
            writer.WriteLine("\t\t<td><span>" + coderStat.events + "</span></td>");
            writer.WriteLine("\t\t<td><span>" + coderStat.eventsLastYear + "</span></td>");
            writer.WriteLine("\t</tr>");

            writer.WriteLine("\t<tr class=\"titleLine\">");
            writer.WriteLine("\t\t<td><span>Rating</span></td>");
            writer.WriteLine("\t\t<td><span>Max rating</span></td>");
            writer.WriteLine("\t\t<td><span>Volatility</span></td>");
            writer.WriteLine("\t</tr>");
            writer.WriteLine("\t<tr>");
            writer.WriteLine("\t\t<td><span class=\"" + RatingToString(coderStat.rating, false) + "\">" + coderStat.rating + "</span></td>");
            writer.WriteLine("\t\t<td><span class=\"" + RatingToString(coderStat.maxrating, false) + "\">" + coderStat.maxrating + "</span></td>");
            writer.WriteLine("\t\t<td><span>" + coderStat.vol + "</span></td>");
            writer.WriteLine("\t</tr>");

            writer.WriteLine("\t<tr class=\"titleLine\">");
            writer.WriteLine("\t\t<td><span># submits</span></td>");
            writer.WriteLine("\t\t<td><span># solves</span></td>");
            writer.WriteLine("\t\t<td><span>Submission accuracy</span></td>");
            writer.WriteLine("\t</tr>");
            writer.WriteLine("\t<tr>");
            writer.WriteLine("\t\t<td><span>" + coderStat.submits + "</span></td>");
            writer.WriteLine("\t\t<td><span>" + coderStat.solves + "</span></td>");
            writer.WriteLine("\t\t<td><span>" + (coderStat.submits == 0 ? "NaN" : (Convert.ToDouble(coderStat.solves) / Convert.ToDouble(coderStat.submits) * 100.0).ToString("N2") + "%") + "</span></td>");
            writer.WriteLine("\t</tr>");

            writer.WriteLine("\t<tr class=\"titleLine\">");
            writer.WriteLine("\t\t<td><span># challenges</span></td>");
            writer.WriteLine("\t\t<td><span># successful challenges</span></td>");
            writer.WriteLine("\t\t<td><span>Challenge accuracy</span></td>");
            writer.WriteLine("\t</tr>");
            writer.WriteLine("\t<tr>");
            writer.WriteLine("\t\t<td><span>" + coderStat.total_challenges + "</span></td>");
            writer.WriteLine("\t\t<td><span>" + coderStat.succ_challenges + "</span></td>");
            writer.WriteLine("\t\t<td><span>" + (coderStat.total_challenges == 0 ? "NaN" : (Convert.ToDouble(coderStat.succ_challenges) / Convert.ToDouble(coderStat.total_challenges) * 100.0).ToString("N2") + "%") + "</span></td>");
            writer.WriteLine("\t</tr>");
            writer.WriteLine("</tbody></table></div>");

            writer.WriteLine("<div class=\"dualDiv\">");
            writer.WriteLine("<h2>Cooccurrence</h2>");

            writer.WriteLine("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tbody>");
            List<String> coderList = new List<string>();
            foreach (string coderID in coderStat.win.Keys)
            {
                coderList.Add(coderID);
            }
            writer.WriteLine("\t<tr class=\"titleLine\">");
            writer.WriteLine("\t\t<td><span>Handle</span></td>");
            writer.WriteLine("\t\t<td><span>Rating</span></td>");
            writer.WriteLine("\t\t<td><span># cooccurrence</span></td>");
            writer.WriteLine("\t\t<td><span>Win / Lose / Deuce</span></td>");
            writer.WriteLine("\t\t<td><span></span></td>");
            writer.WriteLine("\t</tr>");
            for (int i = 0; i < 10 && coderList.Count != 0; ++i)
            {
                int maxcooc = 0;
                string bestcoderID = null;
                foreach (string coderID in coderList)
                {
                    if (coderStat.win[coderID] + coderStat.lose[coderID] + coderStat.deuce[coderID] > maxcooc)
                    {
                        maxcooc = coderStat.win[coderID] + coderStat.lose[coderID] + coderStat.deuce[coderID];
                        bestcoderID = coderID;
                    }
                }
                writer.WriteLine("\t<tr>");
                writer.WriteLine("\t\t<td><a href=\"" + bestcoderID + ".html\" class=\"" + RatingToString(stats[bestcoderID].rating, false) + "\">" + stats[bestcoderID].handle + "</a></td>");
                writer.WriteLine("\t\t<td><span class=\"" + RatingToString(stats[bestcoderID].rating, false) + "\">" + stats[bestcoderID].rating + "</span></td>");
                writer.WriteLine("\t\t<td><span>" + maxcooc + "</span></td>");
                writer.WriteLine("\t\t<td><span>" + coderStat.win[bestcoderID] + " / " + coderStat.lose[bestcoderID] + " / " + coderStat.deuce[bestcoderID] + "</span></td>");
                writer.WriteLine("\t\t<td><a href=\"../dual.php?handle1=" + coderStat.handle + "&handle2=" + stats[bestcoderID].handle + "\">See dual between <span class=\"" + RatingToString(coderStat.rating, false) + "\">" + coderStat.handle + "</span> and <span class=\"" + RatingToString(stats[bestcoderID].rating, false) + "\">" + stats[bestcoderID].handle + "</span></a></td>");
                writer.WriteLine("\t</tr>");
                coderList.Remove(bestcoderID);
            }
            writer.WriteLine("</tbody></table></div>");

            coderHistory.Reverse();
            writer.WriteLine("<div class=\"historyDiv\">");
            writer.WriteLine("<h2>Competition history</h2>");
            writer.WriteLine("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tbody>");
            writer.WriteLine("\t<tr class=\"titleLine\">");
            writer.WriteLine("\t\t<td><span>Event</span></td>");
            writer.WriteLine("\t\t<td><span>Div</span></td>");
            writer.WriteLine("\t\t<td><span>Rank</span></td>");
            writer.WriteLine("\t\t<td><span>Points</span></td>");
            writer.WriteLine("\t\t<td><span>Level 1</span></td>");
            writer.WriteLine("\t\t<td><span>Level 2</span></td>");
            writer.WriteLine("\t\t<td><span>Level 3</span></td>");
            writer.WriteLine("\t\t<td><span>Challenge</span></td>");
            writer.WriteLine("\t\t<td><span>Challenge Points</span></td>");
            writer.WriteLine("\t\t<td><span>Rating</span></td>");
            writer.WriteLine("\t\t<td><span>Rating Change</span></td>");
            writer.WriteLine("\t\t<td><span>Volatility</span></td>");
            writer.WriteLine("\t</tr>");
            foreach (Record record in coderHistory)
            {
                writer.WriteLine("\t<tr>");
                //writer.WriteLine("\t\t<td><a href=\"http://www.topcoder.com/stat?c=coder_room_stats&rd=" + record.round.roundID + "&cr=" + record.coder.id + "\" class=\"eventText\">" + record.round.name + "</span></td>");
                writer.WriteLine("\t\t<td><a href=\"../rank/" + record.round.roundID + ".html\" class=\"eventText\">" + record.round.name + "</a></td>");
                writer.WriteLine("\t\t<td><span>" + record.coder.division + "</span></td>");
                writer.WriteLine("\t\t<td><span>" + record.coder.divRank + "</span></td>");
                writer.WriteLine("\t\t<td><span>" + record.coder.finalPoints + "</span></td>");
                writer.WriteLine("\t\t<td><span class=\"" + StatusToString(record.coder.problemStatus[0]) + "\">" + (record.coder.problemStatus[0].Equals("Passed System Test") ? record.coder.problemPoints[0] : record.coder.problemStatus[0]) + "</span></td>");
                writer.WriteLine("\t\t<td><span class=\"" + StatusToString(record.coder.problemStatus[1]) + "\">" + (record.coder.problemStatus[1].Equals("Passed System Test") ? record.coder.problemPoints[1] : record.coder.problemStatus[1]) + "</span></td>");
                writer.WriteLine("\t\t<td><span class=\"" + StatusToString(record.coder.problemStatus[2]) + "\">" + (record.coder.problemStatus[2].Equals("Passed System Test") ? record.coder.problemPoints[2] : record.coder.problemStatus[2]) + "</span></td>");
                writer.WriteLine("\t\t<td><span>" + (record.coder.succ_challenges > 0 ? "+" : "") + record.coder.succ_challenges + "/" + (record.coder.fail_challenges > 0 ? "-" : "") + record.coder.fail_challenges + "</span></td>");
                writer.WriteLine("\t\t<td><span class=\"" + ChallengeScoreToString(record.coder.challengePoints) + "\">" + record.coder.challengePoints + "</span></td>");
                writer.WriteLine("\t\t<td><span class=\"" + RatingToString(record.coder.newRating, false) + "\">" + record.coder.newRating + "</span></td>");
                writer.WriteLine("\t\t<td><span class=\"" + RatingChangeToString(record.coder.newRating - record.coder.oldRating) + "\">" + RatingChangeToImage(record.coder.newRating - record.coder.oldRating) + Math.Abs(record.coder.newRating - record.coder.oldRating) + "</span></td>");
                writer.WriteLine("\t\t<td><span>" + record.coder.vol + "</span></td>");
                writer.WriteLine("\t</tr>");
            }
            writer.WriteLine("</tbody></table></div>");
            writer.WriteLine("<div class=\"backDiv\">");
            writer.WriteLine("<h3><a href=\"../ZJUerXTCer.html\" class=\"backLink\">Back to homepage</h3>");
            writer.WriteLine("</div>");

            writer.WriteLine("</body></html>");
            writer.Close();
            stream.Close();
        }
 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 int CompareBySubmissionSuccRate(CoderStat coder1, CoderStat coder2)
 {
     if (coder1.submits < 20 && coder2.submits < 20)
     {
         return 0;
     }
     else if (coder2.submits < 20)
     {
         return -1;
     }
     else if (coder1.submits < 20)
     {
         return 1;
     }
     else
     {
         if (coder1.solves * coder2.submits == coder2.solves * coder1.submits)
         {
             return coder2.solves - coder1.solves;
         }
         else
         {
             return coder2.solves * coder1.submits - coder1.solves * coder2.submits;
         }
     }
 }
 public static int CompareByRatingActive(CoderStat coder1, CoderStat coder2)
 {
     if (!coder2.active && !coder1.active)
     {
         return 0;
     }
     else if (!coder2.active)
     {
         return -1;
     }
     else if (!coder1.active)
     {
         return 1;
     }
     return coder2.rating - coder1.rating;
 }
 public static int CompareByRating(CoderStat coder1, CoderStat coder2)
 {
     return coder2.rating - coder1.rating;
 }
 public static int CompareByMaxRating(CoderStat coder1, CoderStat coder2)
 {
     return coder2.maxrating - coder1.maxrating;
 }
 public static int CompareByEvents(CoderStat coder1, CoderStat coder2)
 {
     return(coder2.events - coder1.events);
 }
 public static int CompareByEventsLastYear(CoderStat coder1, CoderStat coder2)
 {
     return(coder2.eventsLastYear - coder1.eventsLastYear);
 }
 public static int CompareByColorChangeTimes(CoderStat coder1, CoderStat coder2)
 {
     return coder2.colorChangeTimes - coder1.colorChangeTimes;
 }
 public static int CompareByRating(CoderStat coder1, CoderStat coder2)
 {
     return(coder2.rating - coder1.rating);
 }
 public static int CompareByMaxRating(CoderStat coder1, CoderStat coder2)
 {
     return(coder2.maxrating - coder1.maxrating);
 }
Exemple #21
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 static int CompareByEvents(CoderStat coder1, CoderStat coder2)
 {
     return coder2.events - coder1.events;
 }