Esempio n. 1
0
        void DoTheExport(MiscHelpers.TemplateType type)
        {
            TreeModel model = treeDebaters.Model;
            TreeIter  iter;

            if (model.GetIterFirst(out iter))
            {
                try {
                    ITemplate  tmpl         = MiscHelpers.GetTemplate("debaters", type);
                    ITmplBlock tmplDebaters = tmpl.ParseBlock("DEBATERS");
                    int        n            = 0;
                    do
                    {
                        n++;
                        TreeIter        storeIter = ConvertModelIterToStoreIter(iter);
                        EditableDebater d         = (EditableDebater)store.GetValue(storeIter, 0);
                        tmplDebaters.Assign("NUM", n.ToString());
                        tmplDebaters.Assign("NAME", d.Name.ToString());
                        tmplDebaters.Assign("CLUB", d.Club.ToString());
                        tmplDebaters.Assign("AGE", d.Age.ToString());
                        tmplDebaters.Assign("ROLE", EscapeString(d.Role.ToString(), type));
                        tmplDebaters.Assign("BLACKLIST", EscapeString(d.BlackList.ToString(), type));
                        tmplDebaters.Assign("WHITELIST", EscapeString(d.WhiteList.ToString(), type));
                        tmplDebaters.Assign("EXTRAINFO", EscapeString(d.ExtraInfo.ToString(), type));
                        tmplDebaters.Out();
                    }while(model.IterNext(ref iter));
                    MiscHelpers.AskShowTemplate(this,
                                                "Debaters successfully generated, see " +
                                                "pdfs/debaters.(pdf|csv)",
                                                MiscHelpers.MakeExportFromTemplate()
                                                );
                }
                catch (Exception ex) {
                    MiscHelpers.ShowMessage(this, "Could not export Debaters: " + ex.Message, MessageType.Error);
                }
            }
        }
Esempio n. 2
0
        private void ExportResultsCSV()
        {
            const int maxJudgesPerRoom = 4;

            try {
                List <RoundData> rounds = Tournament.I.Rounds;

                var tmpl      = MiscHelpers.GetTemplate("round-results", MiscHelpers.TemplateType.CSV);
                var roomsTmpl = tmpl.ParseBlock("ROOMS");

                for (var roundNum = 0; roundNum < rounds.Count; roundNum++)
                {
                    var round = rounds[roundNum];

                    foreach (RoomData venue in round.Rooms)
                    {
                        roomsTmpl.Assign("ROUND", roundNum.ToString());
                        roomsTmpl.Assign("VENUE", venue.RoomName);

                        var judges = venue.Judges;
                        for (var i = 0; i < maxJudgesPerRoom; i++)
                        {
                            var name =
                                judges.Count > i && judges[i] != null
                                                                        ? judges[i].Name.ToString()
                                                                        : "";
                            roomsTmpl.Assign("JUDGE" + (i + 1), name);
                        }

                        var gov          = venue.Gov;
                        var govName      = gov == null ? "?" : gov.TeamName;
                        var govPoints    = gov == null ? null : GetTeamAveragePoints(roundNum, gov);
                        var govPointsStr = govPoints == null ? "?" : OPDtabData.MiscHelpers.DoubleToStr(govPoints.Value);
                        roomsTmpl.Assign("GOV", govName);
                        roomsTmpl.Assign("GOVRESULT", govPointsStr);

                        var opp          = venue.Opp;
                        var oppName      = opp == null ? "?" : opp.TeamName;
                        var oppPoints    = opp == null ? null : GetTeamAveragePoints(roundNum, opp);
                        var oppPointsStr = oppPoints == null ? "?" : OPDtabData.MiscHelpers.DoubleToStr(oppPoints.Value);
                        roomsTmpl.Assign("OPP", oppName);
                        roomsTmpl.Assign("OPPRESULT", oppPointsStr);

                        var frees = venue.FreeSpeakers;

                        var free1          = frees.Count >= 1 ? frees[0] : null;
                        var free1Name      = free1 == null ? "?" : free1.Name.ToString();
                        var free1Result    = free1 == null ? null : GetDebaterAveragePoints(roundNum, free1);
                        var free1ResultStr = free1Result == null ? "?" : OPDtabData.MiscHelpers.DoubleToStr(free1Result.Value);
                        roomsTmpl.Assign("FREE1", free1Name);
                        roomsTmpl.Assign("FREE1RESULT", free1ResultStr);

                        var free2          = frees.Count >= 2 ? frees[1] : null;
                        var free2Name      = free2 == null ? "?" : free2.Name.ToString();
                        var free2Result    = free2 == null ? null : GetDebaterAveragePoints(roundNum, free2);
                        var free2ResultStr = free2Result == null ? "?" : OPDtabData.MiscHelpers.DoubleToStr(free2Result.Value);
                        roomsTmpl.Assign("FREE2", free2Name);
                        roomsTmpl.Assign("FREE2RESULT", free2ResultStr);

                        var free3          = frees.Count >= 3 ? frees[2] : null;
                        var free3Name      = free3 == null ? "?" : free3.Name.ToString();
                        var free3Result    = free3 == null ? null : GetDebaterAveragePoints(roundNum, free3);
                        var free3ResultStr = free3Result == null ? "?" : OPDtabData.MiscHelpers.DoubleToStr(free3Result.Value);
                        roomsTmpl.Assign("FREE3", free3Name);
                        roomsTmpl.Assign("FREE3RESULT", free3ResultStr);

                        roomsTmpl.Out();
                    }
                }

                MiscHelpers.AskShowTemplate(this,
                                            "Results Export successfully generated, see pdfs/round-results.csv.",
                                            MiscHelpers.MakeExportFromTemplate()
                                            );
            } catch (Exception ex) {
                MiscHelpers.ShowMessage(this,
                                        "Could not export Results: " + ex.Message, MessageType.Error);
            }
        }
