Exemplo n.º 1
0
        public EditRoundResults() : base(Gtk.WindowType.Toplevel)
        {
            this.Build();
            RoundResultData.UpdateStats();
            // resultsheet
            resultsheet = new RoundResultSheet();
            ebResultSheet.Add(resultsheet);
            ebResultSheet.ShowAll();

            // cbRooms
            SetupCombobox(cbRooms);
            cbRooms.Sensitive = false;
            rooms             = new ListStore(typeof(RoomData));
            cbRooms.Model     = rooms;

            // cbRounds
            SetupCombobox(cbRounds);
            rounds         = new ListStore(typeof(RoundData));
            cbRounds.Model = rounds;
            foreach (RoundData rd in Tournament.I.Rounds)
            {
                rounds.AppendValues(rd);
            }
            SelectFirstIncomplete(cbRounds);
        }
Exemplo n.º 2
0
        void UpdateJudges()
        {
            RoundResultData.UpdateStats();
            MiscHelpers.ClearTable(tableJudges);
            List <Debater> judges = new List <Debater>();

            foreach (Debater d in Tournament.I.Debaters)
            {
                if (d.Role.IsJudge)
                {
                    judges.Add(d);
                }
            }
            judges.Sort(delegate(Debater a, Debater b) {
                return(b.StatsAvg[0].CompareTo(a.StatsAvg[0]));
            });
            for (uint pos = 0; pos < judges.Count; pos++)
            {
                Debater j = judges[(int)pos];
                tableJudges.Attach(new DebaterWidget(new RoundDebater(j)),
                                   0, 1,
                                   2 * pos + 1, 2 * pos + 2,
                                   AttachOptions.Fill, AttachOptions.Fill, 0, 0);
                Label lbl1 = new Label();
                lbl1.Markup = "<big><b>" +
                              RoundResultData.StatAsString(j.StatsAvg[0]) + "&#177;" +
                              RoundResultData.ErrAsString(j.StatsAvg[1]) + "</b></big>";
                lbl1.Xalign = 0;
                tableJudges.Attach(lbl1,
                                   1, 2,
                                   2 * pos + 1, 2 * pos + 2,
                                   AttachOptions.Fill, AttachOptions.Fill, 0, 0);
                Label lbl2 = new Label();
                lbl2.Markup = "<big><b>" +
                              RoundResultData.StatAsString(j.StatsAvg[2]) + "</b></big>";
                lbl2.Xalign = 0;
                tableJudges.Attach(lbl2,
                                   2, 3,
                                   2 * pos + 1, 2 * pos + 2,
                                   AttachOptions.Fill, AttachOptions.Fill, 0, 0);
                if (pos < judges.Count - 1)
                {
                    Debater jNext = judges[(int)(pos + 1)];
                    double  diff  = j.StatsAvg[0] - jNext.StatsAvg[0];
                    if (double.IsNaN(diff))
                    {
                        diff = 0;
                    }
                    int pixels = 5 * (int)Math.Round(diff * 10);
                    tableJudges.Attach(MyGridLine.H(pixels + 3),
                                       0, 3,
                                       2 * pos + 2, 2 * pos + 3,
                                       AttachOptions.Fill, AttachOptions.Fill, 0, 0);
                }
            }

            tableJudges.ShowAll();
        }
Exemplo n.º 3
0
 string JudgeStatsToMarkup(double sum, int n, double tresh)
 {
     if (n == 0)
     {
         return("?");
     }
     else
     {
         double avg = sum / n;
         return(Math.Abs(avg) > tresh
                                 ? "<b><span color=\"#FF6600\">" + RoundResultData.StatAsString(avg) + "</span></b>"
                                         : RoundResultData.StatAsString(avg));
     }
 }
Exemplo n.º 4
0
 void SetSpeakerFrameLabels()
 {
     foreach (int i in new int[] { 0, 1, 2, 3, 7, 8 })
     {
         DebaterWidget w = dataWidgets[i] as DebaterWidget;
         int           j = i;
         if (w.HasResult)
         {
             j = results[i].GetPosition();
         }
         Frame f = w.GetAncestor(Frame.GType) as Frame;
         RoundResultData.RoleType role;
         int index;
         RoundResultData.ParsePosition(j, out role, out index);
         (f.LabelWidget as Label).Markup = "<i>" + (index + 1) + ". " + role + "</i>";
     }
 }
