Example #1
0
    def _upload_problem(self, problem):
        """Uploads a specified problem to imgur.

        Returns:
            A tuple (str, (int, int)), where str is the url, on imgur and
            the tuples are the dimensions of the image (width, height).
        Raises:
           LatexParsingException : there was an issue parsing the document
        """
        default_doc = []
        # populate doc with the appropriate problem
        for line in problem[0]:
            # these first two statements are for wrapping the title around in a minipage which allows
            # the problem to be generated on one page and doesn't invoke \newpage
            if line == '\\begin{document}':
                default_doc.append(NoEscape(line))
                default_doc.append(NoEscape('\\begin{minipage}{\\textwidth}'))
            elif line == '\\maketitle':
                default_doc.append(NoEscape(line))
                default_doc.append(NoEscape('\\end{minipage}'))
            elif line == '\\end{itemize}':
                for line2 in problem[1]:
                    default_doc.append(NoEscape(line2))
                default_doc.append(NoEscape(line))
            else:
                default_doc.append(NoEscape(line))

        doc_class_line = NoEscape(default_doc[0])
        use_pkg_line = NoEscape(default_doc[1])
        # skip twocolumn since it makes the problem look spread awfully
        opts = filter(lambda pkg: pkg != 'twocolumn', doc_class_line[doc_class_line.find('[') + 1: doc_class_line.find(']')].split(','))
        args = NoEscape(doc_class_line[doc_class_line.find('{') + 1: doc_class_line.find('}')])
        doc = Document(documentclass=Command('documentclass', options=opts, arguments=args))
        # load packages
        doc.packages = [Package(i) for i in use_pkg_line[use_pkg_line.find('{') + 1: use_pkg_line.find('}')].split(',')]
        # position right after \begin{document}
        it = 4
        while default_doc[it].strip() != '\end{document}':
            doc.append(NoEscape(default_doc[it]))
            it += 1
        # fail safe for future problems which may not parse correctly
        try:
            doc.generate_pdf('default', compiler="pdflatex")
        except:
            raise LatexParsingException

        # These are normal Linux commands that are used to convert the pdf
        # file created by pylatex into a snippet
        os.system("pdfcrop default.pdf")
        os.system("pdftoppm default-crop.pdf|pnmtopng > default.png")
        path = os.path.abspath('default.png')
        uploaded_image = self._client.upload_image(path, title="LaTeX")
        return uploaded_image.link, OnlineImage.get_local_image_info(path)
