Beispiel #1
0
    def ontask(self, task):
        """ Some additional supplies for the latex format
        """
        super(CEOITemplate, self).ontask(task)
        # Register contestheader.tex as \taskheader
        shutil.copyfile(os.path.join(os.path.dirname(__file__),
                                     "contestheader.tex"),
                        os.path.join(task.wdir, "contestheader.tex"))
        task.supply("latex", def_latex("taskheader",
                                       input_latex("contestheader.tex")))

        # Register translation.tex as \translationheader
        shutil.copyfile(os.path.join(os.path.dirname(__file__),
                                     "translation.tex"),
                        os.path.join(task.wdir, "translation.tex"))
        task.supply("latex", def_latex("translationheader",
                                       input_latex("translation.tex")))

        # Tell LaTeX where watermark can be found
        shutil.copyfile(os.path.join(os.path.dirname(__file__),
                                     "ceoi-watermark.png"),
                        os.path.join(task.wdir, "ceoi-watermark.png"))
        task.supply("latex", def_latex("watermark", "ceoi-watermark.png"))

        # Tell Latex where bar.pdf can be found
        shutil.copy(os.path.join(self.contest.wdir, "bar.pdf"),
                    os.path.join(task.wdir, "bar.pdf"))
        task.supply("latex", def_latex("barpdf", "bar.pdf"))

        shutil.copyfile(os.path.join(os.path.dirname(__file__),
                                     "ceoistyle.asy"),
                        os.path.join(task.wdir, "ceoistyle.asy"))

        self.mktestcasetable(task)
Beispiel #2
0
    def ontask(self, task):
        """ Some additional supplies for the latex format
        """
        super(BOITemplate, self).ontask(task)

        #Provide access to the BOI logo
        shutil.copy(
            os.path.join(os.path.dirname(__file__),
                         "header{}.pdf".format(self.year)),
            os.path.join(os.getcwd(), "header.pdf"))

        # Copy translation headers
        copyrecursivelyifnecessary(os.path.join(task.wdir, "..", "general"),
                                   os.path.join(task.wdir, "general"))

        # Register contestheader.tex as \taskheader
        shutil.copy(
            os.path.join(os.path.dirname(__file__), "contestheader.tex"),
            os.path.join(task.wdir, "taskheader.tex"))
        task.supply("latex",
                    def_latex("taskheader", input_latex("taskheader.tex")))

        task.supply("latex", def_latex("olympiadyear", self.year))

        self.mktestcasetable(task)
Beispiel #3
0
    def ontask(self, task):
        """ Some additional supplies for the latex format
        """
        super(CEOITemplate, self).ontask(task)
        # Register contestheader.tex as \taskheader
        shutil.copyfile(
            os.path.join(os.path.dirname(__file__), "contestheader.tex"),
            os.path.join(task.wdir, "contestheader.tex"))
        task.supply("latex",
                    def_latex("taskheader", input_latex("contestheader.tex")))

        # Register translation.tex as \translationheader
        shutil.copyfile(
            os.path.join(os.path.dirname(__file__), "translation.tex"),
            os.path.join(task.wdir, "translation.tex"))
        task.supply(
            "latex",
            def_latex("translationheader", input_latex("translation.tex")))

        # Tell LaTeX where watermark can be found
        shutil.copyfile(
            os.path.join(os.path.dirname(__file__), "ceoi-watermark.png"),
            os.path.join(task.wdir, "ceoi-watermark.png"))
        task.supply("latex", def_latex("watermark", "ceoi-watermark.png"))

        # Tell Latex where bar.pdf can be found
        shutil.copy(os.path.join(self.contest.wdir, "bar.pdf"),
                    os.path.join(task.wdir, "bar.pdf"))
        task.supply("latex", def_latex("barpdf", "bar.pdf"))

        shutil.copyfile(
            os.path.join(os.path.dirname(__file__), "ceoistyle.asy"),
            os.path.join(task.wdir, "ceoistyle.asy"))

        self.mktestcasetable(task)