Exemplo n.º 5
0
        protected void OnBtnExportRoundDataClicked(object sender, System.EventArgs e)
        {
            // the Gtk Warning can be ignored, it's a bug in Gtk...
            FileChooserDialog dlg = new FileChooserDialog("Choose CSV file", this, FileChooserAction.Save,
                                                          "Cancel", ResponseType.Cancel,
                                                          "Save", ResponseType.Accept);

            dlg.SetCurrentFolder(Directory.GetCurrentDirectory());
            TextWriter tw       = null;
            string     fileName = null;

            if (dlg.Run() == (int)ResponseType.Accept)
            {
                // try open the file for writing
                try {
                    fileName = dlg.Filename;
                    dlg.Destroy();
                    tw = new StreamWriter(fileName);
                }
                catch (Exception ex) {
                    MiscHelpers.ShowMessage(this, "Could not open file: " + ex.Message, MessageType.Error);
                    return;
                }
            }
            else
            {
                dlg.Destroy();
                return;
            }


            // get judges  and speakers
            List <Debater> judges   = new List <Debater>();
            List <Debater> speakers = new List <Debater>();

            foreach (Debater d in Tournament.I.Debaters)
            {
                if (d.Role.IsJudge)
                {
                    judges.Add(d);
                }
                else if (d.Role.IsTeamMember)
                {
                    speakers.Add(d);
                }
            }
            judges.Sort();
            speakers.Sort();

            // write out the header
            List <string> judgesStr = new List <string>();

            foreach (Debater d in judges)
            {
                judgesStr.Add(d.Name + " (" + d.Club + ")");
            }
            WriteCSVLine(tw, "Name", "Club", "Team", "Round", "Room", "Position", judgesStr, judgesStr);

            // for each round, write out all team members and it's results
            foreach (RoundData rd in Tournament.I.Rounds)
            {
                foreach (Debater d in speakers)
                {
                    // init with null
                    string        roomStr = null;
                    string        posStr  = null;
                    List <string> points  = new List <string>();
                    for (int i = 0; i < 2 * judges.Count; i++)
                    {
                        points.Add(null);
                    }
                    // check if debater was set in this round
                    int roomIdx = d.GetRoomIndex(rd.RoundName);
                    if (roomIdx >= 0)
                    {
                        roomStr            = (roomIdx + 1).ToString();
                        RoundResultData rr = d.RoundResults.Find(delegate(RoundResultData obj) {
                            return(obj.Equals(rd.RoundName));
                        });
                        // check if debater has some results
                        if (rr != null)
                        {
                            posStr = rr.GetPosAsString();
                            // get the judges in the room, determine indices
                            List <int> judgesIndex = new List <int>();
                            foreach (RoundDebater j in rd.Rooms[roomIdx].Judges)
                            {
                                judgesIndex.Add(judges.FindIndex(delegate(Debater obj) {
                                    return(obj.Equals(j));
                                }));
                            }
                            // check if data makes sense
                            // rr.Role is for speaker only Gov, Opp, Free (Judge is impossible!)
                            if (rr.SpeakerScores.Count != judgesIndex.Count ||
                                rr.TeamScores.Count != judgesIndex.Count)
                            {
                                Console.WriteLine("Data for " + d + " inconsistent, skipping.");
                                continue;
                            }
                            // write it in points, doubled size since speaker and team points...
                            for (int i = 0; i < judgesIndex.Count; i++)
                            {
                                points[judgesIndex[i]] = rr.SpeakerScores[i].ToString();
                                if (rr.Role != RoundResultData.RoleType.Free)
                                {
                                    points[judges.Count + judgesIndex[i]] = rr.TeamScores[i].ToString();
                                }
                            }
                        }
                    }
                    WriteCSVLine(tw, d.Name, d.Club, d.Role, rd.RoundName, roomStr, posStr, points);
                }
            }

            tw.Close();
            MiscHelpers.AskShowTemplate(this, "RoundData successfully exported.", fileName);
        }