Example #2
0
 def fromToken(self, s: Token):
     s = escape_latex(s.string)
     return NoEscape(s)
    def save_latex(self, reportsummary, filename, rel_path, Disp_3d_image):
        companyname = str(reportsummary["ProfileSummary"]['CompanyName'])
        companylogo = str(reportsummary["ProfileSummary"]['CompanyLogo'])
        groupteamname = str(reportsummary["ProfileSummary"]['Group/TeamName'])
        designer = str(reportsummary["ProfileSummary"]['Designer'])
        projecttitle = str(reportsummary['ProjectTitle'])
        subtitle = str(reportsummary['Subtitle'])
        jobnumber = str(reportsummary['JobNumber'])
        client = str(reportsummary['Client'])

        header = PageStyle("header")
        # Create center header
        with header.create(Head("C")):
            with header.create(Tabularx('|l|p{6cm}|l|X|')) as table:
                table.add_hline()
                # MultiColumn(4)
                table.add_row(('Company Name', companyname, 'Project Title',
                               projecttitle),
                              color='OsdagGreen')
                table.add_hline()
                table.add_row(
                    ('Group/Team Name', groupteamname, 'Subtitle', subtitle),
                    color='OsdagGreen')
                table.add_hline()
                table.add_row(('Designer', designer, 'Job Number', jobnumber),
                              color='OsdagGreen')
                table.add_hline()
                table.add_row(
                    ('Date', time.strftime("%d /%m /%Y"), 'Client', client),
                    color='OsdagGreen')
                table.add_hline()
        # Create right footer
        with header.create(Foot("R")):
            header.append(NoEscape(r'Page \thepage'))

        geometry_options = {
            "top": "1.2in",
            "bottom": "1in",
            "left": "0.6in",
            "right": "0.6in",
            "headsep": "0.8in"
        }
        doc = Document(geometry_options=geometry_options, indent=False)
        doc.packages.append(Package('amsmath'))
        doc.packages.append(Package('graphicx'))
        doc.packages.append(Package('needspace'))
        doc.add_color('OsdagGreen', 'HTML', 'D5DF93')
        doc.preamble.append(header)
        doc.change_document_style("header")

        with doc.create(Section('Design Conclusion')):
            with doc.create(Tabularx('|X|X|', row_height=1.2)) as table:
                table.add_hline()
                table.add_row(('Section Designation', 'Remarks'),
                              color='OsdagGreen')
                table.add_hline()
                table.add_row(
                    (reportsummary['Define Section']['Section Designation'],
                     'Pass'))
                table.add_hline()

        with doc.create(Section('Section Details')):
            with doc.create(Tabularx('|X|X|', row_height=1.2)) as table:
                table.add_hline()
                table.add_row(
                    (bold('Section Type'),
                     reportsummary['Define Section']['Section Type']))
                table.add_hline()
                table.add_row(
                    (bold('Section Template'),
                     reportsummary['Define Section']['Section Template']))
                table.add_hline()

        with doc.create(Section('Section Parameters')):
            with doc.create(Tabularx('|X|X|', row_height=1.2)) as table:
                for parameter in reportsummary['Define Section'][
                        'Section Parameters']:
                    para = reportsummary['Define Section'][
                        'Section Parameters'][parameter]
                    table.add_hline()
                    table.add_row((bold(para[0]), para[1]))
                table.add_hline()

        labels = [
            'Area, a(cm²)',
            'Moment of Inertia',
            'I_zz(cm4)',
            'I_yy(cm4)',
            'Radius of Gyration',
            'r_zz(cm)',
            'r_yy(cm)',
            'Centriod',
            'c_z(cm)',
            'c_y(cm)',
            'Plastic Section modulus',
            'Z_pz(cm³)',
            'Z_py(cm³)',
            'Elastic Section modulus',
            'Z_zz(cm³)',
            'Z_yy(cm³)',
        ]
        values = list(reportsummary['Section Properties'].values())
        Properties = [
            (labels[0], values[0]),
            (labels[1], ""),
            (labels[2], values[1]),
            (labels[3], values[2]),
            (labels[4], ""),
            (labels[5], values[3]),
            (labels[6], values[4]),
            (labels[7], ""),
            (labels[8], values[5]),
            (labels[9], values[6]),
            (labels[10], ""),
            (labels[11], values[7]),
            (labels[12], values[8]),
            (labels[13], ""),
            (labels[14], values[9]),
            (labels[15], values[10]),
        ]

        with doc.create(Section('Section Properties')):
            with doc.create(Tabularx('|X|X|', row_height=1.2)) as table:
                for ppty in Properties:
                    table.add_hline()
                    table.add_row((bold(ppty[0]), ppty[1]))
                table.add_hline()
        doc.append(NewPage())

        if (not 'TRAVIS' in os.environ):
            with doc.create(Section('3D View')):
                with doc.create(Figure(position='h!')) as view_3D:
                    view_3dimg_path = rel_path + Disp_3d_image
                    # view_3D.add_image(filename=view_3dimg_path, width=NoEscape(r'\linewidth'))
                    view_3D.add_image(filename=view_3dimg_path)

                    view_3D.add_caption('3D View')
        try:
            doc.generate_pdf(filename, compiler='pdflatex', clean_tex=False)
        except:
            pass
Example #4
0
    def _report_attack_configuration(self):
        """Create subsubsection about the attack and data configuration."""
        # Create tables for attack parameters and the data configuration.
        ap = self.attack_pars
        dc = self.data_conf
        self.report_section.append(Subsubsection("Attack Details"))
        with self.report_section.create(MiniPage()):
            with self.report_section.create(MiniPage(width=r"0.49\textwidth")):
                # -- Create table for the attack parameters.
                self.report_section.append(Command("centering"))
                with self.report_section.create(Tabular("|l|c|")) as tab_ap:
                    tab_ap.add_hline()
                    tab_ap.add_row(["Number of classes", ap["number_classes"]])
                    tab_ap.add_hline()
                    tab_ap.add_row([
                        "Number of shadow models", ap["number_shadow_models"]
                    ])
                    tab_ap.add_hline()
                    tab_ap.add_row([
                        "Shadow training set size",
                        ap["shadow_training_set_size"],
                    ])
                    tab_ap.add_hline()
                    tab_ap.add_row(["Shadow epochs", ap["shadow_epochs"]])
                    tab_ap.add_hline()
                    tab_ap.add_row(
                        ["Shadow batch size", ap["shadow_batch_size"]])
                    tab_ap.add_hline()
                    tab_ap.add_row(["Attack epochs", ap["attack_epochs"]])
                    tab_ap.add_hline()
                    tab_ap.add_row(
                        ["Attack batch size", ap["attack_batch_size"]])
                    tab_ap.add_hline()
                self.report_section.append(
                    Command("captionsetup", "labelformat=empty"))
                self.report_section.append(
                    Command(
                        "captionof",
                        "table",
                        extra_arguments="Attack parameters",
                    ))

            with self.report_section.create(MiniPage(width=r"0.49\textwidth")):
                # -- Create table for the data configuration
                self.report_section.append(Command("centering"))
                nr_targets, target_training_set_size = dc[
                    "record_indices_per_target"].shape
                with self.report_section.create(Tabular("|l|c|")) as tab_dc:
                    tab_dc.add_hline()
                    tab_dc.add_row([
                        NoEscape("Samples used to train shadow models ($S$)"),
                        len(dc["shadow_indices"]),
                    ])
                    tab_dc.add_hline()
                    tab_dc.add_row([
                        NoEscape("Samples used to train target models ($T$)"),
                        len(dc["target_indices"]),
                    ])
                    tab_dc.add_hline()
                    tab_dc.add_row([
                        "Samples used to evaluate the attack",
                        len(dc["evaluation_indices"]),
                    ])
                    tab_dc.add_hline()
                    tab_dc.add_row(["Attacked target models", nr_targets])
                    tab_dc.add_hline()
                    tab_dc.add_row([
                        "Target model's training sets size",
                        target_training_set_size
                    ])
                    tab_dc.add_hline()
                    tab_dc.add_row([
                        NoEscape("Size of $S \cap T$"),
                        len(
                            set(dc["shadow_indices"])
                            & set(dc["target_indices"])),
                    ])
                    tab_dc.add_hline()
                self.report_section.append(
                    Command("captionsetup", "labelformat=empty"))
                self.report_section.append(
                    Command(
                        "captionof",
                        "table",
                        extra_arguments="Target and Data Configuration",
                    ))