Beispiel #4
0
    def ontask(self, task):
        """ Some additional supplies for the latex format
        """
        super(LgTemplate, self).ontask(task)

        # Provide access to our graphdrawing headers
        shutil.copy(os.path.join(os.path.dirname(__file__), "paths.tex"),
                    os.path.join(task.wdir, "paths.tex"))
        shutil.copy(os.path.join(os.path.dirname(__file__), "paths.lua"),
                    os.path.join(task.wdir, "paths.lua"))
        shutil.copy(
            os.path.join(os.path.dirname(__file__), "graphdrawing.tex"),
            os.path.join(task.wdir, "graphdrawing.tex"))
        shutil.copy(
            os.path.join(os.path.dirname(__file__), "graphdrawing.lua"),
            os.path.join(task.wdir, "graphdrawing.lua"))

        # Provide access to our logo
        shutil.copy(os.path.join(os.path.dirname(__file__), "logo.eps"),
                    os.path.join(task.wdir, "logo.eps"))

        # Register contestheader.tex as \taskheader
        shutil.copy(
            os.path.join(os.path.dirname(__file__), "contestheader.tex"),
            os.path.join(task.wdir, "taskheader.tex"))
        task.supply("latex",
                    def_latex("taskheader", input_latex("taskheader.tex")))

        # Provide translation-{de,en}.tex
        shutil.copy(
            os.path.join(os.path.dirname(__file__), "translation-de.tex"),
            os.path.join(task.wdir, "translation-de.tex"))
        shutil.copy(
            os.path.join(os.path.dirname(__file__), "translation-en.tex"),
            os.path.join(task.wdir, "translation-en.tex"))

        # Provide common asy files
        shutil.copyfile(
            os.path.join(os.path.dirname(__file__), "graphics.cfg"),
            "graphics.cfg")
        shutil.copyfile(os.path.join(os.path.dirname(__file__), "mystyle.asy"),
                        "mystyle.asy")

        task.supply("latex", def_latex("feedback", task.feedback))

        score_mode = task.score_mode()
        task.supply("latex",
                    def_latex("scoring", self.score_mode_year(score_mode)))

        task.supply("latex", r"\newcount\numsubtasks ")
        task.supply("latex", lambda: r"\numsubtasks={}".\
                                         format(len(task.subtasks) - 1))

        task.supply("latex", r"\newif\ifrestricted")
        if task._has_restricted_feedback_level():
            task.supply("latex", r"\restrictedtrue")

        self.mktestcasetable(task)
Beispiel #5
0
    def ontask(self, task):
        """ Some additional supplies for the latex format
        """
        super(LgTemplate, self).ontask(task)

        # Provide access to our graphdrawing headers
        shutil.copy(os.path.join(os.path.dirname(__file__), "paths.tex"),
                    os.path.join(task.wdir, "paths.tex"))
        shutil.copy(os.path.join(os.path.dirname(__file__), "paths.lua"),
                    os.path.join(task.wdir, "paths.lua"))
        shutil.copy(os.path.join(os.path.dirname(__file__), "graphdrawing.tex"),
                    os.path.join(task.wdir, "graphdrawing.tex"))
        shutil.copy(os.path.join(os.path.dirname(__file__), "graphdrawing.lua"),
                    os.path.join(task.wdir, "graphdrawing.lua"))

        # Register contestheader.tex as \taskheader
        shutil.copy(os.path.join(os.path.dirname(__file__),
                                 "contestheader.tex"),
                    os.path.join(task.wdir, "taskheader.tex"))
        task.supply("latex", def_latex("taskheader",
                                       input_latex("taskheader.tex")))
        # Register translation.tex as \translationheader
        shutil.copyfile(os.path.join(os.path.dirname(__file__),
                                     "translation.tex"),
                        os.path.join(task.wdir, "translation.tex"))
        task.supply("latex", def_latex("translationheader",
                                       input_latex("translation.tex")))
        # Compile bar.asy
        shutil.copyfile(os.path.join(os.path.dirname(__file__), "graphics.cfg"),
                        "graphics.cfg")
        shutil.copyfile(os.path.join(os.path.dirname(__file__), "mystyle.asy"),
                        "mystyle.asy")
        shutil.copyfile(os.path.join(os.path.dirname(__file__), "logo.eps"),
                        "logo.eps")
        shutil.copyfile(os.path.join(os.path.dirname(__file__), "bar.asy"),
                        "bar.asy")
        task.supply_asy("lg", self.contest.simple_query("lg"))
        task.supply_asy("taskname", task.simple_query("name"))
        task.supplement_file("asy", "info.asy")
        task.compile("bar.asy")

        # Tell Latex where bar.pdf can be found
        task.supply("latex", def_latex("barpdf", "bar.pdf"))

        task.supply("latex", def_latex("feedback", task.feedback))

        task.supply("latex", r"\newcount\numsubtasks ")
        task.supply("latex", lambda: r"\numsubtasks={}".\
                                         format(len(task.subtasks) - 1))

        task.supply("latex", r"\newif\ifrestricted")
        if task._has_restricted_feedback_level():
            task.supply("latex", r"\restrictedtrue")

        self.mktestcasetable(task)