Esempio n. 3
0
        void DoTheExport(MiscHelpers.TemplateType type)
        {
            try {
                ITemplate tmpl      = MiscHelpers.GetTemplate("ranking", type);
                string    separator = type == MiscHelpers.TemplateType.PDF ?
                                      "+" : "\",\"";
                ITmplBlock tmplTitle = tmpl.ParseBlock("TITLE");
                tmplTitle.Assign("V", Tournament.I.Title);
                tmplTitle.Out();

                ITmplBlock tmplTeams = tmpl.ParseBlock("TEAMS");
                int        pos       = 1;
                int        realPos   = 1;
                foreach (RankingDataItem item in teams)
                {
                    TeamData td = (TeamData)item.Data;
                    if (!(pos > 1 && teams[pos - 2].TotalPoints == item.TotalPoints))
                    {
                        realPos = pos;
                    }
                    tmplTeams.Assign("POS", realPos.ToString());
                    tmplTeams.Assign("NAME", td.TeamName);

                    List <int> speakerPos = new List <int>(3);
                    foreach (RoundDebater rd in td)
                    {
                        int realPos_ = 1;
                        for (int i = 0; i < speakers.Count; i++)
                        {
                            if (!(i > 0 && speakers[i - 1].TotalPoints == speakers[i].TotalPoints))
                            {
                                realPos_ = i + 1;
                            }
                            if (rd.Equals(speakers[i].Data))
                            {
                                speakerPos.Add(realPos_);
                            }
                        }
                    }
                    speakerPos.Sort();
                    ITmplBlock tmplSpeakerPos = tmpl.ParseBlock("SPEAKERPOS");
                    for (int i = 0; i < speakerPos.Count; i++)
                    {
                        tmplSpeakerPos.Assign("POS", speakerPos[i].ToString());
                        tmplSpeakerPos.Assign("SEP", i == speakerPos.Count - 1?"":separator);
                        tmplSpeakerPos.Out();
                    }


                    // we divide the avg by three to make it comparable to team position
                    tmplTeams.Assign("SPEAKERPOSAVG", item.AvgPoints < 0 ? "?" :
                                     OPDtabData.MiscHelpers.FmtDecimal(OPDtabData.MiscHelpers.CalcExactAverage(speakerPos) / 3)
                                     );

                    if (mBreakingTeams.Contains(pos - 1))
                    {
                        tmplTeams.Assign("BREAKMARK", "Break");
                    }
                    else
                    {
                        tmplTeams.Assign("BREAKMARK", "");
                    }
                    tmplTeams.Assign("POINTS", OPDtabData.MiscHelpers.DoubleToStr(item.TotalPoints));
                    ITmplBlock tmplPointsPerRound = tmpl.ParseBlock("POINTSPERROUNDTEAM");
                    int        nPoints            = 0;
                    if (item.RoundPoints.Count == 0)
                    {
                        tmplPointsPerRound.Assign("POINTS", "?");
                        tmplPointsPerRound.Assign("POS", "");
                        tmplPointsPerRound.Assign("SEP", "");
                        tmplPointsPerRound.Out();
                    }
                    else
                    {
                        for (int i = 0; i < item.RoundPoints.Count; i++)
                        {
                            string[] PosToStr = new string[] { "G", "O", "F" };
                            tmplPointsPerRound.Assign("POINTS", OPDtabData.MiscHelpers.DoubleToStr(item.RoundPoints[i]));
                            tmplPointsPerRound.Assign("POS",
                                                      PosToStr[(int)RoundResultData.PosToRoleType[item.RoundPositions[i]]]);
                            tmplPointsPerRound.Assign("SEP", i == item.RoundPoints.Count - 1?"":separator);
                            tmplPointsPerRound.Out();
                            nPoints++;
                        }
                    }
                    if (type == MiscHelpers.TemplateType.CSV)
                    {
                        // in CSV mode pad with more separators
                        for (int i = nPoints; i < Tournament.I.Rounds.Count; i++)
                        {
                            tmplPointsPerRound.Assign("POINTS", "");
                            tmplPointsPerRound.Assign("SEP", separator);
                            tmplPointsPerRound.Out();
                        }
                    }
                    tmplTeams.Out();
                    pos++;
                }

                ITmplBlock tmplSpeakers = tmpl.ParseBlock("SPEAKERS");
                pos     = 1;
                realPos = 1;
                foreach (RankingDataItem item in speakers)
                {
                    RoundDebater rd = (RoundDebater)item.Data;
                    if (!(pos > 1 && speakers[pos - 2].TotalPoints == item.TotalPoints))
                    {
                        realPos = pos;
                    }
                    tmplSpeakers.Assign("POS", realPos.ToString());
                    tmplSpeakers.Assign("NAME", rd.Name.FirstName + " " + rd.Name.LastName);
                    tmplSpeakers.Assign("POINTS", OPDtabData.MiscHelpers.DoubleToStr(item.TotalPoints));
                    if (mTeamSpeakers.Contains(pos - 1))
                    {
                        tmplSpeakers.Assign("BREAKMARK", "Team");
                    }
                    else if (mFreeSpeakers.Contains(pos - 1))
                    {
                        tmplSpeakers.Assign("BREAKMARK", "Tab");
                    }
                    else if (mBestSpeakers.Contains(pos - 1))
                    {
                        tmplSpeakers.Assign("BREAKMARK", "Raum");
                    }
                    else
                    {
                        tmplSpeakers.Assign("BREAKMARK", "");
                    }
                    tmplSpeakers.Assign("TEAMNAME", rd.Role.TeamName);

                    ITmplBlock tmplPointsPerRound = tmpl.ParseBlock("POINTSPERROUNDSPEAKER");
                    int        nPoints            = 0;
                    if (item.Points == null)
                    {
                        tmplPointsPerRound.Assign("POINTS", "?");
                        tmplPointsPerRound.Assign("POS", "");
                        tmplPointsPerRound.Assign("SEP", "");
                        tmplPointsPerRound.Out();
                    }
                    else
                    {
                        for (int i = 0; i < item.Points.Count; i++)
                        {
                            tmplPointsPerRound.Assign("POINTS",
                                                      OPDtabData.MiscHelpers.DoubleToStr(item.Points[i]));
                            tmplPointsPerRound.Assign("POS",
                                                      OPDtabData.MiscHelpers.IntToStr(item.RoundPositions[i] + 1));
                            tmplPointsPerRound.Assign("SEP", i == item.Points.Count - 1?"":separator);
                            tmplPointsPerRound.Out();
                            nPoints++;
                        }
                    }
                    if (type == MiscHelpers.TemplateType.CSV)
                    {
                        // in CSV mode pad with more separators
                        for (int i = nPoints; i < Tournament.I.Rounds.Count; i++)
                        {
                            tmplPointsPerRound.Assign("POINTS", "");
                            tmplPointsPerRound.Assign("POS", "");
                            tmplPointsPerRound.Assign("SEP", separator);
                            tmplPointsPerRound.Out();
                        }
                    }
                    tmplSpeakers.Assign("AVERAGEPOINTS", item.AvgPoints < 0 ? "?" :
                                        OPDtabData.MiscHelpers.FmtDecimal(item.AvgPoints));
                    tmplSpeakers.Out();
                    pos++;
                }
                MiscHelpers.AskShowTemplate(this,
                                            "Ranking Export successfully generated, see pdfs/ranking.(pdf|csv).",
                                            MiscHelpers.MakeExportFromTemplate()
                                            );
            }
            catch (Exception ex) {
                MiscHelpers.ShowMessage(this, "Could not export Ranking: " + ex.Message, MessageType.Error);
            }
        }