def gameStadistic(size,train_steps, turnPlayer,agent, agent2,train = 0 ,save_games = False,visualize = True):
    total_games = 1
    if train == 0:
        print("How many games:")
        while(True):
            try:
                total_games = input("Select number: ")
                total_games = int(total_games)
                assert total_games > 0, "Number must be positive."
                break
            except:
                print("You must choose a number")
    player1 = [0]
    player2 = [0]
    replay = []
    for j in range(total_games):
        round = 0
        model = Model(tup=(None,) * size**2, turn=True, winner=None,size = size ,terminal=False)
        if train == 0:
            print("Playing",j,"of",total_games)
        game = []
        while(True):
            #Check if a player won or tie
            if mvc._find_winner(model.tup,size) == True:
                player1.append(player1[-1] + 1)
                player2.append(player2[-1])
                break
            elif mvc._find_winner(model.tup,size) == False:
                player1.append(player1[-1])
                player2.append(player2[-1] +1)
                break
            elif mvc._isTie(size,round):
                player1.append(player1[-1])
                player2.append(player2[-1])
                break
            #Playing the game
            if turnPlayer.playerTurn() == player.typePlayer.IA_PLAYER:
                for _ in range(train_steps):
                    agent.do_rollout(model)
                model = agent.choose(model)
            elif turnPlayer.playerTurn() == player.typePlayer.IA_PLAYER_2:
                for _ in range(train_steps):
                    agent2.do_rollout(model)
                model = agent2.choose(model)
            round +=1
            if save_games:
                game.append(copy.copy(model))
            turnPlayer.newTurn()
        turnPlayer.reset()
        replay.append(game.copy())
    gamesPlayed = np.arange(total_games+1)

    #Create Report
    doc = Document('basic')
    doc.preamble.append(Command('title', 'Game report'))
    doc.preamble.append(Command('author', 'Tic Tac Toe'))
    doc.preamble.append(Command('date', NoEscape(r'\today')))
    doc.append(NoEscape(r'\maketitle'))

    with doc.create(Section('Introducction')):
            doc.append(bold('This document was autogenerate. '))
            doc.append('Here we present the result between two agents after ' + str(total_games) + 'games.')
            doc.append(' This document present graphs with the victories of the agents and the total points obtain.')
            doc.append(' The agent 1 is ' + agent.agent_name + ' and the agent 2 is ' + agent2.agent_name + '. ')
            date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            doc.append(bold('Document generate ' + date  + '.'))

    with doc.create(Section('Agent 1: ' + agent.agent_name)):
            doc.append(NoEscape(agent.agent_description))
    with doc.create(Section('Agent 2: ' + agent2.agent_name)):
            doc.append(NoEscape(agent2.agent_description))
    with doc.create(Section('Victories count')):
        doc.append('In this secction we can see the plot with the point counts of each agent.')
        with doc.create(Figure(position='htbp')) as plot:
            df = pd.DataFrame({
                "Games Played": gamesPlayed,
                "Player 1: "+ turnPlayer.PLAYER1: player1,
                "Player 2: "+ turnPlayer.PLAYER2: player2
            })
            ax = df.plot.area(x="Games Played",stacked=False)
            plot.add_plot()
            plot.add_caption('Points per agent.')
            #plt.close()
    if visualize:
        plt.show()

    doc.generate_pdf('Reports/game_report', clean_tex=True)


    if save_games:
        return replay
Example #6
0
def de_texsign(s: tokens.TeXSign):
    return NoEscape('\\TeX')
Example #7
0
def de_footnote(s: tokens.Footnote):
    line = cache.get_footnote(s.token_str)
    return NoEscape(r"\footnote{{{}}}".format(''.join(
        [de_token(c) for c in line.children])))
Example #8
0
def de_in_code(s: tokens.InCode):
    return tex.in_code(NoEscape(''.join(de_token(c) for c in s.inner_token)))
Example #9
0
def de_raw_line(c: lines.Raw):
    return NoEscape(''.join([de_token(c) for c in c.children]))