Beispiel #6
0
    def ontask(self, task):
        super(PlainTemplate, self).ontask(task)
        self.supply_cases(task)
        task.supplement_file("latex", "taskinfo.tex")
        shutil.copy(os.path.join(os.path.dirname(__file__), "header.tex"),
                    os.path.join(task.wdir, "header.tex"))
        shutil.copy(os.path.join(os.path.dirname(__file__), 
                                 "taskinfo-base.tex"),
                    os.path.join(task.wdir, "taskinfo-base.tex"))
        task.supply("latex", r"\input{taskinfo-base.tex}")
        task.supply("latex", def_latex("basicheader",
                                       input_latex("header.tex")))
        task.supply_latex("taskname", task.simple_query("name"))
        task.supply_latex("contestname",
                          task.contest.simple_query("_description"))
        task.supply_latex("timelimit", task.latex_timelimit)
        task.supply_latex("memlimit", task.latex_memorylimit)
        task.supply_latex("inputwidth",
                          functools.partial(self.inputwidth, task))
        task.supply_latex("outputwidth",
                          functools.partial(self.outputwidth, task))

        self.initconstraint(task)
        self.initsubtaskinfo(task)
        self.mktestcasetable(task)
Beispiel #7
0
    def supply_case_table(self, task,
                          start="\\begin{tabular}{|p{\\inputwidth}|"
                                "p{\\outputwidth}|}\n\\hline Input & Output "
                                "\\\\\\hline",
                          end="\\end{tabular}",
                          beforeeachcell="\\vspace{-2ex}",
                          aftereachcell="\\vspace{-2ex}",
                          aftereachline="\\\\\\hline",
                          sep="&"):
        """ Create a customized testcase table
        """
        def tct():
            r = ""
            r += start
            for i in range(1, len(task.saved) + 1):
                r += beforeeachcell + "\\tcin{" + str(i) + "}" + aftereachcell
                r += sep
                r += beforeeachcell + "\\tcout{" + str(i) + "}" + aftereachcell
                r += aftereachline
            r += end
            return r

        def tcn():
            return "\\newcount\\numsamples \\numsamples={}".format(
                len(task.saved))

        task.supply("latex", def_latex("testcasetable", tct))
        task.supply("latex", tcn)