Example #10
0
    def print_to_pdf(self,
                     matrices: list,
                     color_matrices: list,
                     filename=None,
                     add_borders=True):
        if filename == None:
            filename = self.pdf_filename

        doc = Document()
        doc.packages.append(Package('xcolor', options='table'))
        doc.packages.append(Package('transparent'))
        # doc.packages.append(Package('geometry', options='margin=0.5in'))
        doc.append(NoEscape('\setcounter{secnumdepth}{0}'))
        doc.append(NoEscape('\pagenumbering{gobble}'))
        doc.append(NoEscape('\setlength{\\arrayrulewidth}{1pt}'))
        # define colors from color dict
        colors = ColorMatrix()
        for color in colors.strDict:
            doc.append(NoEscape(colors.strDict[color]))

        today = date.today()
        with doc.create(
                Section(
                    NoEscape('{\\fontsize{20pt}{15pt}\selectfont' +
                             ' Randomly generated numbers collected on ' +
                             str(today) + ' and adapted from:}'))):
            doc.append(
                NoEscape(
                    '{\\fontsize{14pt}{12pt}\selectfont' +
                    ' https://onlinemathtools.com/generate-random-matrix}'))

        with doc.create(
                Section(
                    NoEscape(
                        '{\\fontsize{20pt}{15pt}\selectfont' +
                        ' Zoom color palette shuffled with and adapted from:}')
                )):
            doc.append(
                NoEscape('{\\fontsize{14pt}{12pt}\selectfont' +
                         ' https://onlinerandomtools.com/shuffle-words}'))
            doc.append(NoEscape("\\newpage"))

        for i in range(len(matrices)):
            M = matrices[i]
            C = color_matrices[i]
            # set the specs for the table that holds the matrix entries
            if add_borders:
                border = '|'
            else:
                border = ''

            with doc.create(Subsection('Option #' + str(i + 1))):
                ############ create number table
                with doc.create(
                        Tabular(border + border.join(['c' for t in M[0]]) +
                                border)) as table:
                    if add_borders:
                        table.add_hline()
                    for row in M:
                        # if there are negative entries, put a + in front of positives
                        if (M < 0).any():
                            row = [
                                '+' + str(num) if num >= 0 else '–' +
                                str(-1 * num) for num in row
                            ]
                            if "+0" in row:
                                row[row.index("+0")] = '0'
                                # NoEscape('\cellcolor{green}0')

                        table.add_row(row)
                        if add_borders:
                            table.add_hline()

                # doc.append(NoEscape("\hfill")) # same line right side
                doc.append(NoEscape("\\break"))  # new line
                doc.append(NoEscape("\\vspace{1cm}"))  # new line
                # doc.append('.') # new line
                doc.append(NoEscape("\\break"))  # new line
                ############ create color table
                # fin correct table width
                if (M < 0).any():
                    if (M > 1000).any():
                        spacer = '23.2'
                    else:
                        spacer = '23.1'
                else:
                    spacer = '10'

                with doc.create(
                        Tabular(
                            border +
                            border.join(['m{' + spacer + 'px}'
                                         for t in C[0]]) + border)) as table:
                    if add_borders:
                        table.add_hline()
                    for row in C:
                        table.add_row([
                            NoEscape('\cellcolor{' + color + '}')
                            for color in row
                        ])
                        if add_borders:
                            table.add_hline()

        doc.generate_pdf(filename, clean_tex=False)
Example #11
0
def make_doc(preamble="preamble.tex"):
    doc = Document(fontenc=None)
    if preamble is not None:
        doc.preamble.append(NoEscape(open(preamble).read()))
    doc.append(Command("ignorespaces"))
    return doc
Example #12
0
def read_one(texfile):
    raw = open(texfile).read()
    return NoEscape(raw.replace("\n\n", ""))
Example #13
0
def tabela_previsao_orcamentaria(doc, enum, previsao_orcamentaria):
    item(doc, enum, NoEscape(r'PREVISÃO ORÇAMENTÁRIA: \\'))

    # TODO: blank=True para os DecimalField
    inscricoes = previsao_orcamentaria.inscricoes or 0
    convenios = previsao_orcamentaria.convenios or 0
    patrocinios = previsao_orcamentaria.patrocinios or 0
    fonte_financiamento = previsao_orcamentaria.fonte_financiamento or 0
    honorarios = previsao_orcamentaria.honorarios or 0
    passagens = previsao_orcamentaria.passagens or 0
    alimentacao = previsao_orcamentaria.alimentacao or 0
    hospedagem = previsao_orcamentaria.hospedagem or 0
    divulgacao = previsao_orcamentaria.divulgacao or 0
    material_consumo = previsao_orcamentaria.material_consumo or 0
    xerox = previsao_orcamentaria.xerox or 0
    certificados = previsao_orcamentaria.certificados or 0
    outros = previsao_orcamentaria.outros or 0
    outros_especificacao = previsao_orcamentaria.outros_especificacao or ''
    # TODO: não estão sendo usadas
    # fundacao           = previsao_orcamentaria.fundacao or ''
    # outro_orgao_gestor = previsao_orcamentaria.outro_orgao_gestor or ''

    total_receitas = (inscricoes + convenios + patrocinios +
                      fonte_financiamento)

    total_despesas = (honorarios + passagens + alimentacao + hospedagem +
                      divulgacao + material_consumo + xerox + certificados +
                      outros)

    with doc.create(Tabularx('|' + 'X|' * 4,
                             width_argument=WIDTH_ARGUMENT)) as tab:
        tab.add_hline()

        tab.add_row(MultiColumn(2, data=bold('Receitas'), align='|c|'),
                    MultiColumn(2, data=bold('Despesas'), align='c|'))
        tab.add_hline()

        tab.add_row('Inscrições', inscricoes, 'Honorários', honorarios)
        tab.add_hline()

        tab.add_row('Convênios', convenios, 'Passagens', passagens)
        tab.add_hline()

        tab.add_row('Patrocínios', patrocinios, 'Alimentação', alimentacao)
        tab.add_hline()

        tab.add_row('Fonte(s) de financiamento', fonte_financiamento,
                    'Hospedagem', hospedagem)
        tab.add_hline()

        tab.add_row('', '', 'Divulgação', divulgacao)
        tab.add_hline()

        tab.add_row('', '', 'Material de consumo', material_consumo)
        tab.add_hline()

        tab.add_row('', '', 'Xerox', xerox)
        tab.add_hline()

        tab.add_row('', '', 'Certificados', certificados)
        tab.add_hline()

        tab.add_row('', '', 'Outros (especificar)',
                    '{}\n{}'.format(str(outros), outros_especificacao))
        tab.add_hline()

        tab.add_row(bold('Total'), total_receitas,
                    MultiRow(2, data=bold('Total')),
                    MultiRow(2, data=total_despesas))
        doc.append(UnsafeCommand('cline', '1-2'))

        # TODO: não tem atributo para saldo previsto na classe PrevisaoOrcamentaria_CursoExtensao
        tab.add_row(bold('Saldo previsto'), '', '', '')
        tab.add_hline()
Example #14
0
def popular_servidores(doc, servidor, docente_cursoextensao=None):
    with doc.create(MdFramed(options=MDFRAMED_OPTIONS)):
        doc.append(bold(NoEscape(r'SERVIDORES UNIOESTE \\')))

        doc.append(
            NoEscape(r'Nome completo: {} \\'.format(
                escape_latex(servidor.nome_completo))))

        if servidor.__class__ == AgenteUniversitario_CursoExtensao:
            for tipo_docente in TipoDocente.objects.all():
                doc.append(
                    NoEscape(r'({}) {} '.format(PHANTOM, tipo_docente.nome)))
            doc.append(
                NoEscape(r'({}) {} \\'.format(TIMES, 'Agente Universitário')))
        else:
            for tipo_docente in TipoDocente.objects.all():
                if docente_cursoextensao.docente.tipo_docente.id == tipo_docente.id:
                    doc.append(
                        NoEscape(r'({}) {} '.format(TIMES, tipo_docente.nome)))
                else:
                    doc.append(
                        NoEscape(r'({}) {} '.format(PHANTOM,
                                                    tipo_docente.nome)))
            doc.append(
                NoEscape(r'({}) {} \\'.format(PHANTOM,
                                              'Agente Universitário')))

        # TODO: regime_trabalho
        #  doc.append('Regime de trabalho: ')
        #  doc.append(servidor.regime_trabalho)
        #  doc.append(NoEscape('\ hora(s)'))

        if docente_cursoextensao:
            carga_horaria = docente_cursoextensao.carga_horaria_dedicada
        else:
            carga_horaria = servidor.carga_horaria_dedicada
        doc.append(
            NoEscape(
                r'Carga horária semanal dedicada à atividade: {} hora(s) \\'.
                format(carga_horaria)))

        doc.append(
            NoEscape(r'Colegiado: {} \\'.format(
                escape_latex(servidor.colegiado))))

        doc.append(NoEscape(r'Centro: {} \\'.format(servidor.centro.nome)))

        # TODO: unidade_administrativa
        #  doc.append('Unidade Administrativa: ')
        #  for unidade in UnidadeAdministrativa.objects.all():
        #      if agente_cursoextensao.unidade_administrativa and
        #          agente_cursoextensao.unidade_administrativa.id == unidade.id:
        #          doc.append(NoEscape(r'({}) {} '.format(TIMES, unidade.nome)))
        #      else:
        #          doc.append(NoEscape(r'({}) {} '.format(PHANTOM, unidade.nome)))

        #  if agente_cursoextensao.campus:
        #      doc.append(NoEscape(r'({}) CAMPUS DE: {}'.format(TIMES, agente_cursoextensao.campus.nome)))
        #  else:
        #      doc.append(NoEscape(r'({}) CAMPUS DE: '.format(PHANTOM)))
        #  doc.append(NewLine())

        doc.append(
            NoEscape(r'E-mail: {} \\'.format(escape_latex(servidor.email))))

        doc.append(
            NoEscape(r'Telefone: {} \\'.format(escape_latex(
                servidor.telefone))))

        doc.append(
            NoEscape(r'Endereço: {}, {} -- {} -- {} \\'.format(
                escape_latex(servidor.logradouro),
                escape_latex(servidor.cidade), escape_latex(servidor.estado),
                escape_latex(servidor.pais))))

        with doc.create(MdFramed(options=MDFRAMED_OPTIONS)):
            doc.append(NoEscape(r'Função: \\'))
            if docente_cursoextensao:
                tabela_alternativas(doc,
                                    FuncaoServidor,
                                    'XXX',
                                    id=docente_cursoextensao.funcao.id,
                                    hline=False)
            else:
                tabela_alternativas(doc,
                                    FuncaoServidor,
                                    'XXX',
                                    id=servidor.funcao.id,
                                    hline=False)

        doc.append(Command('bigskip'))
        doc.append(Command('bigskip'))
        doc.append(
            NoEscape(r'Assinatura do participante: \hrulefill \\ \\ \\'))
        doc.append(
            NoEscape(r'Assinatura da chefia imediata: \hrulefill \\ \\'))

        doc.append(bold('PLANO DE TRABALHO: '))
        if docente_cursoextensao:
            doc.append(escape_latex(docente_cursoextensao.plano_trabalho))
        else:
            doc.append(escape_latex(servidor.plano_trabalho))