Beispiel #8
0
    def ontask(self, task):
        super(PlainTemplate, self).ontask(task)

        def si(x, y):
            return "\\SI{" + str(x) + "}{" + str(y) + "}"

        task.latex_timelimit = lambda: si(task._timelimit, "s")
        task.latex_memorylimit = lambda: si(task._memorylimit, "MiB")

        self.supply_cases(task)
        task.supplement_file("latex", "taskinfo.tex")
        shutil.copy(os.path.join(os.path.dirname(__file__), "header.tex"),
                    os.path.join(task.wdir, "header.tex"))
        shutil.copy(
            os.path.join(os.path.dirname(__file__), "taskinfo-base.tex"),
            os.path.join(task.wdir, "taskinfo-base.tex"))
        task.supply("latex", r"\input{taskinfo-base.tex}")
        task.supply("latex", def_latex("basicheader",
                                       input_latex("header.tex")))
        task.supply_latex("taskname", task.simple_query("name"))
        task.supply_latex("contestname", self.get_contestname)
        task.supply_latex("timelimit", task.latex_timelimit)
        task.supply_latex("memlimit", task.latex_memorylimit)
        task.supply_latex("inputwidth",
                          functools.partial(self.inputwidth, task))
        task.supply_latex("outputwidth",
                          functools.partial(self.outputwidth, task))

        self.initconstraint(task)
        self.initsubtaskinfo(task)
        self.mktestcasetable(task)
Beispiel #9
0
    def supply_case_table(self,
                          task,
                          start="\\begin{tabular}{|p{\\inputwidth}|"
                          "p{\\outputwidth}|}\n\\hline Input & Output "
                          "\\\\\\hline",
                          end="\\end{tabular}",
                          beforeeachcell="\\vspace{-2ex}",
                          aftereachcell="\\vspace{-2ex}",
                          aftereachline="\\\\\\hline",
                          sep="&"):
        """ Create a customized testcase table
        """
        def tct():
            r = ""
            r += start
            for i in range(1, len(task.saved) + 1):
                r += beforeeachcell + "\\tcin{" + str(i) + "}" + aftereachcell
                r += sep
                r += beforeeachcell + "\\tcout{" + str(i) + "}" + aftereachcell
                r += aftereachline
            r += end
            return r

        def tcn():
            return "\\newcount\\numsamples \\numsamples={}".format(
                len(task.saved))

        task.supply("latex", def_latex("testcasetable", tct))
        task.supply("latex", tcn)
Beispiel #10
0
    def __init__(self, contest):
        super(CEOITemplate, self).__init__(contest)
        self.contest = contest

        # Compile bar.asy
        shutil.copyfile(os.path.join(os.path.dirname(__file__), "bar.asy"),
                        "bar.asy")

        contest.supply("latex",
                       def_latex("contestday", contest.simple_query("day")))
        contest.supplement_file("asy", "info.asy")
        contest.compile("bar.asy")
Beispiel #11
0
    def __init__(self, contest):
        super(CEOITemplate, self).__init__(contest)
        self.contest = contest

        # Compile bar.asy
        shutil.copyfile(os.path.join(os.path.dirname(__file__), "bar.asy"),
                        "bar.asy")

        contest.supply("latex", def_latex("contestday",
                                          contest.simple_query("day")))
        contest.supplement_file("asy", "info.asy")
        contest.compile("bar.asy")
Beispiel #12
0
    def make_overview_sheets(self):
        """
        Print overview sheets in two versions (with tasks and all contestants
        of any individual team in one file OR without tasks and all contestants
        separately) and ZIP them together
        """
        if self.contest.ignore_latex:
            return

        teams = {}
        contestants_with_language = {}
        overview_sheets_for = {}

        assert (all(t._feedback_level == FEEDBACK_LEVEL_RESTRICTED
                    for t in self.contest.tasks.values()))
        assert (all(t.score_mode() == SCORE_MODE_MAX_SUBTASK
                    for t in self.contest.tasks.values()))

        prefix = "overview-sheets-for"

        for u in self.contest.users.values():
            team = u.team

            if team not in teams:
                teams[team] = []
            teams[team].append(u)

            for l in u.primary_statements:
                if l not in contestants_with_language:
                    contestants_with_language[l] = []
                contestants_with_language[l].append(u)

        if not os.path.exists("overview"):
            os.mkdir("overview")

        copyrecursivelyifnecessary(
            os.path.join(self.contest.wdir, "general"),
            os.path.join(self.contest.wdir, "overview", "general"))

        self.contest.supply("contestoverview",
                            def_latex("olympiadyear", self.year))

        import csv
        printingunwanted = dict()
        requestsfile = "printingrequested.csv"
        if os.path.exists(requestsfile):
            with open(requestsfile, encoding='utf-8-sig') as f:
                reader = csv.DictReader(f, delimiter=',', quotechar='"')
                for row in reader:
                    c, l = row["Country"], row["Language"]
                    if c not in printingunwanted:
                        printingunwanted[c] = dict()
                    printingunwanted[c]["en"] = row["English"] == "No"
                    printingunwanted[c][l] = row["Own"] == "No"

        with chdir("overview"):
            if not os.path.exists(".overviews-per-language"):
                os.mkdir(".overviews-per-language")

            with chdir(".overviews-per-language"):
                for l, users in contestants_with_language.items():
                    if self.contest.relevant_language and \
                        self.contest.relevant_language != l:
                        continue

                    self.supply_overview()
                    self.contest._build_supplements_for_key("contestoverview")

                    #Provide access to the BOI logo
                    shutil.copy(
                        os.path.join(os.path.dirname(__file__),
                                     "header{}.pdf".format(self.year)),
                        os.path.join(os.getcwd(), "header.pdf"))

                    def do_supply_language():
                        return self.language_supplement(l)

                    def do_supply_credentials():
                        return "\n".join("\\printoverviewpage{%s}{%s, %s}{%s}" % \
                            (u.username, u.lastname, u.firstname, u.password)
                            for u in users)

                    self.contest.supply("lang", do_supply_language)
                    self.contest.supply("credentials", do_supply_credentials)

                    filename = prefix + "-" + l + ".tex"

                    shutil.copy(
                        os.path.join(os.path.dirname(__file__),
                                     "overview-template.tex"), filename)
                    self.contest._build_supplements_for_key("credentials")
                    self.contest._build_supplements_for_key("lang")

                    pdf = PdfFileReader(self.contest.compile(filename))
                    assert (pdf.getNumPages() == len(users))

                    for i, u in enumerate(users):
                        overview_sheets_for[(u.username, l)] = pdf.getPage(i)

                    self.contest.supplements["lang"].parts.clear()
                    self.contest.supplements["credentials"].parts.clear()

            def cleardoublepage(stream):
                if stream.getNumPages() % 2 == 1:
                    stream.addBlankPage()

            for team, users in teams.items():
                if not os.path.exists(team.code):
                    os.mkdir(team.code)

                with chdir(team.code):
                    hw = PdfFileWriter()

                    for u in users:
                        # Overview sheets
                        ow = PdfFileWriter()

                        for l in u.primary_statements:
                            if self.contest.relevant_language and \
                                self.contest.relevant_language != l:
                                continue
                            ow.addPage(overview_sheets_for[(u.username, l)])
                        with open("overview-" + u.username + ".pdf",
                                  "wb") as f:
                            ow.write(f)

                        # handout
                        for l in u.primary_statements:
                            if self.contest.relevant_language and \
                                self.contest.relevant_language != l:
                                continue
                            if printingunwanted \
                                .get(team.name, dict()) \
                                .get(l, False):
                                print_msg("Not adding translation to language "
                                          "{} for user {} to the handout "
                                          "as requested by team {}".format(
                                              l, u.username, team.code))
                                hw.addPage(overview_sheets_for[(u.username,
                                                                l)])
                                cleardoublepage(hw)
                                continue
                            hw.addPage(overview_sheets_for[(u.username, l)])
                            cleardoublepage(hw)

                            for t in sorted(self.contest.tasks.values(),
                                            key=lambda x: x.name):
                                if l in t._statements:
                                    st = PdfFileReader(t._statements[l].file_)
                                    hw.appendPagesFromReader(st)
                                    cleardoublepage(hw)

                    with open("handout.pdf", "wb") as f:
                        hw.write(f)

                job = {
                    "overview-" + u.username + ".pdf":
                    os.path.join(team.code, "overview-" + u.username + ".pdf")
                    for u in users
                }
                job["handout.pdf"] = os.path.join(team.code, "handout.pdf")

                r = ZipRule(os.path.join("..", ".rules"),
                            team.code + "-all.zip", job).ensure()