Example #15
0
def tabela_area_tematica_secundaria(doc, enum, id=None):
    item(doc, enum, NoEscape(r'ÁREA TEMÁTICA SECUNDÁRIA: \\'))
    tabela_alternativas(doc, AreaTematica, '|X|X|X|', id=id)
Example #16
0
def de_under_line(s: tokens.UnderLine):
    return tex.under_line(
        NoEscape(''.join([de_token(c) for c in s.inner_token])))
Example #17
0
def de_normal(c: lines.Normal):
    content = NoEscape("".join([de_token(c) for c in c.children]))
    return content
Example #18
0
def de_hyperlink(s: tokens.Hyperlink):
    from urllib.parse import urljoin
    desc, link = NoEscape(''.join([de_token(c)
                                   for c in s.inner_token])), s.link
    link = urljoin('http:', link)
    return NoEscape(r"\href{{{}}}{{{}}}".format(link, desc))
Example #19
0
def de_empty(_):
    return NoEscape("\n")
Example #20
0
def de_sign(s: tokens.Sign):
    tex_sign = sign_to_tex.get(s.token_str, 'unknown')
    if isinstance(s.parent, tokens.InFormula) or isinstance(
            s.parent.parent, env.Formula):
        return NoEscape(tex_sign)
    return NoEscape('$' + tex_sign + '$')
Example #21
0
def de_xml(c: lines.XML):
    if c.tag == 'title':
        cache.title = NoEscape(r"\title{{{}}}".format(c.content))
    elif c.tag == 'author':
        cache.author = NoEscape(r"\author{{{}}}".format(c.content))
    return NoEscape('')
Example #22
0
def de_latexsign(s: tokens.LaTeXSign):
    return NoEscape('\\LaTeX')
Example #23
0
def de_normal(s: tokens.Normal):
    return NoEscape(escape_latex(''.join(s.inner_token)))
Example #24
0
                                        LineHeight * 2)
                    dz.FigWording(xlabel='',
                                  ylabel='',
                                  title=element_lines[j],
                                  graph_axis=dz.Axis[j])

                #Label with theoretical flux:
                target_lines = ['N2_6548A', 'N2_6584A']
                if reduc_lineslog_df.index.isin(target_lines).sum() == len(
                        target_lines):
                    ratio = reduc_lineslog_df.loc[
                        'N2_6584A'].line_Int / reduc_lineslog_df.loc[
                            'N2_6548A'].line_Int
                    label = 'Galaxy {}: nitrogen lines observed ratio: ${:L}$'.format(
                        objName.replace('_', '-'), ratio)
                    label = NoEscape(label)
                else:
                    label = (r'Galaxy {}: Nitrogen lines:'.format(
                        objName.replace('_', '-')))
                    for k in range(len(element_lines)):
                        label_line = ' {} ${:L}$ '.format(
                            element_lines[k].replace('_', ' '),
                            reduc_lineslog_df.loc[element_lines[k]].line_Int)
                        label += label_line
                    label = NoEscape(label)

                plt.tight_layout()
                dz.fig_to_pdf(label=label, add_page=True)
                dz.reset_fig()

            #------Plot Sulfur lines
Example #25
0
def de_bold(s: tokens.Bold):
    return bold(NoEscape(''.join([de_token(c) for c in s.inner_token])),
                escape=False)