Beispiel #13
0
    def supply_overview(self):
        # Task information
        task_list = sorted(self.contest.tasks.values(), key=lambda x: x.name)

        thead = ["\\tName", "\\tTaskType", "\\tTimeLimit", "\\tMemoryLimit"]
        tbody = []

        show_score_mode_col = len(set(t.score_mode() for t in task_list)) > 1
        score_map = {}
        score_list = []

        if show_score_mode_col:
            thead.append("\\tScoring")

        show_max_score_col = len(set(t.max_score() for t in task_list)) > 1

        if show_max_score_col:
            thead.append("\\tMaxScore")

        for t in task_list:
            tbody.append([
                "\\ttfamily " + t.name, "\\tTT" + t.tasktype,
                t.latex_timelimit(),
                t.latex_memorylimit()
            ])

            scm = t.score_mode()

            if scm not in score_map:
                score_map[scm] = len(score_map) + 1
                score_list.append("\\tScoringFrom" + self.score_mode_year(scm))

            if show_score_mode_col:
                tbody[-1].append("(%d)" % score_map[scm])

            if show_max_score_col:
                tbody[-1].append("$%d$" % t.max_score())

        def mcol(i, h):
            coltype = "c"
            colentry = h
            colsep = "&&"

            if i == 0:
                coltype = "|" + coltype
                colentry = "\\kern4pt" + colentry

            if i == len(thead) - 1:
                coltype = coltype + "|"
                colentry = colentry + "\\kern4pt"
                colsep = ""

            return "\\multicolumn{1}{%s}{%s}%s" % (coltype, colentry, colsep)

        thead_string = "\\begin{tabular}{" + \
            "@{\\hskip0pt}p{.52cm}@{\\hskip0pt}".join(["c"] * len(thead)) + \
            "}\\noalign{\\hrule}" + "".join(mcol(i,h) for i,h
                                                      in enumerate(thead)) + \
            "\\\\" + "\\noalign{\\hrule}"

        def trow(l):
            return "\\noalign{\\smallskip}" + \
                   "&&".join("\\cellcolor[gray]{.9}\\hbox{\\vrule height 14pt "
                             "depth 9.2pt width 0pt}" + x for x in l) + "\\\\"

        tbody_string = "\n".join(trow(l) for l in tbody)

        task_overview = "\\subsection*{\\tTasks}" + thead_string + \
                            tbody_string + "\\end{tabular}"

        if not show_max_score_col and len(task_list) > 0:
            task_overview += "\\par\\medskip\\tMaxScoreGeneral{$%d$}" % \
                                     task_list[0].max_score()

        self.contest.supply("contestoverview",
                            def_latex("printtaskoverview", task_overview))

        # Scoring information
        if len(score_list) == 1:
            score_info = score_list[0] + "general"
        elif len(score_list) > 1:
            score_info = "\\tScoringIntroduction\n\\begin{enumerate}" + \
                         "\n".join("\\item " + scm for scm in score_list) + \
                         "\\end{enumerate}"
        else:
            score_info = ""
        score_info = "\\subsection*{\\tScoring}\n" + score_info

        self.contest.supply("contestoverview",
                            def_latex("printscoring", score_info))
        self.contest.supply("contestoverview",
                            def_latex("contestname", self.get_contestname))
Beispiel #14
0
 def supply_latex(self, name, f):
     self.supply("latex", def_latex(name, escape_latex(f)))