Example #26
0
    def _report_attack_results(self, save_path):
        """
        Create subsubsection describing the most important results of the attack.

        Parameters
        ----------
        save_path :
            Path to save the tex, pdf and asset files of the attack report.

        This subsection contains results only for the first target model.
        """
        tm = 0  # Specify target model
        self.report_section.append(Subsubsection("Attack Results"))
        res = self.attack_results

        # ECDF graph (like in paper)
        precision_sorted = np.sort(res["precision_list"], axis=0)[:, tm]
        recall_sorted = np.sort(res["recall_list"], axis=0)[:, tm]
        py = np.arange(1, len(precision_sorted) + 1) / len(precision_sorted)
        ry = np.arange(1, len(recall_sorted) + 1) / len(recall_sorted)

        fig = plt.figure()
        ax = plt.axes()
        ax.set_xlabel("Accuracy")
        ax.set_ylabel("Cumulative Fraction of Classes")
        ax.plot(precision_sorted, py, "k-", label="Precision")
        ax.plot(recall_sorted, ry, "k--", label="Recall")
        ax.legend()

        alias_no_spaces = str.replace(self.attack_alias, " ", "_")
        fig.savefig(save_path + f"/fig/{alias_no_spaces}-ecdf.pdf",
                    bbox_inches="tight")
        plt.close(fig)

        with self.report_section.create(MiniPage()):
            with self.report_section.create(MiniPage(width=r"0.49\textwidth")):
                self.report_section.append(Command("centering"))
                self.report_section.append(
                    Command(
                        "includegraphics",
                        NoEscape(f"fig/{alias_no_spaces}-ecdf.pdf"),
                        "width=8cm",
                    ))
                self.report_section.append(
                    Command("captionsetup", "labelformat=empty"))
                self.report_section.append(
                    Command(
                        "captionof",
                        "figure",
                        extra_arguments="Empirical CDF",
                    ))

            tp_row = []
            fp_row = []
            tn_row = []
            fn_row = []
            class_row = []
            precision_row = []
            accuracy_row = []
            recall_row = []

            # Average column
            class_row.append(f"0-{self.attack_pars['number_classes']-1}")
            tp_row.append(
                np.round(
                    np.sum(res["tp_list"], axis=0)[tm] / len(res["tp_list"]),
                    2))
            fp_row.append(
                np.round(
                    np.sum(res["fp_list"], axis=0)[tm] / len(res["fp_list"]),
                    2))
            tn_row.append(
                np.round(
                    np.sum(res["tn_list"], axis=0)[tm] / len(res["tn_list"]),
                    2))
            fn_row.append(
                np.round(
                    np.sum(res["fn_list"], axis=0)[tm] / len(res["fn_list"]),
                    2))
            accuracy_row.append(
                np.round(
                    np.sum(res["eval_accuracy_list"], axis=0)[tm] /
                    len(res["eval_accuracy_list"]),
                    3,
                ))
            precision_row.append(
                np.round(
                    np.sum(res["precision_list"], axis=0)[tm] /
                    len(res["precision_list"]),
                    3,
                ))
            recall_row.append(
                np.round(
                    np.sum(res["recall_list"], axis=0)[tm] /
                    len(res["recall_list"]), 3))

            # Maximum accuracy class
            max_class = np.argmax(res["eval_accuracy_list"], axis=0)[tm]
            class_row.append(max_class)
            tp_row.append(res["tp_list"][max_class][tm])
            fp_row.append(res["fp_list"][max_class][tm])
            tn_row.append(res["tn_list"][max_class][tm])
            fn_row.append(res["fn_list"][max_class][tm])
            accuracy_row.append(
                np.round(res["eval_accuracy_list"][max_class][tm], 3))
            precision_row.append(
                np.round(res["precision_list"][max_class][tm], 3))
            recall_row.append(np.round(res["recall_list"][max_class][tm], 3))

            # Minimum accuracy class
            min_class = np.argmin(res["eval_accuracy_list"], axis=0)[tm]
            class_row.append(min_class)
            tp_row.append(res["tp_list"][min_class][tm])
            fp_row.append(res["fp_list"][min_class][tm])
            tn_row.append(res["tn_list"][min_class][tm])
            fn_row.append(res["fn_list"][min_class][tm])
            accuracy_row.append(
                np.round(res["eval_accuracy_list"][min_class][tm], 3))
            precision_row.append(
                np.round(res["precision_list"][min_class][tm], 3))
            recall_row.append(np.round(res["recall_list"][min_class][tm], 3))

            with self.report_section.create(MiniPage(width=r"0.49\textwidth")):
                self.report_section.append(Command("centering"))
                with self.report_section.create(
                        Tabular("|l|c|c|c|")) as result_tab:
                    result_tab.add_hline()
                    result_tab.add_row(
                        list(
                            map(
                                bold,
                                [
                                    "",
                                    "Average",
                                    "max. Acc.",
                                    "min. Acc.",
                                ],
                            )))
                    result_tab.add_hline()
                    result_tab.add_row(
                        ["Class", class_row[0], class_row[1], class_row[2]])
                    result_tab.add_hline()
                    result_tab.add_row(
                        ["True Positives", tp_row[0], tp_row[1], tp_row[2]])
                    result_tab.add_hline()
                    result_tab.add_row(
                        ["False Positives", fp_row[0], fp_row[1], fp_row[2]])
                    result_tab.add_hline()
                    result_tab.add_row(
                        ["True Negatives", tn_row[0], tn_row[1], tn_row[2]])
                    result_tab.add_hline()
                    result_tab.add_row(
                        ["False Negatives", fn_row[0], fn_row[1], fn_row[2]])
                    result_tab.add_hline()
                    result_tab.add_row([
                        "Accuracy", accuracy_row[0], accuracy_row[1],
                        accuracy_row[2]
                    ])
                    result_tab.add_hline()
                    result_tab.add_row([
                        "Precision",
                        precision_row[0],
                        precision_row[1],
                        precision_row[2],
                    ])
                    result_tab.add_hline()
                    result_tab.add_row([
                        "Recall", recall_row[0], recall_row[1], recall_row[2]
                    ])
                    result_tab.add_hline()
                self.report_section.append(
                    Command("captionsetup", "labelformat=empty"))
                self.report_section.append(
                    Command("captionof",
                            "table",
                            extra_arguments="Attack Summary"))

        ap = self.attack_pars

        # Histograms
        fig, (ax0, ax1, ax2) = plt.subplots(1, 3, sharey=True, figsize=(12, 3))
        ax0.hist(res["eval_accuracy_list"][:, tm], edgecolor="black")
        ax1.hist(res["precision_list"][:, tm], edgecolor="black")
        ax2.hist(res["recall_list"][:, tm], edgecolor="black")
        ax0.set_xlabel("Accuracy")
        ax1.set_xlabel("Precision")
        ax2.set_xlabel("Recall")
        ax0.set_ylabel("Number of Classes")
        ax0.tick_params(axis="x", labelrotation=45)
        ax1.tick_params(axis="x", labelrotation=45)
        ax2.tick_params(axis="x", labelrotation=45)
        ax0.set_axisbelow(True)
        ax1.set_axisbelow(True)
        ax2.set_axisbelow(True)

        alias_no_spaces = str.replace(self.attack_alias, " ", "_")
        fig.savefig(save_path +
                    f"/fig/{alias_no_spaces}-accuracy_precision_recall.pdf",
                    bbox_inches="tight")
        plt.close(fig)

        with self.report_section.create(Figure(position="H")) as fig:
            fig.add_image(
                f"fig/{alias_no_spaces}-accuracy_precision_recall.pdf",
                width=NoEscape(r"\textwidth"))
            self.report_section.append(
                Command("captionsetup", "labelformat=empty"))
            self.report_section.append(
                Command(
                    "captionof",
                    "figure",
                    extra_arguments=
                    "Accuracy, precision and recall histogram for all "
                    "attack models",
                ))
Example #27
0
def de_italic(s: tokens.Italic):
    return italic(NoEscape(''.join([de_token(c) for c in s.inner_token])),
                  escape=False)
            colors_dict[calib_frame_by_time] = next(color_cycler)

#-----------Create the table
#Create the doc
doc = Document(dz.reducFolders['reduc_data'] + 'closest_star')
doc.packages.append(
    Package('geometry',
            options=['left=1cm', 'right=1cm', 'top=1cm', 'bottom=1cm']))
doc.packages.append(Package('preview', options=['active', 'tightpage']))
doc.packages.append(Package('color', options=[
    'usenames',
    'dvipsnames',
]))

#Table pre-commands
doc.append(NoEscape(r'\begin{table*}[h]'))
doc.append(NoEscape(r'\begin{preview}'))
doc.append(NoEscape(r'\centering'))
doc.append(NoEscape(r'\pagenumbering{gobble}'))

#Table header
table_format = 'lllllllll'

#Elements we want to put in the table
idces_table = (dz.reducDf.frame_tag.isin(
    dz.observation_dict['objects'] + dz.observation_dict['Standard_stars'] +
    ['flat', 'arc'])) & (dz.reducDf.file_location.str.contains('/raw_fits/'))
file_names = dz.reducDf[idces_table].sort_values(['RUN']).file_name.values
file_folders = dz.reducDf[idces_table].sort_values(['RUN'
                                                    ]).file_location.values
RA_values = dz.reducDf[idces_table].sort_values(['RUN']).RA.values
Example #29
0
def de_bold_italic(s: tokens.BoldItalic):
    return bold(
        italic(NoEscape(''.join([de_token(c) for c in s.inner_token])),
               escape=False))
Example #30
0
 def fromDeleteLine(self, s: DeleteLine):
     s = escape_latex(s.string)
     return NoEscape(rf"\sout{{{s}}}")
Example #31
0
def de_delete_line(s: tokens.DeleteLine):
    return tex.delete_line(NoEscape(''.join(
        [de_token(c) for c in s.inner_token])),
                           escape=False)