Пример #1
0
def generate_pdf(stroka):
    pdf_path = get_dir('odli_pdf') + '\\' +stroka.Surname +' '+ stroka.Firstname +' '+ stroka.Patronymic
    logo_image = r'miaclogo.png'

    pdf = Document(pdf_path)
    pdf.packages.add(Package('babel',options='russian'))
    pdf.packages.add(Package('pdfx', options= NoEscape('a-1b') ))
    pdf.packages.add(Package('inputenc',options='utf8'))
    pdf.packages.add(Package('fontenc',options='T2A'))
    pdf.packages.add(Package('geometry',options='a5paper'))

    first_page = PageStyle("firstpage")
    with first_page.create(Head("L")) as header_left:
        with header_left.create(MiniPage(width=NoEscape(r"0.49\textwidth"),pos='l')) as logo_wrapper:
            logo_wrapper.append(StandAloneGraphic(image_options="width=120px",filename=logo_image))
        with header_left.create(MiniPage(width=NoEscape(r"0.49\textwidth"),pos='c')) as logo_wrapper:
            logo_wrapper.append(NoEscape("Сгенерированно в СПб ГБУЗ МИАЦ"))
            logo_wrapper.append(NewLine())
            logo_wrapper.append(NoEscape("В основе данные, предоставленные лабораториями"))
    pdf.preamble.append(first_page)

    pdf.change_document_style("firstpage")
    pdf.add_color(name="lightgray", model="gray", description="0.80")
    pdf.append(HorizontalSpace(size="500px"))
    with pdf.create(Section(NoEscape("Исследование на COVID-19"),numbering=False)):
        pdf.append(NoEscape("Наименование лаборатории: " + stroka.Name_Lab ))
        pdf.append(NewLine())
        pdf.append(NoEscape("Дата исследования: " + stroka.Date_Test))
        pdf.append(NewLine())
        pdf.append(NoEscape("Ответственный за исследование: "))
        pdf.append(NewLine())
        pdf.append(NoEscape(stroka.lab_familia +' '+ stroka.lab_name +' '+ stroka.lab_secondname))
    with pdf.create(Section(NoEscape("Пациент: ") ,numbering=False)):
        pdf.append(LargeText(NoEscape(stroka.Surname +' '+ stroka.Firstname +' '+ stroka.Patronymic)))
        pdf.append(NewLine())
        pdf.append(NewLine())
        pdf.append(NoEscape("Дата рождения: " + stroka.Birthday))
        pdf.append(NewLine())
        pdf.append(NoEscape("Паспорт: " + stroka.Passport))
        pdf.append(NewLine())
        pdf.append(NoEscape("СНИЛС: " + stroka.Snils))
        pdf.append(NewLine())
        pdf.append(NoEscape("ОМС: " + stroka.Policy_OMS))
        pdf.append(NewLine())
        pdf.append(NoEscape("Контактный номер: " + stroka.Phone))
        pdf.append(NewLine())
    with pdf.create(Section(NoEscape("Результат: "),numbering=False)):
        pdf.append(NoEscape("Качественное обнаружение короновируса SARS 2 в различных образцах: "))
        pdf.append(NewLine())
        pdf.append(NewLine())
        if stroka.Result_Test == 'ND':
            pdf.append(TextColor('green',LargeText(NoEscape('Не обнаружено'))))
        if stroka.Result_Test == 'DET':
            pdf.append(TextColor('red',LargeText(NoEscape('Обнаружено'))))

    pdf.generate_pdf(clean_tex=True,compiler='pdflatex')

    with open(pdf_path+'.pdf', "rb") as pdf_file:
        encoded_pdf = base64.b64encode(pdf_file.read()).decode()
    return encoded_pdf
Пример #2
0
    def render_table(self,
                     doc: Document,
                     name_override: Optional[LatexObject] = None,
                     toc_ref: Optional[str] = None,
                     extra_rows: Optional[List[Tuple[str, Any]]] = None) -> None:
        """Write this table into a LaTeX document.

        Args:
            doc: The LaTeX document to be appended to.
            name_override: An optional replacement for this table's name field.
            toc_ref: A reference to be added to the table of contents.
            extra_rows: Any extra rows to be added to the table before the kwargs.
        """
        with doc.create(Table(position='htp!')) as table:
            table.append(NoEscape(r'\refstepcounter{table}'))
            table.append(Label(Marker(name=str(self.fe_id), prefix="tbl")))
            if toc_ref:
                table.append(NoEscape(r'\addcontentsline{toc}{subsection}{' + escape_latex(toc_ref) + '}'))
            with doc.create(Tabularx('|lX|', booktabs=True)) as tabular:
                package = Package('xcolor', options='table')
                if package not in tabular.packages:
                    # Need to invoke a table color before invoking TextColor (bug?)
                    tabular.packages.append(package)
                package = Package('seqsplit')
                if package not in tabular.packages:
                    tabular.packages.append(package)
                tabular.add_row((name_override if name_override else bold(self.name),
                                 MultiColumn(size=1, align='r|', data=TextColor('blue', self.fe_id))))
                tabular.add_hline()
                type_str = f"{self.type}"
                match = re.fullmatch(r'^<.* \'(?P<typ>.*)\'>$', type_str)
                type_str = match.group("typ") if match else type_str
                tabular.add_row(("Type: ", escape_latex(type_str)))
                if self.path:
                    if isinstance(self.path, LatexObject):
                        tabular.add_row(("", self.path))
                    else:
                        tabular.add_row(("", escape_latex(self.path)))
                for k, v in self.fields.items():
                    tabular.add_hline()
                    tabular.add_row((f"{k.capitalize()}: ", v))
                if self.args:
                    tabular.add_hline()
                    tabular.add_row(("Args: ", self.args))
                if extra_rows:
                    for (key, val) in extra_rows:
                        tabular.add_hline()
                        tabular.add_row(key, val)
                if self.kwargs:
                    tabular.add_hline()
                    for idx, (kwarg, val) in enumerate(self.kwargs.items()):
                        tabular.add_row((italic(kwarg), val), color='white' if idx % 2 else 'black!5')
Пример #3
0
def test_basic():
    # Tests the basic commands and environments
    # Basic commands
    new_page = NewPage()
    repr(new_page)

    new_line = NewLine()
    repr(new_line)

    line_break = LineBreak()
    repr(line_break)

    h_fill = HFill()
    repr(h_fill)

    # Basic environments
    huge = HugeText("Huge")
    huge.append("Huge 2")
    repr(huge)

    large = LargeText("Large")
    large.append("Large 2")
    repr(large)

    medium = MediumText("Medium")
    medium.append("Medium 2")
    repr(medium)

    small = SmallText("Small")
    small.append("Small 2")
    repr(small)

    footnote = FootnoteText("Footnote")
    footnote.append("Footnote 2")
    repr(footnote)

    text_color = TextColor("green", "GreenText")
    text_color.append("More Green Text")
    repr(text_color)
Пример #4
0
def test_basic():
    # Tests the basic commands and environments
    # Basic commands
    new_page = NewPage()
    repr(new_page)

    new_line = NewLine()
    repr(new_line)

    line_break = LineBreak()
    repr(line_break)

    h_fill = HFill()
    repr(h_fill)

    # Basic environments
    huge = HugeText("Huge")
    huge.append("Huge 2")
    repr(huge)

    large = LargeText("Large")
    large.append("Large 2")
    repr(large)

    medium = MediumText("Medium")
    medium.append("Medium 2")
    repr(medium)

    small = SmallText("Small")
    small.append("Small 2")
    repr(small)

    footnote = FootnoteText("Footnote")
    footnote.append("Footnote 2")
    repr(footnote)

    text_color = TextColor("green", "GreenText")
    text_color.append("More Green Text")
    repr(text_color)
Пример #5
0
def writeQuestion(doc, question, result, figpie, figbar):
    doc.append(TextColor("blue",question))
    width_pie = NoEscape(r"{}\textwidth".format(settings.scale_pie))
    width_bar = NoEscape(r"{}\textwidth".format(settings.scale_bar))
    
    with doc.create(Figure(position="H")) as main_fig:    
        with doc.create(SubFigure(position='b')) as left_fig:
            left_fig.add_image(settings.fig_path + figbar, width = width_bar, placement=NoEscape("\centering"))
            left_fig.add_caption("")        
        #doc.append(HFill())    
        with doc.create(SubFigure(position='b')) as right_fig:
            right_fig.add_image(settings.fig_path + figpie, width = width_pie, placement=NoEscape("\centering"))
            right_fig.add_caption("")        
        main_fig.add_caption("")
Пример #6
0
def create_latex_file(pokemon, list_of_normal_ivs, list_of_boosted_ivs):
    geometry_options = {
        "landscape": True,
        "margin": "0.5in",
        "headheight": "20pt",
        "headsep": "10pt",
        "includeheadfoot": True
    }

    doc = Document(page_numbers=True, geometry_options=geometry_options)

    doc.add_color('color100', 'rgb', rgb_to_dumb_string(0, 207, 194))
    doc.add_color('color98', 'rgb', rgb_to_dumb_string(60, 141, 1))
    doc.add_color('color96', 'rgb', rgb_to_dumb_string(72, 165, 6))
    doc.add_color('color93', 'rgb', rgb_to_dumb_string(242, 183, 8))
    doc.add_color('color91', 'rgb', rgb_to_dumb_string(246, 96, 0))

    section = Section(f'{pokemon.name} IV Chart')

    table = Tabular('|c|c|c|c|c|c|', row_height=1.5)
    table.add_hline()
    table.add_row((MultiColumn(
        6, align='|c|', data=TextColor('white',
                                       pokemon.name), color='black'), ), )

    table.add_row(
        (MultiColumn(1, align='|c',
                     data='Lv20'), MultiColumn(1, align='c|', data='Lv25'),
         MultiColumn(3, align='c|',
                     data='IV'), MultiColumn(1, align='|c|', data='%')))

    for index in range(len(list_of_normal_ivs)):
        n_iv = list_of_normal_ivs[index]
        b_iv = list_of_boosted_ivs[index]

        row_data = (f'{n_iv.cp}', f'{b_iv.cp}', f'{n_iv.attack}',
                    f'{n_iv.defense}', f'{n_iv.stamina}',
                    f'{n_iv.perfection_percent_rounded}')

        table.add_hline()
        table.add_row(row_data,
                      color=color_by_iv(n_iv.perfection_percent_rounded))

    section.append(table)
    doc.append(section)

    doc.generate_tex(f'latex/{pokemon.name}')
    doc.generate_pdf(f'pdf/{pokemon.name}')
Пример #7
0
def save_report(model, file_name, detailed_traces=2):
    print('Saving analytics report to {}.tex and {}.pdf'.format(
        file_name, file_name))

    inference_network = model._inference_network
    iter_per_sec = inference_network._total_train_iterations / inference_network._total_train_seconds
    traces_per_sec = inference_network._total_train_traces / inference_network._total_train_seconds
    traces_per_iter = inference_network._total_train_traces / inference_network._total_train_iterations
    train_loss_initial = inference_network._history_train_loss[0]
    train_loss_final = inference_network._history_train_loss[-1]
    train_loss_change = train_loss_final - train_loss_initial
    train_loss_change_per_sec = train_loss_change / inference_network._total_train_seconds
    train_loss_change_per_iter = train_loss_change / inference_network._total_train_iterations
    train_loss_change_per_trace = train_loss_change / inference_network._total_train_traces
    valid_loss_initial = inference_network._history_valid_loss[0]
    valid_loss_final = inference_network._history_valid_loss[-1]
    valid_loss_change = valid_loss_final - valid_loss_initial
    valid_loss_change_per_sec = valid_loss_change / inference_network._total_train_seconds
    valid_loss_change_per_iter = valid_loss_change / inference_network._total_train_iterations
    valid_loss_change_per_trace = valid_loss_change / inference_network._total_train_traces

    sys.stdout.write(
        'Generating report...                                           \r')
    sys.stdout.flush()

    geometry_options = {
        'tmargin': '1.5cm',
        'lmargin': '1cm',
        'rmargin': '1cm',
        'bmargin': '1.5cm'
    }
    doc = Document('basic', geometry_options=geometry_options)
    doc.preamble.append(NoEscape(r'\usepackage[none]{hyphenat}'))
    doc.preamble.append(NoEscape(r'\usepackage{float}'))
    # doc.preamble.append(NoEscape(r'\renewcommand{\familydefault}{\ttdefault}'))

    doc.preamble.append(Command('title', 'pyprob analytics: ' + model.name))
    doc.preamble.append(
        Command(
            'date',
            NoEscape(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))))
    doc.append(NoEscape(r'\maketitle'))
    # doc.append(NoEscape(r'\small'))

    print('Analytics: Current system')
    with doc.create(Section('Current system', numbering=False)):
        with doc.create(Tabularx('ll')) as table:
            table.add_row(('pyprob version', __version__))
            table.add_row(('PyTorch version', torch.__version__))

    # doc.append(NoEscape(r'\newpage'))
    print('Analytics: Inference network')
    with doc.create(Section('Inference network', numbering=False)):
        print('Analytics: Inference network.File')
        with doc.create(Section('File')):
            with doc.create(Tabularx('ll')) as table:
                # table.add_row(('File name', file_name))
                # file_size = '{:,}'.format(os.path.getsize(file_name))
                # table.add_row(('File size', file_size + ' Bytes'))
                table.add_row(('Created', inference_network._created))
                table.add_row(('Modified', inference_network._modified))
                table.add_row(('Updates to file', inference_network._updates))
        print('Analytics: Inference network.Training')
        with doc.create(Section('Training')):
            with doc.create(Tabularx('ll')) as table:
                table.add_row(
                    ('pyprob version', inference_network._pyprob_version))
                table.add_row(
                    ('PyTorch version', inference_network._torch_version))
                table.add_row(('Trained on', inference_network._trained_on))
                table.add_row(('Total training time', '{0}'.format(
                    util.days_hours_mins_secs_str(
                        inference_network._total_train_seconds))))
                table.add_row(
                    ('Total training traces',
                     '{:,}'.format(inference_network._total_train_traces)))
                table.add_row(('Traces / s', '{:,.2f}'.format(traces_per_sec)))
                table.add_row(
                    ('Traces / iteration', '{:,.2f}'.format(traces_per_iter)))
                table.add_row(
                    ('Iterations',
                     '{:,}'.format(inference_network._total_train_iterations)))
                table.add_row(
                    ('Iterations / s', '{:,.2f}'.format(iter_per_sec)))
                table.add_row(('Optimizer', inference_network._optimizer_type))
                table.add_row(('Validation set size',
                               inference_network._valid_batch.length))
        print('Analytics: Inference network.Training loss')
        with doc.create(Subsection('Training loss')):
            with doc.create(Tabularx('ll')) as table:
                table.add_row(
                    ('Initial loss', '{:+.6e}'.format(train_loss_initial)))
                table.add_row(
                    ('Final loss', '{:+.6e}'.format(train_loss_final)))
                table.add_row(('Loss change / s',
                               '{:+.6e}'.format(train_loss_change_per_sec)))
                table.add_row(('Loss change / iteration',
                               '{:+.6e}'.format(train_loss_change_per_iter)))
                table.add_row(('Loss change / trace',
                               '{:+.6e}'.format(train_loss_change_per_trace)))
        print('Analytics: Inference network.Validation loss')
        with doc.create(Subsection('Validation loss')):
            with doc.create(Tabularx('ll')) as table:
                table.add_row(
                    ('Initial loss', '{:+.6e}'.format(valid_loss_initial)))
                table.add_row(
                    ('Final loss', '{:+.6e}'.format(valid_loss_final)))
                table.add_row(('Loss change / s',
                               '{:+.6e}'.format(valid_loss_change_per_sec)))
                table.add_row(('Loss change / iteration',
                               '{:+.6e}'.format(valid_loss_change_per_iter)))
                table.add_row(('Loss change / trace',
                               '{:+.6e}'.format(valid_loss_change_per_trace)))
        with doc.create(Figure(position='H')) as plot:
            fig = plt.figure(figsize=(10, 6))
            ax = plt.subplot(111)
            ax.plot(inference_network._history_train_loss_trace,
                    inference_network._history_train_loss,
                    label='Training')
            ax.plot(inference_network._history_valid_loss_trace,
                    inference_network._history_valid_loss,
                    label='Validation')
            ax.legend()
            plt.xlabel('Training traces')
            plt.ylabel('Loss')
            plt.grid()
            fig.tight_layout()
            plot.add_plot(width=NoEscape(r'\textwidth'))
            plot.add_caption('Loss plot.')

        print('Analytics: Inference network.Neural network modules')
        with doc.create(Section('Neural network modules')):
            with doc.create(Tabularx('ll')) as table:
                table.add_row(
                    ('Total trainable parameters',
                     '{:,}'.format(inference_network._history_num_params[-1])))
                # table.add_row(('Softmax boost', inference_network.softmax_boost))
                # table.add_row(('Dropout', inference_network.dropout))
                # table.add_row(('Standardize inputs', inference_network.standardize_observes))
            with doc.create(Figure(position='H')) as plot:
                fig = plt.figure(figsize=(10, 4))
                ax = plt.subplot(111)
                ax.plot(inference_network._history_num_params_trace,
                        inference_network._history_num_params)
                plt.xlabel('Training traces')
                plt.ylabel('Number of parameters')
                plt.grid()
                fig.tight_layout()
                plot.add_plot(width=NoEscape(r'\textwidth'))
                plot.add_caption('Number of parameters.')

            doc.append(NoEscape(r'\newpage'))
            print(
                'Analytics: Inference network.Neural network modules.All modules'
            )
            with doc.create(Subsection('All modules')):
                doc.append(str(inference_network))

            for m_name, m in inference_network.named_modules():
                if (m_name != ''):
                    regex = r'(sample_embedding_layer\(\S*\)._)|(proposal_layer\(\S*\)._)|(_observe_embedding_layer.)|(_lstm)'
                    if len(list(re.finditer(regex, m_name))) > 0:
                        # if ('_observe_embedding_layer.' in m_name) or ('sample_embedding_layer.' in m_name) or ('proposal_layer.' in m_name):
                        doc.append(NoEscape(r'\newpage'))
                        with doc.create(Subsubsection(m_name)):
                            doc.append(str(m))
                            for p_name, p in m.named_parameters():
                                if not 'bias' in p_name:
                                    with doc.create(
                                            Figure(position='H')) as plot:
                                        fig = plt.figure(figsize=(10, 10))
                                        ax = plt.subplot(111)
                                        plt.imshow(np.transpose(
                                            util.weights_to_image(p),
                                            (1, 2, 0)),
                                                   interpolation='none')
                                        plt.axis('off')
                                        plot.add_plot(
                                            width=NoEscape(r'\textwidth'))
                                        plot.add_caption(m_name + '_' + p_name)
            # doc.append(NoEscape(r'\newpage'))
            # print('Analytics: Inference network.Neural network modules.Address embeddings')
            # with doc.create(Subsection('Address embeddings')):
            #     for p_name, p in inference_network.named_parameters():
            #         if ('address_embedding' in p_name):
            #             with doc.create(Figure(position='H')) as plot:
            #                 fig = plt.figure(figsize=(10,10))
            #                 ax = plt.subplot(111)
            #                 plt.imshow(np.transpose(util.weights_to_image(p),(1,2,0)), interpolation='none')
            #                 plt.axis('off')
            #                 plot.add_plot(width=NoEscape(r'\textwidth'))
            #                 plot.add_caption(FootnoteText(p_name.replace('::', ':: ')))

        gc.collect()
        doc.append(NoEscape(r'\newpage'))
        print('Analytics: Inference network.Traces')
        with doc.create(Section('Traces')):
            with doc.create(Tabularx('ll')) as table:
                table.add_row(
                    ('Total training traces',
                     '{:,}'.format(inference_network._total_train_traces)))
            print(
                'Analytics: Inference network.Traces.Distributions encountered'
            )
            with doc.create(Subsection('Distributions encountered')):
                with doc.create(Tabularx('ll')) as table:
                    # print([v[2] for v in inference_network._address_stats.values()])
                    distributions = set([
                        v[2]
                        for v in inference_network._address_stats.values()
                    ])
                    num_distributions = len(distributions)
                    table.add_row(
                        ('Number of distributions', num_distributions))
                    table.add_empty_row()
                    for distribution in distributions:
                        table.add_row((distribution, ''))
            print('Analytics: Inference network.Traces.Addresses encountered')
            with doc.create(Subsection('Addresses encountered')):
                with doc.create(Tabularx('lX')) as table:
                    num_addresses_all = len(
                        inference_network._address_stats.keys())
                    table.add_row(('Number of addresses', num_addresses_all))
                    num_addresses_controlled = len([
                        k for k, v in inference_network._address_stats.items()
                        if v[3]
                    ])
                    num_addresses_replaced = len([
                        k for k, v in inference_network._address_stats.items()
                        if v[3] and v[4]
                    ])
                    num_addresses_observed = len([
                        k for k, v in inference_network._address_stats.items()
                        if v[5]
                    ])
                    table.add_row(
                        (TextColor('red', 'Number of addresses (controlled)'),
                         TextColor('red', num_addresses_controlled)))
                    table.add_row((TextColor('green',
                                             'Number of addresses (replaced)'),
                                   TextColor('green', num_addresses_replaced)))
                    table.add_row((TextColor('blue',
                                             'Number of addresses (observed)'),
                                   TextColor('blue', num_addresses_observed)))
                    table.add_row(
                        ('Number of addresses (uncontrolled)',
                         num_addresses_all - num_addresses_controlled -
                         num_addresses_observed))
                    table.add_empty_row()
                doc.append('\n')
                with doc.create(LongTable('llllllp{12cm}')) as table:
                    # table.add_empty_row()
                    table.add_row(FootnoteText('Count'), FootnoteText('ID'),
                                  FootnoteText('Distrib.'),
                                  FootnoteText('Ctrl.'),
                                  FootnoteText('Replace'),
                                  FootnoteText('Obs.'),
                                  FootnoteText('Address'))
                    table.add_hline()

                    # address_to_abbrev = {}
                    # abbrev_to_address =
                    # abbrev_i = 0
                    # sorted_addresses = sorted(inference_network.address_histogram.items(), key=lambda x:x[1], reverse=True)
                    plt_all_addresses = []
                    plt_all_counts = []
                    plt_all_colors = []
                    plt_controlled_addresses = []
                    plt_controlled_counts = []
                    plt_controlled_colors = []
                    address_id_to_count = {}
                    address_id_to_color = {}
                    address_id_count_total = 0
                    for address, vals in inference_network._address_stats.items(
                    ):
                        address = address.replace('::', ':: ')
                        count = vals[0]
                        address_id = vals[1]
                        distribution = vals[2]
                        control = vals[3]
                        replace = vals[4]
                        observed = vals[5]
                        plt_all_addresses.append(address_id)
                        plt_all_counts.append(1 if replace else count)
                        address_id_to_count[address_id] = count
                        address_id_count_total += count
                        if control:
                            if replace:
                                color = 'green'
                                plt_controlled_counts.append(1)
                            else:
                                color = 'red'
                                plt_controlled_counts.append(count)

                            plt_controlled_addresses.append(address_id)
                            plt_controlled_colors.append(color)
                        elif observed:
                            color = 'blue'
                            plt_controlled_addresses.append(address_id)
                            plt_controlled_colors.append(color)
                            plt_controlled_counts.append(count)
                        else:
                            color = 'black'
                        table.add_row(
                            (TextColor(color,
                                       FootnoteText('{:,}'.format(count))),
                             TextColor(color, FootnoteText(address_id)),
                             TextColor(color, FootnoteText(distribution)),
                             TextColor(color, FootnoteText(control)),
                             TextColor(color, FootnoteText(replace)),
                             TextColor(color, FootnoteText(observed)),
                             TextColor(color, FootnoteText(address))))
                        plt_all_colors.append(color)
                        address_id_to_color[address_id] = color

                gc.collect()
                with doc.create(Figure(position='H')) as plot:
                    fig = plt.figure(figsize=(10, 5))
                    ax = plt.subplot(111)
                    plt_x = range(len(plt_all_addresses))
                    ax.bar(plt_x, plt_all_counts, color=plt_all_colors)
                    plt.xticks(plt_x, plt_all_addresses)
                    plt.xlabel('Address ID')
                    plt.ylabel('Count')
                    # plt.grid()
                    fig.tight_layout()
                    plot.add_plot(width=NoEscape(r'\textwidth'))
                    plot.add_caption(
                        'Histogram of all addresses. Red: controlled, green: replaced, black: uncontrolled, blue: observed.'
                    )

                with doc.create(Figure(position='H')) as plot:
                    fig = plt.figure(figsize=(10, 5))
                    ax = plt.subplot(111)
                    plt_x = range(len(plt_controlled_addresses))
                    ax.bar(plt_x,
                           plt_controlled_counts,
                           color=plt_controlled_colors)
                    plt.xticks(plt_x, plt_controlled_addresses)
                    plt.xlabel('Address ID')
                    plt.ylabel('Count')
                    # plt.grid()
                    fig.tight_layout()
                    plot.add_plot(width=NoEscape(r'\textwidth'))
                    plot.add_caption(
                        'Histogram of controlled and observed addresses. Red: controlled, green: replaced, blue: observed.'
                    )

            gc.collect()
            print('Analytics: Inference network.Traces.Trace lengths')
            with doc.create(Subsection('Trace lengths')):
                with doc.create(Tabularx('ll')) as table:
                    trace_lengths_controlled = [
                        v[3] for v in inference_network._trace_stats.values()
                    ]
                    trace_lengths_controlled_min = min(
                        trace_lengths_controlled)
                    trace_lengths_controlled_max = max(
                        trace_lengths_controlled)
                    trace_lengths_all = [
                        v[2] for v in inference_network._trace_stats.values()
                    ]
                    trace_lengths_all_min = min(trace_lengths_all)
                    trace_lengths_all_max = max(trace_lengths_all)
                    s_controlled = 0
                    s_all = 0
                    total_count = 0
                    for _, v in inference_network._trace_stats.items():
                        trace_length_controlled = v[3]
                        trace_length_all = v[2]
                        count = v[0]
                        s_controlled += trace_length_controlled * count
                        total_count += count
                        s_all += trace_length_all * count
                    trace_length_controlled_mean = s_controlled / total_count
                    trace_length_all_mean = s_all / total_count
                    table.add_row(('Trace length min',
                                   '{:,}'.format(trace_lengths_all_min)))
                    table.add_row(('Trace length max',
                                   '{:,}'.format(trace_lengths_all_max)))
                    table.add_row(('Trace length mean',
                                   '{:.2f}'.format(trace_length_all_mean)))
                    table.add_row(
                        ('Controlled trace length min',
                         '{:,}'.format(trace_lengths_controlled_min)))
                    table.add_row(
                        ('Controlled trace length max',
                         '{:,}'.format(trace_lengths_controlled_max)))
                    table.add_row(
                        ('Controlled trace length mean',
                         '{:.2f}'.format(trace_length_controlled_mean)))
                with doc.create(Figure(position='H')) as plot:
                    plt_counter = dict(Counter(trace_lengths_all))
                    plt_lengths = [
                        i for i in range(0, trace_lengths_all_max + 1)
                    ]
                    plt_counts = [
                        plt_counter[i] if i in plt_counter else 0
                        for i in range(0, trace_lengths_all_max + 1)
                    ]
                    fig = plt.figure(figsize=(10, 5))
                    ax = plt.subplot(111)
                    ax.bar(plt_lengths,
                           plt_counts,
                           width=trace_lengths_all_max / 500.)
                    plt.xlabel('Length')
                    plt.ylabel('Count')
                    # plt.yscale('log')
                    # plt.grid()
                    fig.tight_layout()
                    plot.add_plot(width=NoEscape(r'\textwidth'))
                    plot.add_caption('Histogram of trace lengths.')
                with doc.create(Figure(position='H')) as plot:
                    plt_counter = dict(Counter(trace_lengths_controlled))
                    plt_lengths = [
                        i for i in range(0, trace_lengths_controlled_max + 1)
                    ]
                    plt_counts = [
                        plt_counter[i] if i in plt_counter else 0
                        for i in range(0, trace_lengths_controlled_max + 1)
                    ]
                    fig = plt.figure(figsize=(10, 5))
                    ax = plt.subplot(111)
                    ax.bar(plt_lengths, plt_counts)
                    plt.xlabel('Length')
                    plt.ylabel('Count')
                    # plt.yscale('log')
                    # plt.grid()
                    fig.tight_layout()
                    plot.add_plot(width=NoEscape(r'\textwidth'))
                    plot.add_caption('Histogram of controlled trace lengths.')

            gc.collect()
            print(
                'Analytics: Inference network.Traces.Unique traces encountered'
            )
            with doc.create(Subsection('Unique traces encountered')):
                detailed_traces = min(len(inference_network._trace_stats),
                                      detailed_traces)
                with doc.create(Tabularx('ll')) as table:
                    table.add_row(
                        ('Unique traces encountered',
                         '{:,}'.format(len(inference_network._trace_stats))))
                    table.add_row(('Unique traces rendered in detail',
                                   '{:,}'.format(detailed_traces)))
                doc.append('\n')
                with doc.create(LongTable('llllp{15cm}')) as table:
                    # table.add_empty_row()
                    table.add_row(FootnoteText('Count'), FootnoteText('ID'),
                                  FootnoteText('Len.'),
                                  FootnoteText('Ctrl. len.'),
                                  FootnoteText('Unique trace'))
                    table.add_hline()

                    plt_traces = []
                    plt_counts = []
                    for trace_str, vals in inference_network._trace_stats.items(
                    ):
                        count = vals[0]
                        trace_id = vals[1]
                        length_all = vals[2]
                        length_controlled = vals[3]
                        addresses_controlled = vals[4]
                        addresses_controlled_str = ' '.join(
                            addresses_controlled)
                        plt_traces.append(trace_id)
                        plt_counts.append(count)
                        table.add_row(
                            (FootnoteText('{:,}'.format(count)),
                             FootnoteText(trace_id),
                             FootnoteText('{:,}'.format(length_all)),
                             FootnoteText('{:,}'.format(length_controlled)),
                             FootnoteText(addresses_controlled_str)))

                with doc.create(Figure(position='H')) as plot:
                    fig = plt.figure(figsize=(10, 5))
                    ax = plt.subplot(111)
                    plt_x = range(len(plt_traces))
                    ax.bar(plt_x, plt_counts)
                    plt.xticks(plt_x, plt_traces)
                    plt.xlabel('Trace ID')
                    plt.ylabel('Count')
                    # plt.grid()
                    fig.tight_layout()
                    plot.add_plot(width=NoEscape(r'\textwidth'))
                    plot.add_caption('Histogram of unique traces.')

                with doc.create(Figure(position='H')) as plot:
                    sorted_trace_stats = OrderedDict(
                        sorted(dict(inference_network._trace_stats).items(),
                               key=lambda x: x[1],
                               reverse=True))
                    master_trace_pairs = {}
                    transition_count_total = 0
                    for trace_str, vals in sorted_trace_stats.items():
                        count = vals[0]
                        ta = vals[4]
                        for left, right in zip(ta, ta[1:]):
                            if (left, right) in master_trace_pairs:
                                master_trace_pairs[(left, right)] += count
                            else:
                                master_trace_pairs[(left, right)] = count
                            transition_count_total += count
                    fig = plt.figure(figsize=(10, 5))
                    ax = plt.subplot(111)
                    master_graph = pydotplus.graphviz.Dot(graph_type='digraph',
                                                          rankdir='LR')
                    transition_count_max = 0
                    for p, count in master_trace_pairs.items():
                        if count > transition_count_max:
                            transition_count_max = count
                        nodes = master_graph.get_node(p[0])
                        if len(nodes) > 0:
                            n0 = nodes[0]
                        else:
                            n0 = pydotplus.Node(p[0])
                            master_graph.add_node(n0)
                        nodes = master_graph.get_node(p[1])
                        if len(nodes) > 0:
                            n1 = nodes[0]
                        else:
                            n1 = pydotplus.Node(p[1])
                            master_graph.add_node(n1)
                        master_graph.add_edge(
                            pydotplus.Edge(n0, n1, weight=count))
                    for node in master_graph.get_nodes():
                        node.set_color('gray')
                        node.set_fontcolor('gray')
                    for edge in master_graph.get_edges():
                        edge.set_color('gray')

                    master_graph_annotated = pydotplus.graphviz.graph_from_dot_data(
                        master_graph.to_string())
                    for node in master_graph_annotated.get_nodes():
                        # color = util.rgb_to_hex(util.rgb_blend((1, 1, 1), (1, 0, 0), address_id_to_count[node.obj_dict['name']] / address_id_count_total))
                        address_id = node.obj_dict['name']
                        node.set_style('filled')
                        node.set_fillcolor(address_id_to_color[address_id])
                        node.set_color('black')
                        node.set_fontcolor('black')
                    for edge in master_graph_annotated.get_edges():
                        (left, right) = edge.obj_dict['points']
                        count = master_trace_pairs[(left, right)]
                        edge.set_label(count)
                        # color = util.rgb_to_hex((1.5*(count/transition_count_total), 0, 0))
                        edge.set_color('black')
                        edge.set_penwidth(2.5 * count / transition_count_max)

                    png_str = master_graph_annotated.create_png(
                        prog=['dot', '-Gsize=90', '-Gdpi=600'])
                    bio = BytesIO()
                    bio.write(png_str)
                    bio.seek(0)
                    img = np.asarray(mpimg.imread(bio))
                    plt.imshow(util.crop_image(img), interpolation='bilinear')
                    plt.axis('off')
                    plot.add_plot(width=NoEscape(r'\textwidth'))
                    plot.add_caption(
                        'Succession of controlled addresses (accumulated over all traces). Red: controlled, green: replaced, blue: observed.'
                    )

                for trace_str, vals in OrderedDict(
                        islice(sorted_trace_stats.items(), 0,
                               detailed_traces)).items():
                    count = vals[0]
                    trace_id = vals[1]
                    doc.append(NoEscape(r'\newpage'))
                    with doc.create(Subsubsection('Unique trace ' + trace_id)):
                        sys.stdout.write(
                            'Rendering unique trace {0}...                                       \r'
                            .format(trace_id))
                        sys.stdout.flush()

                        addresses = len(plt_controlled_addresses)
                        trace_addresses = vals[4]

                        with doc.create(Tabularx('ll')) as table:
                            table.add_row(FootnoteText('Count'),
                                          FootnoteText('{:,}'.format(count)))
                            table.add_row(
                                FootnoteText('Controlled length'),
                                FootnoteText('{:,}'.format(
                                    len(trace_addresses))))
                        doc.append('\n')

                        im = np.zeros((addresses, len(trace_addresses)))
                        for i in range(len(trace_addresses)):
                            address = trace_addresses[i]
                            address_i = plt_controlled_addresses.index(address)
                            im[address_i, i] = 1
                        truncate = 100
                        for col_start in range(0, len(trace_addresses),
                                               truncate):
                            col_end = min(col_start + truncate,
                                          len(trace_addresses))
                            with doc.create(Figure(position='H')) as plot:
                                fig = plt.figure(figsize=(20 * (
                                    (col_end + 4 - col_start) / truncate), 4))
                                ax = plt.subplot(111)
                                # ax.imshow(im,cmap=plt.get_cmap('Greys'))
                                sns.heatmap(
                                    im[:, col_start:col_end],
                                    cbar=False,
                                    linecolor='lightgray',
                                    linewidths=.5,
                                    cmap='Greys',
                                    yticklabels=plt_controlled_addresses,
                                    xticklabels=np.arange(col_start, col_end))
                                plt.yticks(rotation=0)
                                fig.tight_layout()
                                plot.add_plot(
                                    width=NoEscape(r'{0}\textwidth'.format(
                                        (col_end + 4 - col_start) / truncate)),
                                    placement=NoEscape(r'\raggedright'))

                        with doc.create(Figure(position='H')) as plot:
                            pairs = {}
                            for left, right in zip(trace_addresses,
                                                   trace_addresses[1:]):
                                if (left, right) in pairs:
                                    pairs[(left, right)] += 1
                                else:
                                    pairs[(left, right)] = 1

                            fig = plt.figure(figsize=(10, 5))
                            ax = plt.subplot(111)
                            graph = pydotplus.graphviz.graph_from_dot_data(
                                master_graph.to_string())

                            trace_address_to_count = {}
                            for address in trace_addresses:
                                if address in trace_address_to_count:
                                    trace_address_to_count[address] += 1
                                else:
                                    trace_address_to_count[address] = 1

                            transition_count_max = 0
                            for p, count in pairs.items():
                                if count > transition_count_max:
                                    transition_count_max = count
                                left_node = graph.get_node(p[0])[0]
                                right_node = graph.get_node(p[1])[0]
                                edge = graph.get_edge(p[0], p[1])[0]

                                # color = util.rgb_to_hex(util.rgb_blend((1,1,1), (1,0,0), trace_address_to_count[p[0]] / len(trace_addresses)))
                                left_node.set_style('filled')
                                left_node.set_fillcolor(
                                    address_id_to_color[p[0]])
                                left_node.set_color('black')
                                left_node.set_fontcolor('black')

                                # color = util.rgb_to_hex(util.rgb_blend((1,1,1), (1,0,0), trace_address_to_count[p[0]] / len(trace_addresses)))
                                right_node.set_style('filled')
                                right_node.set_fillcolor(
                                    address_id_to_color[p[1]])
                                right_node.set_color('black')
                                right_node.set_fontcolor('black')

                                # (left, right) = edge.obj_dict['points']
                                edge.set_label(count)
                                # color = util.rgb_to_hex((1.5*(count/len(trace_addresses)),0,0))
                                edge.set_color('black')
                                edge.set_penwidth(2.5 * count /
                                                  transition_count_max)

                            png_str = graph.create_png(
                                prog=['dot', '-Gsize=90', '-Gdpi=600'])
                            bio = BytesIO()
                            bio.write(png_str)
                            bio.seek(0)
                            img = np.asarray(mpimg.imread(bio))
                            plt.imshow(util.crop_image(img),
                                       interpolation='bilinear')
                            plt.axis('off')
                            plot.add_plot(width=NoEscape(r'\textwidth'))
                            plot.add_caption(
                                'Succession of controlled addresses (for one trace of type '
                                + trace_id +
                                '). Red: controlled, green: replaced, blue: observed.'
                            )

                        with doc.create(Tabularx('lp{16cm}')) as table:
                            table.add_row(
                                FootnoteText('Trace'),
                                FootnoteText(' '.join(trace_addresses)))

    doc.generate_pdf(file_name, clean_tex=False)
    sys.stdout.write(
        '                                                               \r')
    sys.stdout.flush()
Пример #8
0
def generate_unique():
    geometry_options = {
        "head": "40pt",
        "margin": "0.5in",
        "bottom": "0.6in",
        "includeheadfoot": True
    }
    doc = Document(geometry_options=geometry_options)

    # Generating first page style
    first_page = PageStyle("firstpage")

    # Header image
    with first_page.create(Head("L")) as header_left:
        with header_left.create(
                MiniPage(width=NoEscape(r"0.49\textwidth"),
                         pos='c')) as logo_wrapper:
            logo_file = os.path.join(os.path.dirname(__file__),
                                     'sample-logo.png')
            logo_wrapper.append(
                StandAloneGraphic(image_options="width=120px",
                                  filename=logo_file))

    # Add document title
    with first_page.create(Head("R")) as right_header:
        with right_header.create(
                MiniPage(width=NoEscape(r"0.49\textwidth"), pos='c',
                         align='r')) as title_wrapper:
            title_wrapper.append(LargeText(bold("Bank Account Statement")))
            title_wrapper.append(LineBreak())
            title_wrapper.append(MediumText(bold("Date")))

    # Add footer
    with first_page.create(Foot("C")) as footer:
        message = "Important message please read"
        with footer.create(
                Tabularx(
                    "X X X X",
                    width_argument=NoEscape(r"\textwidth"))) as footer_table:

            footer_table.add_row(
                [MultiColumn(4, align='l', data=TextColor("blue", message))])
            footer_table.add_hline(color="blue")
            footer_table.add_empty_row()

            branch_address = MiniPage(width=NoEscape(r"0.25\textwidth"),
                                      pos='t')
            branch_address.append("960 - 22nd street east")
            branch_address.append("\n")
            branch_address.append("Saskatoon, SK")

            document_details = MiniPage(width=NoEscape(r"0.25\textwidth"),
                                        pos='t',
                                        align='r')
            document_details.append("1000")
            document_details.append(LineBreak())
            document_details.append(simple_page_number())

            footer_table.add_row([
                branch_address, branch_address, branch_address,
                document_details
            ])

    doc.preamble.append(first_page)
    # End first page style

    # Add customer information
    with doc.create(Tabu("X[l] X[r]")) as first_page_table:
        customer = MiniPage(width=NoEscape(r"0.49\textwidth"), pos='h')
        customer.append("Verna Volcano")
        customer.append("\n")
        customer.append("For some Person")
        customer.append("\n")
        customer.append("Address1")
        customer.append("\n")
        customer.append("Address2")
        customer.append("\n")
        customer.append("Address3")

        # Add branch information
        branch = MiniPage(width=NoEscape(r"0.49\textwidth"),
                          pos='t!',
                          align='r')
        branch.append("Branch no.")
        branch.append(LineBreak())
        branch.append(bold("1181..."))
        branch.append(LineBreak())
        branch.append(bold("TIB Cheque"))

        first_page_table.add_row([customer, branch])
        first_page_table.add_empty_row()

    doc.change_document_style("firstpage")
    doc.add_color(name="lightgray", model="gray", description="0.80")

    # Add statement table
    with doc.create(LongTabu("X[l] X[2l] X[r] X[r] X[r]",
                             row_height=1.5)) as data_table:
        data_table.add_row(
            ["date", "description", "debits($)", "credits($)", "balance($)"],
            mapper=bold,
            color="lightgray")
        data_table.add_empty_row()
        data_table.add_hline()
        row = ["2016-JUN-01", "Test", "$100", "$1000", "-$900"]
        for i in range(30):
            if (i % 2) == 0:
                data_table.add_row(row, color="lightgray")
            else:
                data_table.add_row(row)

    doc.append(NewPage())

    # Add cheque images
    with doc.create(LongTabu("X[c] X[c]")) as cheque_table:
        cheque_file = os.path.join(os.path.dirname(__file__),
                                   'chequeexample.png')
        cheque = StandAloneGraphic(cheque_file, image_options="width=200px")
        for i in range(0, 20):
            cheque_table.add_row([cheque, cheque])

    doc.generate_pdf("complex_report", clean_tex=False)
Пример #9
0
    def generar(self, Carrera, Asignatura, Curso, listaPreguntas, aleatorio):

        today = str(self.__fecha)

        geometry_options = {
            "head": "48pt",
            "margin": "0.5in",
            "bottom": "0.6in",
            "includeheadfoot": True
        }

        doc = Document(geometry_options=geometry_options)

        header = PageStyle("header")  # DEFINIMOS LA VARIABLE CON ESTILO

        #image_filename = os.path.join(os.path.dirname("__file__"), '../static/zigmap.png') # IMAGEN UNAB

        #data_folder = os.path.join("../", "static/zigmap.png")

        #file_to_open = os.path.join(data_folder, "zigmap.png")

        #image_filename = data_folder
        image_filename = "zigmap.png"

        # Generating first page style
        first_page = PageStyle("firstpage")

        # Header image
        with first_page.create(Head("L")) as header_left:

            with header_left.create(
                    SubFigure(
                        position='L',
                        width=NoEscape(r'0.10\linewidth'))) as logo_wrapper:

                print("IMAGEN")
                #logo_wrapper.add_image('zigmap.png', width=NoEscape(r'\linewidth'))

        # Add document title
        with first_page.create(Head("C")) as center_header:
            with center_header.create(
                    MiniPage(width=NoEscape(r"0.49\textwidth"),
                             pos='c',
                             align='c')) as title_wrapper:
                title_wrapper.append(LargeText(bold(self.__nombre)))

        # Add document title
        with first_page.create(Head("R")) as right_header:
            with right_header.create(
                    MiniPage(width=NoEscape(r"0.49\textwidth"),
                             pos='c',
                             align='r')) as title_wrapper:
                #title_wrapper.append(LargeText(bold("Solemne II")))
                #title_wrapper.append(LineBreak())
                title_wrapper.append(MediumText(bold(
                    Asignatura.get_nombreA())))

        # Add footer
        with first_page.create(Foot("C")) as footer:
            message = "Programación II"
            with footer.create(
                    Tabularx("X X X X", width_argument=NoEscape(
                        r"\textwidth"))) as footer_table:

                footer_table.add_row([
                    MultiColumn(4, align='l', data=TextColor("black", message))
                ])
                footer_table.add_hline(color="black")
                footer_table.add_empty_row()

                branch_address = MiniPage(width=NoEscape(r"0.45\textwidth"),
                                          pos='t',
                                          align='l')
                branch_address.append(
                    MediumText("Facultad de " + Carrera.get_facultad()))
                branch_address.append("\n")
                branch_address.append("")

                branch_address2 = MiniPage(width=NoEscape(r"0.10\textwidth"),
                                           pos='t')
                branch_address2.append("")
                branch_address2.append("\n")
                branch_address2.append("")

                document_details = MiniPage(width=NoEscape(r"0.25\textwidth"),
                                            pos='t',
                                            align='r')
                document_details.append(self.__fecha)
                document_details.append(LineBreak())
                document_details.append("")  # simple_page_number()

                footer_table.add_row([
                    branch_address, branch_address2, branch_address2,
                    document_details
                ])

        doc.preamble.append(first_page)
        # End first page style

        ############################################

        ####################################################
        # Add customer information
        with doc.create(Tabu("X[l] X[r]")) as first_page_table:
            customer = MiniPage(width=NoEscape(r"0.55\textwidth"), pos='h')
            customer.append("Nombre: ___________________________________")
            customer.append("\n")
            customer.append("    Rut:  _______________")
            customer.append("\n")
            customer.append("Nota: ______________")
            customer.append("\n")
            customer.append("\n")

            # Add branch information
            branch = MiniPage(width=NoEscape(r"0.35\textwidth"),
                              pos='t!',
                              align='r')

            if self.__unidad == "unidad1":
                branch.append(bold("Unidad: 1"))
            elif self.__unidad == "unidad2":
                branch.append(bold("Unidad: 2"))
            else:
                branch.append(bold("Unidades: 1 & 2"))
            branch.append(LineBreak())

            branch.append(bold("Curso: "))
            branch.append(bold(Curso.get_cod()))
            branch.append(LineBreak())

            branch.append(bold("Ponderación: "))
            branch.append(bold(self.__ponderacion + "%"))
            branch.append(LineBreak())

            first_page_table.add_row([customer, branch])

        doc.append(LargeText(bold("Indicaciones:")))

        # INDICACIONES

        with doc.create(Itemize()) as itemize:
            doc.append(LineBreak())
            itemize.add_item(
                " Lea atentamente los enunciados de cada pregunta antes de contestar."
            )
            itemize.add_item(
                " Conteste su evaluación en silencio, está prohibido conversar o gesticulizar en la sala durante la prueba."
            )
            itemize.add_item(
                " Dispone de 90 minutos para realizar esta evaluación.")
            itemize.add_item(
                " Marque la alternativa con lapiz pasta, no se aceptan marcadas con lapiz grafito."
            )
            itemize.add_item(
                " Utilice solamente sus materiales, está prohibido solicitar materiales a sus compañeros."
            )
            # you can append to existing items
            itemize.append(Command("ldots"))

        doc.change_document_style("firstpage")
        doc.add_color(name="lightgray", model="gray", description="0.80")
        customer.append(LineBreak())

        now = str(datetime.today())

        for p in listaPreguntas:
            with doc.create(Section('Pregunta - ' + p.get_tipo())):

                doc.append(p.get_contenido())

        doc.append(NewPage())

        nombreFile = str(
            self.__nombre) + " - " + self.get_fecha() + " - " + str(aleatorio)

        print(
            "--------------------------ANTES DE DIR------------------------------"
        )

        try:
            # GENERANDO PDF
            doc.generate_pdf(filepath="tests/" + nombreFile,
                             clean_tex=True,
                             clean=True)
            #doc.generate_pdf(dirName + "/" + nombreFile, clean_tex=False)

        except FileNotFoundError as e:
            doc.generate_pdf(filepath="../tests/" + nombreFile,
                             clean_tex=True,
                             clean=True)
Пример #10
0
    def doit(self):

        is_multirow = self.num_metrics > 1 and self.spec.multirow

        def render_metric(value, best, second, decimals, format_string,
                          highlight_top, relative_to):
            if isinstance(value, numbers.Number):
                if relative_to is None or relative_to == 0 or not np.isfinite(
                        relative_to):
                    # absolute number
                    rendered = format_string.format(value, prec=decimals)
                else:
                    # percent
                    rendered = format_ratio_percent(value,
                                                    relative_to,
                                                    decimals=decimals)
                if highlight_top:
                    if value == best:
                        rendered = bold(rendered)
                    elif value == second:
                        rendered = italic(rendered)
                return rendered
            else:
                return value

        if self.spec.export_latex:
            row_height = None
        else:
            row_height = 0.65 if is_multirow and self.num_metrics >= 3 else 1

        column_spec = '|r' if self.spec.vertical_bars else 'r'
        t = Tabular('l' + column_spec * self.num_exps,
                    row_height=row_height,
                    pos=['t'])
        escape_header_fun = lambda text: text if self.spec.escape_latex_header else NoEscape(
            text)
        if self.spec.rotate_header:
            t.add_row([''] + [
                NoEscape(r"\rotatebox{90}{%s}" % escape_latex(
                    escape_header_fun(s.display_name(self.exps[s.name]))))
                for s in self.experiment_specs
            ])
        else:
            t.add_row([''] + [
                escape_header_fun(s.display_name(self.exps[s.name]))
                for s in self.experiment_specs
            ])
        t.add_hline()

        for seq in self.seq_names:
            fails = [
                self.is_failed(self.exps[s.name], seq)
                for s in self.experiment_specs
            ]
            failure_strings = [
                self.render_failure(self.exps[s.name], seq)
                for s in self.experiment_specs
            ]
            values = np.array([
                self.get_metrics(self.exps[s.name], seq, s.it)
                for s in self.experiment_specs
            ])

            top_values = list(range(self.num_metrics))
            for c, m in enumerate(self.metrics):
                try:
                    values[:, c] = np.around(values[:, c], m.decimals)
                except IndexError:
                    pass
                non_excluded_values = np.array(values[:, c])
                for i in m.exclude_columns_highlight:
                    non_excluded_values[i] = math.nan
                top_values[c] = best_two_non_repeating(
                    non_excluded_values, reverse=m.larger_is_better)

            if is_multirow:
                rows = [[
                    MultiRow(self.num_metrics, data=self.seq_displayname(seq))
                ]] + [list(['']) for _ in range(1, self.num_metrics)]
            else:
                rows = [[self.seq_displayname(seq)]]
            for c, (fail, failure_str,
                    value_col) in enumerate(zip(fails, failure_strings,
                                                values)):
                if failure_str is not None:
                    if self.spec.color_failed:
                        failure_str = TextColor(self.spec.color_failed,
                                                failure_str)
                    if is_multirow:
                        rows[0].append(
                            MultiRow(self.num_metrics, data=failure_str))
                        for r in range(1, self.num_metrics):
                            rows[r].append('')
                    else:
                        rows[0].append(failure_str)
                else:
                    tmp_data = [None] * self.num_metrics
                    for r, m in enumerate(self.metrics):
                        if m.failed_threshold and value_col[
                                r] > m.failed_threshold:
                            obj = "x"
                            if self.spec.color_failed:
                                obj = TextColor(self.spec.color_failed, obj)
                        else:
                            relative_to = None
                            if m.relative_to_column is not None and m.relative_to_column != c:
                                relative_to = values[m.relative_to_column, r]
                            obj = render_metric(value_col[r],
                                                top_values[r][0],
                                                top_values[r][1],
                                                m.effective_display_decimals(),
                                                m.format_string,
                                                m.highlight_top,
                                                relative_to=relative_to)
                            if fail and self.spec.color_failed:
                                obj = TextColor(self.spec.color_failed, obj)
                        tmp_data[r] = obj
                    if self.num_metrics == 1 or is_multirow:
                        for r, obj in enumerate(tmp_data):
                            rows[r].append(obj)
                    else:
                        entry = []
                        for v in tmp_data:
                            entry.append(v)
                            entry.append(NoEscape("~/~"))
                        entry.pop()
                        rows[0].append(dumps_list(entry))

            for row in rows:
                t.add_row(row)

            if is_multirow:
                t.add_hline()

        if self.spec.export_latex:
            os.makedirs(self.export_basepath, exist_ok=True)
            t.generate_tex(
                os.path.join(self.export_basepath, self.spec.export_latex))

        with self.create(Subsection(self.spec.name, numbering=False)) as p:

            if self.spec.metrics_legend:
                legend = Tabular('|c|', row_height=row_height, pos=['t'])
                legend.add_hline()
                legend.add_row(["Metrics"])
                legend.add_hline()
                for m in self.metrics:
                    legend.add_row([m.display_name])
                legend.add_hline()

                tab = Tabular("ll")
                tab.add_row([t, legend])
                content = tab
            else:
                content = t

            if True:
                content = FootnoteText(content)

            p.append(content)
Пример #11
0
def generate_unique(sectors_notirradiated, hv_notirradiated, spark_notirradiated, irradatgif):
	geometry_options = {
		"head": "40pt",
		"margin": "0.5in",
		"bottom": "1.0in",
		"includeheadfoot": True
	}
	doc = Document(indent=False,geometry_options=geometry_options)

	# Generating first page style
	first_page = PageStyle("firstpage")

	# Header image
	with first_page.create(Head("L")) as header_left:
		with header_left.create(MiniPage(width=NoEscape(r"0.49\textwidth"),
										 pos='c')) as logo_wrapper:
			logo_file = os.path.join(os.path.dirname(__file__),
									 '../cernlogo.png')
			logo_wrapper.append(StandAloneGraphic(image_options="width=80px",
								filename=logo_file))

	# Add document title
	with first_page.create(Head("R")) as right_header:
		with right_header.create(MiniPage(width=NoEscape(r"0.49\textwidth"),
								 pos='c', align='r')) as title_wrapper:
			title_wrapper.append(LargeText(bold("ATLAS New Small Wheel")))
			title_wrapper.append(LineBreak())
			title_wrapper.append(bold("Integration Tests"))
			title_wrapper.append(LineBreak())
			title_wrapper.append(bold(now.strftime("%d-%m-%Y")))
			title_wrapper.append(LineBreak())
			title_wrapper.append("\n")
			title_wrapper.append(LargeText(bold("Chamber: "+str(chambername))))
			title_wrapper.append(LineBreak())
			title_wrapper.append("ID: "+str(ID))
			title_wrapper.append(LineBreak())

	# Add footer
	with first_page.create(Foot("C")) as footer:

		with footer.create(Tabularx(
				"X X X ",
				width_argument=NoEscape(r"\textwidth"))) as footer_table:

			footer_table.add_empty_row()

			footer_table.add_hline(color="blue")

			branch_address1 = MiniPage(
				width=NoEscape(r"0.25\textwidth"),
				pos='t')
			branch_address1.append("Lorenzo Pezzotti")
			branch_address1.append("\n")
			branch_address1.append("*****@*****.**")

			branch_address2 = MiniPage(
				width=NoEscape(r"0.25\textwidth"),
				pos='t')
			branch_address2.append("Alan Peyaud")
			branch_address2.append("\n")
			branch_address2.append("*****@*****.**")

			branch_address3 = MiniPage(
				width=NoEscape(r"0.25\textwidth"),
				pos='t')
			branch_address3.append("Ivan Gnesi")
			branch_address3.append("\n")
			branch_address3.append("*****@*****.**")

			document_details = MiniPage(width=NoEscape(r"0.2\textwidth"),
										pos='t', align='r')
			document_details.append(" ")
			document_details.append(LineBreak())
			document_details.append(simple_page_number())

			footer_table.add_row([branch_address1, branch_address2,
								  branch_address3])

	doc.append(first_page)
	# End first page style
	redcircle = glob.glob("redcircle.png")
	redcircle = StandAloneGraphic(redcircle, image_options="width=220px")

	# Add customer information
	with doc.create(Tabu("X[r]")) as first_page_table:
		'''
		# Add branch information
		branch = MiniPage(width=NoEscape(r"0.49\textwidth"), pos='t!',
						  align='r')
		branch.append("Chamber name: ")
		branch.append(LineBreak())
		branch.append("ID: ")
		branch.append(LineBreak())

		first_page_table.add_row([branch])
		'''
		first_page_table.add_empty_row()

	doc.change_document_style("firstpage")
	doc.add_color(name="lightgray", model="gray", description="0.85")
	doc.add_color(name="lightgray2", model="gray", description="0.6")

	if irradatgif == "y":
		title = "HV irradiated"
	else:
		title = "HV not irradiated"
	with doc.create(Section(title, numbering=False)):
	   # Add statement table
		doc.append("\n")
		doc.append(timeslot)
		doc.append(LineBreak())
		doc.append(str(deltatime/60)+str("_min"))
		doc.append(LineBreak())
		doc.append("Spike_treshold_0.2_uA")
		doc.append(LineBreak())

		with doc.create(LongTabu("|X[l]|X[r]|X[r]|X[r]|X[r]|",
								 row_height=1.5)) as data_table:
			data_table.add_hline()
			data_table.add_row(["Sector",
								"HV",
								"spark/min",
								"Efficiency",
								"Flag"],
							   mapper=bold,
							   color="lightgray2")
			data_table.add_hline()
			data_table.end_table_header()
			data_table.add_hline()
			row = ["sector", "hv","spark", "efficiency", "0 or 1"]
			acceptedlist = []
			not_acc_counter = 0
			pscolor = "blue"
			for i in range(len(hv_notirradiated)):
				if (i % 2) == 0:
					'''
					if int(hv_notirradiated[i]) > 567.9 and spark_notirradiated[i]<1.0:
						accepted = 1
						acceptedlist.append(accepted)

					else:
						accepted = 0
						acceptedlist.append(accepted)
					'''
					if int(hv_notirradiated[i]) > 567.9:
						hvcolor = "black"

					if 548.0 < int(hv_notirradiated[i]) < 567.9:
						hvcolor = "orange"

					if int(hv_notirradiated[i])< 548.0:
						hvcolor = "red"

					if spark_notirradiated[i] > 6.0:
						sparkcolor = "red"

					if spark_notirradiated[i] == 6.0:
						sparkcolor = "orange"

					if spark_notirradiated[i] < 6.0:
						sparkcolor = "black"

					if efficiency[i] < 80.0:
						effcolor = "red"

					if efficiency[i] > 80.0:
						effcolor = "black"

					if efficiency == 80.0:
						effcolor = "orange"

					if sparkcolor == "red" or hvcolor == "red" or effcolor == "red":
						acceptedcolor = "red"
						accepted = 0
						acceptedlist.append(accepted)
						not_acc_counter = not_acc_counter+1

					else:
						acceptedcolor = "black"
						accepted = 1
						acceptedlist.append(accepted)


					data_table.add_row([str(sectors_notirradiated[i]), TextColor(hvcolor,str(int(hv_notirradiated[i]))),
					TextColor(sparkcolor, str(round(spark_notirradiated[i],2))), TextColor(effcolor, str(round(efficiency[i],1))),
					TextColor(acceptedcolor, "V")])
					data_table.add_hline()
				else:
					'''
					if int(hv_notirradiated[i]) > 567.9 and spark_notirradiated[i]<1.0:
						accepted = 1
						acceptedlist.append(accepted)
					else:
						accepted = 0
						acceptedlist.append(accepted)
					'''
					if int(hv_notirradiated[i]) > 567.9:
						hvcolor = "black"

					if 548.0 < int(hv_notirradiated[i]) < 567.9:
						hvcolor = "orange"

					if int(hv_notirradiated[i])< 548.0:
						hvcolor = "red"

					if spark_notirradiated[i] > 6.0:
						sparkcolor = "red"

					if spark_notirradiated[i] == 6.0:
						sparkcolor = "orange"

					if spark_notirradiated[i] < 6.0:
						sparkcolor = "black"

					if efficiency[i] < 80.0:
						effcolor = "red"

					if efficiency[i] > 80.0:
						effcolor = "black"

					if efficiency == 80.0:
						effcolor = "orange"

					if sparkcolor == "red" or hvcolor == "red" or effcolor == "red":
						acceptedcolor = "red"
						accepted = 0
						acceptedlist.append(accepted)
						not_acc_counter = not_acc_counter+1

					else:
						acceptedcolor = "black"
						accepted = 1
						acceptedlist.append(accepted)


					data_table.add_row([str(sectors_notirradiated[i]), TextColor(hvcolor,str(int(hv_notirradiated[i]))),
					TextColor(sparkcolor, str(round(spark_notirradiated[i],2))), TextColor(effcolor, str(round(efficiency[i],1))),
					TextColor(acceptedcolor, "V")], color="lightgray")
					data_table.add_hline()

			data_table.add_hline()
			data_table.add_row("Out of spec", str(len([x for x in hv_notirradiated if x < 548.0])), str(len([x for x in spark_notirradiated if x > 6.0])), str(len([x for x in efficiency if x < 80.0])), str(not_acc_counter))

			data_table.add_empty_row()
			data_table.add_hline()
			data_table.add_row("Chamber efficiency", "","", "", str(round(total_efficiency)))
			data_table.add_hline()
			if "LM2" in chambername:
				newefficiency = efficiency
				newefficiency.pop(4)
				newefficiency.pop(4)
				newefficiency.pop(8)
				newefficiency.pop(8)
				data_table.add_row("Efficiency no LE8", "","", "", str(round(np.mean(newefficiency))))
				data_table.add_hline()

	doc.append(NoEscape('\\clearpage'))
	with doc.create(Section('Summary', numbering=False)):
		piecart.create_pie([acceptedlist.count(1), acceptedlist.count(0)], "piechart.pdf")


		 # Add cheque images
		with doc.create(LongTabu("X[c]")) as summary1_table:
			pie = glob.iglob("piechart.pdf")
			#png_list = [StandAloneGraphic(x, image_options="width=120px") for x in png_list]
			pienew = [StandAloneGraphic(x, image_options="width=220px") for x in pie]
			summary1_table.add_row([pienew[0]])

		#here I have sectors_notirradiated, hv_notirradiated, spark_notirradiated, acceptedlist
		SM1channels = ["L1","R1","L2","R2","L3","R3","L4","R4","L5","R5"]
		SM2channels = ["L6","R6","L7","R7","L8","R8"]

		badresultsall = []
		badresultseta = []
		badresultsstereo = []

		if chambername[0:3] == "SM1":
		   channels = SM1channels
		if chambername[0:3] == "SM2":
		   channels = SM2channels
		if chambername[0:3] == "LM1":
			channels = SM1channels
		if chambername[0:3] == "LM2":
			channels = SM2channels

		for channel in channels:
		   cntall = sum(1 for x, sector in enumerate(sectors_notirradiated) if sector[2:4] == channel and acceptedlist[x] == 1)
		   cnteta = sum(1 for x, sector in enumerate(sectors_notirradiated) if sector[2:4] == channel and (sector[1:2] == "1" or sector[1:2] == "2") and acceptedlist[x] == 1)
		   cntstereo = sum(1 for x, sector in enumerate(sectors_notirradiated) if sector[2:4] == channel and (sector[1:2] == "3" or sector[1:2] == "4") and acceptedlist[x] == 1)
		   badresultsall.append(4-int(cntall))
		   badresultseta.append(2-int(cnteta))
		   badresultsstereo.append(2-int(cntstereo))

		#doc.append(NewPage())

		with doc.create(LongTabu("X[l] X[r] X[r] X[r]",
								 row_height=1.5)) as data_table2:
			data_table2.add_row(["Sector overimposed (from eta side)",
								"Eta",
								"Stereo",
								"Eta+Stereo"],
								mapper=bold,
								color="lightgray2")
			data_table2.add_empty_row()
			data_table2.add_hline()
			row = ["Sector (all layers)", "Out of spec (Eta)", "Out of spec (Stereo)", "Out of spec (E+S)"]

			for i in range(len(channels)):
				if (i % 2) == 0:
					data_table2.add_row([str(channels[i]), str(int(badresultseta[i])), str(badresultsstereo[i]), badresultsall[i]], color="lightgray")
				else:
					data_table2.add_row([str(channels[i]), str(int(badresultseta[i])), str(badresultsstereo[i]), badresultsall[i]])

		with doc.create(LongTabu("X[l] X[r]",
								 row_height=1.5)) as data_table3:
			data_table3.add_row(["Layer",
								"Mean Efficiency"],
								mapper=bold,
								color="lightgray2")
			data_table3.add_empty_row()
			data_table3.add_hline()
			row = ["layers", "efficiency"]
			channelsT3 = ["L1", "L2", "L3", "L4"]
			for i in range(len(layers_efficiency)):
				if (i % 2) == 0:
					data_table3.add_row([str(channelsT3[i]), str(round(layers_efficiency[i],1))], color="lightgray")
				else:
					data_table3.add_row([str(channelsT3[i]), str(round(layers_efficiency[i],1))])

	doc.append(NewPage())

	if irradatgif == "y":
		title = "Current with irradiation"
	else:
		title = "Current with no irradiation"
	with doc.create(Section(title, numbering=False)):

	# Add cheque images
		with doc.create(LongTabu("X[c] X[c] X[c] X[c]")) as cheque_table:
			png_list = glob.glob('BB5-i*.pdf')
			png_list.sort(key=os.path.getmtime)
			png_list = [StandAloneGraphic(x, image_options="width=120px") for x in png_list]
			print len(png_list)
			row_image = []
			i = 0
			for image in png_list:
				row_image.append(image)
				i = i +1
				if i==4:
					cheque_table.add_row([row_image[0], row_image[1], row_image[2], row_image[3]])
					row_image = []
					i=0

	png_list = []
	doc.generate_pdf("complex_report", clean_tex=False, compiler='pdflatex')
Пример #12
0
def _trace_value(inp: Any, tables: Dict[FEID, FeSummaryTable], ret_ref: Flag, wrap_str: bool = True) -> Any:
    """Convert an input value to a FESummaryTable table representation

    Args:
        inp: The input value to be converted.
        tables: A collection of tables representing objects which are used by the current stack of inputs.
        ret_ref: A flag to indicate that _trace_value is returning a reference (this is used to figure out whether
            functions can be in-lined or deserve their own tables).
        wrap_str: Whether literal string values should be wrapped inside extra quote marks.

    Returns:
        An FESummaryTable representation of the input.
    """
    if isinstance(inp, str):
        inp = f"`{escape_latex(inp)}'" if wrap_str else escape_latex(inp)
        if wrap_str:
            # Prevent extremely long strings from overflowing the table
            return NoEscape(r'\seqsplit{' + inp + '}')
        return inp
    elif isinstance(inp, (int, float, bool, type(None), HrefFEID, FEID, PyContainer)):
        if isinstance(inp, (int, float)):
            # Prevent extremely long numbers from overflowing the table
            return NoEscape(r'\seqsplit{' + str(inp) + '}')
        return inp
    elif hasattr(inp, '_fe_traceability_summary'):
        # The first time a traceable object goes through here it won't have it's summary instantiated yet, so it will
        # fall through to the class check at the end to get it's id.
        # noinspection PyProtectedMember,PyUnresolvedReferences
        tables.update(inp._fe_traceability_summary)
        inp_id = FEID(id(inp))
        ret_ref.set_true()
        return HrefFEID(inp_id, tables[inp_id].name)
    elif inspect.ismethod(inp):
        parent = _trace_value(inp.__self__, tables, ret_ref, wrap_str)
        return ContainerList(data=[parent, escape_latex(f".{inp.__name__}")])
    elif inspect.isfunction(inp) or inspect.isclass(inp):
        inp_id = FEID(id(inp))
        if inp_id in tables:
            name = tables[inp_id].name
        else:
            if inspect.isfunction(inp) and inp.__name__ == "<lambda>":
                code = inp.__code__
                var_names = code.co_varnames
                # Attempt to figure out what the lambda function is doing. If it is being used only to invoke some other
                # function (like one might do with LRScheduler), then the parse should work.
                flag = Flag()
                func_description = _parse_lambda(inp, tables, flag) or {}
                func_description['vars'] = _trace_value(var_names, tables, flag, wrap_str=False)
                name = "lambda"
                path = None
                if not flag and func_description.keys() == {'vars', 'function'}:
                    # This is a simple lambda function, so inline it instead of making a new table
                    raw_vars = func_description['vars'].raw_input
                    formatted_vars = []
                    for var in raw_vars:
                        formatted_vars.append(var)
                        formatted_vars.append(', ')
                    if formatted_vars:
                        formatted_vars.pop()  # remove trailing comma
                    return ContainerList(data=[
                        TextColor('cyan', f"{name} "), *formatted_vars, ": ", func_description.get('function', '')
                    ])
            else:
                name = inp.__name__
                path = f"{inp.__module__}.{inp.__qualname__}"
                func_description = {}
            tables[inp_id] = FeSummaryTable(name=name,
                                            fe_id=inp_id,
                                            target_type=type(inp),
                                            path=path,
                                            **func_description)
        ret_ref.set_true()
        return HrefFEID(inp_id, name)
    elif isinstance(inp, _Function):
        inp_id = FEID(id(inp))
        if inp_id not in tables:
            if inspect.ismethod(inp.func):
                path = _trace_value(inp.func, tables, ret_ref, wrap_str)
            elif hasattr(inp.func, '__module__') and hasattr(inp.func, '__qualname__'):
                path = f"{inp.func.__module__}.{inp.func.__qualname__}"
            else:
                path = None
            tables[inp_id] = FeSummaryTable(name=inp.name, fe_id=inp_id, target_type=type(inp.func), path=path)
        ret_ref.set_true()
        return HrefFEID(inp_id, inp.name)
    elif isinstance(inp, _PartialBind):
        return {
            "args": _trace_value(inp.args, tables, ret_ref, wrap_str=True),
            "kwargs": _trace_value(inp.kwargs, tables, ret_ref, wrap_str).raw_input  # unwrap kwargs back into a dict
        }
    elif isinstance(inp, _Command):
        return ContainerList(data=[
            _trace_value(inp.left, tables, ret_ref, wrap_str),
            escape_latex(inp.command),
            _trace_value(inp.right, tables, ret_ref, wrap_str)
        ])
    elif isinstance(inp, _Condition):
        return ContainerList(data=[
            _trace_value(inp.left, tables, ret_ref, wrap_str),
            " if ",
            _trace_value(inp.condition, tables, ret_ref, wrap_str),
            " else ",
            _trace_value(inp.right, tables, ret_ref, wrap_str)
        ])
    elif isinstance(inp, _BoundFn):
        flag = Flag()
        args = _trace_value(inp.args, tables, flag, wrap_str=False)
        kwargs = {}
        if isinstance(inp.args, _PartialBind):
            kwargs = args["kwargs"]
            args = args["args"]
        elif isinstance(args, dict):
            kwargs = args
            args = None
        if not flag and isinstance(inp.func, _Function):
            # The function args are simple, so inline this function in whatever is above it
            if isinstance(args, PyContainer):
                args = args.raw_input
            if isinstance(kwargs, PyContainer):
                kwargs = kwargs.raw_input
            formatted = ["("]
            args = args or ()
            kwargs = kwargs or {}
            for arg in args:
                formatted.append(arg)
                formatted.append(", ")
            for key, value in kwargs.items():
                formatted.append(key)
                formatted.append("=")
                formatted.append(value)
                formatted.append(", ")
            if len(formatted) > 1:
                formatted.pop()  # Remove trailing comma
            formatted.append(")")
            if inspect.ismethod(inp.func.func):
                container_list = _trace_value(inp.func.func, tables, ret_ref, wrap_str)
                container_list.data.extend(formatted)
                return container_list
            return ContainerList(data=[inp.func.name, *formatted])
        else:
            # The function args are complicated, so use the normal approach
            func_href = _trace_value(inp.func, tables, ret_ref, wrap_str)
            inp_id = func_href.fe_id
            inp_table = tables[inp_id]
            inp_table.args = args
            inp_table.kwargs = kwargs
            ret_ref.set_true()
            return func_href
    elif isinstance(inp, inspect.BoundArguments):
        args = inp.arguments
        args.pop('self', None)
        return _trace_value(args, tables, ret_ref, wrap_str=False).raw_input  # unwrap kwargs back into a dict
    elif isinstance(inp, _VarWrap):
        return inp.var
    elif isinstance(inp, (tf.keras.Model, torch.nn.Module)):
        # FE models should never actually get here since they are given summaries by trace_model() during fe.build()
        inp_id = FEID(id(inp))
        if inp_id in tables:
            name = tables[inp_id].name
        else:
            name = inp.model_name if hasattr(inp, 'model_name') else "<Unknown Model Name>"
            tables[inp_id] = FeSummaryTable(name=name, fe_id=inp_id, target_type=type(inp))
        ret_ref.set_true()
        return HrefFEID(inp_id, name)
    elif isinstance(inp, list):
        return PyContainer(data=[_trace_value(x, tables, ret_ref, wrap_str) for x in inp],
                           truncate=_CollectionSizeLimit)
    elif isinstance(inp, tuple):
        return PyContainer(data=tuple([_trace_value(x, tables, ret_ref, wrap_str) for x in inp]),
                           truncate=_CollectionSizeLimit)
    elif isinstance(inp, set):
        return PyContainer(data=set([_trace_value(x, tables, ret_ref, wrap_str) for x in inp]),
                           truncate=_CollectionSizeLimit)
    elif isinstance(inp, dict):
        return PyContainer(
            data={
                _trace_value(k, tables, ret_ref, wrap_str=wrap_str): _trace_value(v, tables, ret_ref, wrap_str=True)
                for k,
                v in inp.items()
            },
            truncate=_CollectionSizeLimit)
    elif isinstance(inp, (tf.Tensor, torch.Tensor, np.ndarray, tf.Variable)):
        inp_type = type(inp)
        inp_id = FEID(id(inp))
        if inp_id not in tables:
            if isinstance(inp, (tf.Tensor, torch.Tensor, tf.Variable)):
                if isinstance(inp, torch.Tensor):
                    inp = inp.cpu().detach()
                    inp.numpy()
                # In the elif here we're sure to be tf
                elif inp.dtype != tf.dtypes.variant:
                    inp = inp.numpy()  # The variant dtype can't be cast to numpy()
            rank = inp.ndim
            description = {'shape': inp.shape}
            if rank == 0 or (rank == 1 and inp.shape[0] <= 10):
                description['values'] = str(inp)
            tables[inp_id] = FeSummaryTable(name="tensor", fe_id=inp_id, target_type=inp_type, **description)
        ret_ref.set_true()
        return HrefFEID(inp_id, "tensor")
    # This should be the last elif
    elif hasattr(inp, '__class__'):
        inp_id = FEID(id(inp))
        if inp_id not in tables:
            kwargs = {}
            path = None
            if hasattr(inp, '__dict__') and '_fe_state_whitelist' not in inp.__dict__:
                # Prevent circular recursion
                tables[inp_id] = FeSummaryTable(name=inp.__class__.__name__, target_type=type(inp), fe_id=inp_id)
                # This object isn't @traceable but does have some stored variables that we can summarize.
                kwargs = _trace_value({k: v
                                       for k, v in inp.__dict__.items() if not k.startswith("_")},
                                      tables,
                                      ret_ref,
                                      wrap_str=False).raw_input
                path = "Not @traceable, so summary is approximate"
            tables[inp_id] = FeSummaryTable(name=inp.__class__.__name__,
                                            target_type=type(inp),
                                            path=path,
                                            fe_id=inp_id,
                                            kwargs=kwargs)
        ret_ref.set_true()
        return HrefFEID(inp_id, inp.__class__.__name__)
    else:
        inp_id = FEID(id(inp))
        if inp_id not in tables:
            tables[inp_id] = FeSummaryTable(name="an object", target_type=type(inp), fe_id=inp_id)
        ret_ref.set_true()
        return HrefFEID(inp_id, "an object")
Пример #13
0
    def flags_table(self,
                    pre_qc_counts=None,
                    pos_qc_counts=None,
                    results=None,
                    lambda_gc=None,
                    sig_vars=None):
        nids_lost = (pre_qc_counts['n_samples'] -
                     pos_qc_counts['n_samples']) / pre_qc_counts['n_samples']
        nids_lost = round(nids_lost, 4)
        nids_sex_check = results['sex_warnings'][True] / pre_qc_counts[
            'n_samples']
        nids_sex_check = round(nids_sex_check, 4)

        if 'is_case_counts' in pre_qc_counts.keys() | pos_qc_counts.keys():
            cas_con_ratio = round(
                pos_qc_counts['is_case_counts']['case'] /
                pos_qc_counts['is_case_counts']['control'], 4)

            tbl = [[
                'Number of SNPs Post-QC', pos_qc_counts['n_variants'], 250000,
                200000, 0, 'green'
            ],
                   [
                       'Number of Cases Post-QC',
                       pos_qc_counts['is_case_counts']['case'], 100, 50, 0,
                       'green'
                   ],
                   [
                       'Number of Controls Post-QC',
                       pos_qc_counts['is_case_counts']['control'], 100, 50, 0,
                       'green'
                   ],
                   [
                       'Case-Control ratio Post-QC', cas_con_ratio, 0.0625,
                       0.0278, 0, 'green'
                   ],
                   [
                       'Number of IDs lost ratio', nids_lost, 0.01, 0.1, 0,
                       'green'
                   ],
                   [
                       'Number of IDs with no Phenotype Post-QC',
                       pos_qc_counts['is_case_counts']['unknown'], 0, 10, 0,
                       'green'
                   ],
                   [
                       'Ratio of IDs that failed sex checks', nids_sex_check,
                       0.005, 0.025, 0, 'green'
                   ], ['Lambda GC Post-QC', lambda_gc, 1.1, 1.2, 0, 'green'],
                   [
                       'Number of Significant GWAS hits Post-QC', sig_vars, 0,
                       1, 0, 'green'
                   ]]

        else:
            tbl = [[
                'Number of SNPs Post-QC', pos_qc_counts['n_variants'], 250000,
                200000, 0, 'green'
            ], ['Number of IDs lost ratio', nids_lost, 0.01, 0.1, 0, 'green'],
                   [
                       'Ratio of IDs that failed sex checks', nids_sex_check,
                       0.005, 0.025, 0, 'green'
                   ]]

        for i in tbl:
            if (i[0] == 'Number of SNPs Post-QC') | (i[0] == 'Number of Cases Post-QC') |\
                    (i[0] == 'Number of Controls Post-QC') | (i[0] == 'Case-Control ratio Post-QC'):
                if (i[1] <= i[2]) & (i[1] >= i[3]):
                    i[4] = 1
                    i[5] = 'orange'
                elif i[1] < i[3]:
                    i[4] = 2
                    i[5] = 'red'
                else:
                    i[4] = 0
                    i[5] = 'green'

            if i[0] == 'Number of IDs lost ratio':
                if (i[1] > i[2]) & (i[1] <= i[3]):
                    i[4] = 1
                    i[5] = 'orange'
                elif i[1] > i[3]:
                    i[4] = 2
                    i[5] = 'red'
                else:
                    i[4] = 0
                    i[5] = 'green'

            if (i[0] == 'Ratio of IDs that failed sex checks') | (
                    i[0] == 'Lambda GC Post-QC'):
                if (i[1] >= i[2]) & (i[1] <= i[3]):
                    i[4] = 1
                    i[5] = 'orange'
                elif i[1] > i[3]:
                    i[4] = 2
                    i[5] = 'red'
                else:
                    i[4] = 0
                    i[5] = 'green'

            if (i[0] == 'Number of Significant GWAS hits Post-QC') | (
                    i[0] == 'Number of IDs with no Phenotype Post-QC'):
                if i[1] == i[2]:
                    i[4] = 0
                    i[5] = 'green'
                elif (i[1] > i[2]) & (i[1] <= i[3]):
                    i[4] = 1
                    i[5] = 'orange'
                else:
                    i[4] = 2
                    i[5] = 'red'

        with self.create(Section('Flags')):
            with self.create(Center()) as centered:
                with centered.create(Tabular('|l|c|c|c|c|c|')) as table:
                    table.add_hline()
                    table.add_row(
                        (bold('Flagname'), bold('Value'), bold('yellow-th'),
                         bold('red-th'), bold('flag'), bold('color')))
                    table.add_hline()
                    for i in range(0, len(tbl)):
                        table.add_row(tbl[i][0], tbl[i][1], tbl[i][2],
                                      tbl[i][3], tbl[i][4],
                                      TextColor(tbl[i][5], tbl[i][5]))
                        table.add_hline()
Пример #14
0
    def portada(Diccionario, eficiencia,T_Hornilla):
        global doc
        doc = Document()
        geometry_options = {"tmargin": "4cm", "rmargin": "2cm", "lmargin": "4cm", "bmargin": "3cm"} 
        doc = Document(geometry_options=geometry_options)
        doc.packages.append(Package('babel', options=['spanish']))
        doc.packages.append(Package('background', options=['pages=all']))
        doc.packages.append(NoEscape('\\backgroundsetup{placement=center,\n angle=0, scale=1, contents={\includegraphics{Membrete.pdf}}, opacity=1}\n'))   
        
        with doc.create(Center()) as centered:
                    centered.append(TextColor('white','HH')) 
                    for i in range(10):
                        centered.append(LineBreak())   
                    centered.append(HugeText('PROPUESTA DE VALOR PARA LA CONSTRUCCIÓN DE UNA HORNILLA '))
                    centered.append(LineBreak()) 
                    centered.append(SmallText('(Generado por HornillAPP)'))
                    for i in range(8):
                        centered.append(LineBreak()) 
                    
        with doc.create(Figure(position='h!')) as imagesRow1:
            with doc.create(SubFigure(
                    position='b',
                    width=NoEscape(r'1\linewidth'))) as left_imagesRow1:
                left_imagesRow1.add_image('IconoAPP.png')
            imagesRow1.append(LineBreak())
                                    
        with doc.create(Center()) as centered:
                    centered.append(TextColor('white','HH')) 
                    for i in range(8):
                        centered.append(LineBreak())
                    #centered.append(VerticalSpace('50')) 
                    centered.append(LargeText('Presentado por: AGROSAVIA'))
                    centered.append(LineBreak())
                    centered.append(SmallText('(Corporación Colombiana de Investigación Agropecuaria)'))
        doc.append(NewPage())
        
        with doc.create(MediumText(' ')) as tlg:
                    tlg.append(TextColor('white','HH')) 
                    tlg.append(LineBreak())
                    tlg.append('Bogotá D.C., ')
                    tlg.append(Command(' ',NoEscape('\\today')))
                    tlg.append('\n \n') #Salto de línea en parráfo
                    tlg.append(LineBreak()) #Salto de línea en parráfo
                    tlg.append('\nSeñor (es):') 
                    tlg.append('\n'+str(Diccionario['Nombre de usuario']))
                    if(str(Diccionario['Departamento'])=='--'):
                        tlg.append('\n'+str(Diccionario['Pais'])+'.')    
                    else:
                        tlg.append('\n'+str(Diccionario['Ciudad'])+', '+str(Diccionario['Departamento'])+'.')
                    tlg.append('\n \n') #Salto de línea en parráfo
                    tlg.append('\nApreciado(s) productor(es):')
                    tlg.append('\n \n') #Salto de línea en parráfo
                    Parrafo= ('Con base en la información suministrada, está aplicación propone (ver Sección 1) la construcción de una hornilla '+
                              T_Hornilla+' con capacidad de '+ str(Diccionario['Capacidad estimada de la hornilla']) +' kg/h'+' (la eficiencia estimada de la hornilla es del '+ str(round(Diccionario['Eficiencia de la hornilla']))+'%) '+'; adecuada para el procesamiento de hasta '+
                              str(Diccionario['Área cosechada al mes'])+
                              ' ha'+' de caña, con una producción de panela '+ str(round(float(Diccionario['Producción de panela por molienda [t]'])))+
                              ' t por molienda y un periodo vegetativo de '+ str(Diccionario['Periodo vegetativo'])+' meses. Teniendo en cuenta que'+
                              ' se realizan '+str(Diccionario['Número de moliendas al año'])+' moliendas al año se estableció una jornada laboral de '+
                              str(Diccionario['Días de trabajo de la hornilla por semana'])+ ' días a la semana de '+str(Diccionario['Horas de trabajo de la hornilla por día'])+ ' horas laborables cada una.'+
                              '\n Además, la aplicación estima que para garantizar una operación apropiada de la hornilla '+
                              ' se requiere de un área disponible de al menos '+str(round(Diccionario['Capacidad estimada de la hornilla']*4.3))+' m²'
                              )
                    tlg.append(Parrafo)                
                    Parrafo= (', cuya productividad puede aumentar al incorporar el sistema de recuperación de calor (hasta '+str(round(Diccionario['Capacidad estimada de la hornilla']+25))+' kg/h) como se muestra en las tablas del análisis financiero y al final del informe.'
                              +' No obstante, la corporación ofrece los siguientes servicios de asistencia técnica para ajustar los valores provistos en esta propuesta de valor:'
                              )
                    tlg.append(Parrafo)
                    
                    with tlg.create(Itemize()) as itemize:
                        itemize.add_item('Estudio detallado para la construcción e instalación de la hornilla.')
                        itemize.add_item('Al menos tres visitas técnicas de dos funcionarios de AGROSAVIA para la puesta en marcha y '+
                                         'capacitación de los operarios en el manejo de la hornilla y en la producción de panela '+
                                         'saborizada, granulada o moldeada en presentación pastilla de chocolate.')
                        itemize.add_item('Entrega de un ejemplar de la guía tecnológica para el manejo integral del sistema '+
                                         'productivo de la caña panelera y una para el mantenimiento de la hornilla.')

                    Parrafo= ('Cualquier inquietud AGROSAVIA está presta a atenderla.\n'+
                              'Cordial saludo.\n'+
                              '\n \n \n'+
                              'AGROSAVIA (Corporación colombiana de investigación agropecuaria)')            
                    tlg.append(Parrafo)            

                    Parrafo= ('\n \n Nota: Está propuesta de valor se basa en condiciones del terreno ideales y estacionarias, por lo que, '+
                              'AGROSAVIA no se hace responsable de la reproducción total o parcial del material aquí suministrado sin una aprobación '+
                              'corporativa.')
                    tlg.append(Parrafo)
                    
        doc.append(NewPage())
        
        with doc.create(MediumText(' ')) as tlg:
                    tlg.append(LargeText(bold('Contenido')))
                    with tlg.create(Itemize()) as itemize:
                                            itemize.add_item('Sección 1')
                                            with itemize.create(Itemize()) as item:
                                                        item.add_item('Información del usuario.')
                                                        item.add_item('Características de la caña sembrada.')
                                                        item.add_item('Características del molino.')
                                                        item.add_item('Consideraciones generales para el manejo de la hornilla.')
                                                        item.add_item('Análisis financiero.')
                                            itemize.add_item('Sección 2')
                                            with itemize.create(Itemize()) as item:
                                                        item.add_item('Diagramas mecánicos de la hornilla.')
                                                        item.add_item('Diagramas mecánicos de la camára.')
                                                        item.add_item('Diagramas mecánicos de la chimenea.')
                                                        item.add_item('Diagramas mecánicos del ducto.')
                                                        item.add_item('Diagramas mecánicos de la hornilla con recuperador de calor.')
        doc.append(NewPage())

        #PORTADA PARA LA SECCIÓN 1 
        
        with doc.create(Center()) as centered:
                    centered.append(TextColor('white','HH')) 
                    for i in range(15):
                        centered.append(LineBreak())   
                    centered.append(HugeText('SECCIÓN 1:'))
                    centered.append(LineBreak())
                    centered.append(HugeText('INFORMACIÓN TÉCNICA Y FINANCIERA')) 
        doc.append(NewPage())
Пример #15
0
    def seccion1(D1, D2):
        global doc
        '''>>>>>>>>>>>>>>>Presentación de los datos de usuario<<<<<<<<<<<<<<<<<'''        
        doc = Documento_Latex.titulos_I (doc, 'DATOS DEL USUARIO PARA GENERAR EL INFORME')   
        with doc.create(Tabular('lccccl')) as table:
            for i in D1:
                if(str(i)=='DATOS DE ENTRADA'):
                    break
                else:
                    if((SM(None, 'Altura', i).ratio()<0.85) and
                       (SM(None, 'Variedad de Caña', i).ratio()<0.85) and
                       (SM(None, 'Usa fertilizante', i).ratio()<0.85) and
                       (SM(None, 'Grados Brix de la panela (promedio)', i).ratio()<0.85) and
                       (SM(None, '--', str(D1[i])).ratio()<0.85)):
                        T1=str(D1[i])
                        #Arreglo para asignar unidades y mostrarlas en el informe
                        if (str(i)=='Área caña sembrada'):
                            T1=str(D1[i])+" ha" 
                        elif (str(i)=='Crecimiento aproximado del área sembrada'):
                            T1=str(D1[i])+" ha"
                        elif (str(i)=='Caña esperada por hectárea'):
                            T1=str(D1[i])+" t/ha"
                        elif (str(i)=='Número de moliendas'):
                            T1=str(D1[i])+" semanal(es)"                    
                        elif (str(i)=='Periodo vegetativo'):
                            T1=str(D1[i])+" mes(es)"                   
                        elif (str(i)=='Caña molida al mes'):
                            T1=str(D1[i])+" t/mes" 
                        elif (str(i)=='Área cosechada al mes'):
                            T1=str(D1[i])+" ha/mes" 
                        elif (str(i)=='Caña molida a la semana'):
                            T1=str(D1[i])+" t/semana" 
                        elif (str(i)=='Caña molida por Hora'):
                            T1=str(D1[i])+" t/hora"
                        elif (str(i)=='Área cosechada al mes'):
                            T1=str(D1[i]*12)+" L/año"
                        elif (str(i)=='Caña molida al año'):
                            T1=str(D1[i])+" t/año"
                        elif (str(i)=='Jugo producido al año'):
                            T1=str(D1[i])+" t/año"
                        elif (str(i)=='Bagazo secado al año'):
                            T1=str(D1[i])+" t/año"
                        table.add_row((bold(str(i)), ' ', ' ', ' ', ' ',T1))
        doc.append(NewPage())
        
        '''>>>>>>>>>>>>>>>>>>>>Presentación de los datos de la caña<<<<<<<<<<<<<<<<<<<<<<<'''
        doc = Documento_Latex.titulos_I (doc, 'CARACTERÍSTICAS DE LAS VARIEDADES DE CAÑA SELECCIONADAS')
        Canas=pd.read_excel('static/Temp/Temp4.xlsx',skipcolumn = 0,)
        Carpe=pd.read_excel('static/Temp/Temp5.xlsx',skipcolumn = 0,)
        Eti = Canas.iloc[0].values
        Val = Canas.iloc[1].values
        Car = Carpe.iloc[0].values
        
        conta=1
        for i in range (len(Car)-1):
            with doc.create(Tabular('lcccccl')) as table:
                for j in range (1,8):
                    table.add_row((bold(str(Eti[conta])), ' ', ' ', ' ', ' ', ' ', str(Val[conta])))
                    conta=conta+1
                conta=conta+1
            doc.append(LineBreak())
            doc.append('\n')
            doc.append(LineBreak())
        
        for i in range (1,len(Car),3):
            with doc.create(Figure(position='h!')) as imagesRow1:
                for j in range(3):
                    if((i+j)<len(Car)):
                        with doc.create(
                            SubFigure(width=NoEscape(r'0.33\linewidth'))) as left_imagesRow1:
                            left_imagesRow1.add_image(Car[i+j], width=NoEscape(r'0.95\linewidth'))
                            left_imagesRow1.add_caption('Variedad de caña '+str(i+j))
                imagesRow1.append(LineBreak())
                imagesRow1.append(NewPage())  
        
        doc.append(NewPage())
        doc.append(TextColor('white','HH')) 
        doc.append(NewPage())
        
        '''>>>>>>>>>>>>>>>>>>>>Presentación de los molinos seleccionados<<<<<<<<<<<<<<<<<<<<<<<'''   
        doc = Documento_Latex.titulos_I (doc, 'MOLINOS PRESELECCIONADOS PARA ESTE DISEÑO')
        Molino=pd.read_excel('static/Temp/Temp.xlsx',skipcolumn = 0,)
        Carpe=pd.read_excel('static/Temp/Temp5.xlsx',skipcolumn = 0,)
        Eti = Canas.iloc[0].values
        Val = Canas.iloc[1].values
        Car = Carpe.iloc[0].values
        Marca=Molino['Marca'].values
        Modelo=Molino['Modelo'].values
        Kilos=Molino['kg/hora'].values
        Diesel=Molino['Diesel'].values
        Electrico=Molino['Electrico'].values
        Valor=Molino['Precio'].values

        with doc.create(Tabular('lcccccl')) as table:
                table.add_row((TextColor('red',bold('VALOR APROXIMADO DE UN MOLINO: ')),
                               ' ', ' ', ' ', ' ', ' ', 
                               TextColor('red', Documento_Latex.Formato_Moneda(sum(Valor)/len(Valor), "$", 2))))
        doc.append(LineBreak())
                
        with doc.create(Tabular('ccccc')) as table:  
            table.add_row("MARCA", "MODELO", "KG POR HORA", "DIESEL O GASOLINA (HP)", "ELÉCTRICO (HP)")
            table.add_empty_row()
            for i in range(len(Marca)):
                table.add_row(str(Marca[i]),
                              str(Modelo[i]), 
                              str(Kilos[i]), 
                              str(Diesel[i]), 
                              str(Electrico[i]))
                
            doc.append(LineBreak())
            doc.append('\n')
            doc.append(LineBreak())
        
        for i in range (1,len(Modelo),3):
            with doc.create(Figure(position='h!')) as imagesRow1:
                for j in range(3):
                    if((i-1)+j<len(Modelo)):
                        with doc.create(
                            SubFigure(width=NoEscape(r'0.33\linewidth'))) as left_imagesRow1:
                            left_imagesRow1.add_image('Molinos/'+str(Modelo[(i-1)+j]+'.jpg'), width=NoEscape(r'0.95\linewidth'))
                            left_imagesRow1.add_caption(str(Modelo[(i-1)+j]))
                imagesRow1.append(LineBreak())
                imagesRow1.append(NewPage()) 
        
        doc.append(NewPage())
        doc.append(TextColor('white','HH')) 
        doc.append(NewPage())                

        #MANUAL DE OPERACIÓN DE LA HORNILLA                   
        with doc.create(MediumText(' ')) as tlg:
                    tlg.append(LargeText(bold('Consideraciones para el manejo de la hornilla')))
                    
                    Parrafo= ('\n \nEl trapiche panelero es un lugar donde se procesa la caña de azúcar para producir la panela. Está constituido por las áreas de molienda, prelimpieza, hornilla, moldeo y almacenamiento.')           
                    tlg.append(Parrafo)

                    Parrafo= ('\n La hornilla panelera, está conformada, por el cenicero, la cámara, la chimenea y el ducto, sobre el cual se asientan directamente los intercambiadores de calor, en los que se deposita el jugo. En la hornilla panelera, se genera y transfiere el calor necesario para concentrar en un sistema de evaporación abierta, el jugo de la caña; de tal forma que la cantidad de energía aprovechada se relaciona directamente con el suministro de aire y bagazo, la eficiencia de la combustión, y la cantidad de energía disipada a los alrededores. Estas variables de operación y transferencia se relacionan entre si y debido a su complejidad y cantidad, dificultan las tareas de manipulación y diseño de la hornilla.')           
                    tlg.append(Parrafo)
                    
                    tlg.append(LargeText(bold('\n \n Manejo de las hornillas paneleras')))
                    
                    with tlg.create(Itemize()) as itemize:
                                            itemize.add_item('Tenga en cuenta las siguientes indicaciones.')
                                            with itemize.create(Itemize()) as item:
                                                        item.add_item('Durante las pruebas iniciales y periodos de capacitación, los operarios que manejan la hornilla deben tener experiencia para evitar la disminución en la calidad de la panela y vida util de los equipos instalados.')
                                                        item.add_item('El trabajo continuo de la hornilla aumenta la capacidad de producción y evita la perdida de energía, puesto que, al no enfriarse durante las horas de la noche se reduce el efecto del cambio térmico sobre los ladrillos de la estructura.')
                                                        item.add_item('La combustión en la hornilla será buena, si se alimenta con pequeñas cantidades de bagazo cada 150 segundos y la válvula de la chimenea tiene una apertura 60° para garantizar un flujo de aire suficientemente alto que produzca llama, sin arrastrar combustible en los gases residuales.')
                                                        item.add_item('La entrada de aire por orificios diferentes a los proyectados en el diseño inicial debe evitarse a toda costa, para aumentar la eficiencia de la combustión y reducir el material particulado de los gases en la chimenea.')
                                                        item.add_item('Elimine obstáculos en las entradas de aire diseñadas para la hornilla y retire periódicamente la ceniza la parrilla para evitar la formación de escoria.')
                                                        item.add_item('El cenicero y su entrada deben mantenerse despejada a fin de no obstruir el paso del aire.')
                                                        item.add_item('El bagazo para alimentar la hornilla debe tener las condiciones de humedad mencionadas en el diseño.')
                                                        item.add_item('Almacene el bagazo por dos semanas en la bagacera, y así, obtendrá un bagazo con al menos un 30% de humedad.')
                                                        item.add_item('Ajuste el tiro de la chimenea usando la válvula mariposa cuando tenga bagazo con mayor humedad.')
                                                        item.add_item('La válvula no opera en tiempo real y cuando se encuentra a medio cerrar se aumenta la velocidad de calentamiento en la zona de evaporación al pie de la entrada del bagazo. Sin embargo, cuando se encuentra abierta el calentamiento se presenta al pie de la chimenea.')
                                                        item.add_item('El tiempo de residencia del jugo en la hornilla, influye en la calidad de la panela y este es directamente proporcional al aumento de los azucares invertidos.')
                                                        item.add_item('Las falcas en las pailas son de seguridad, no deben usarse para contener una mayor cantidad de jugo. Por tanto para aumentar la transferencia de calor al jugo y mejorar la calidad de la panela es importante manejar la cantidad de jugo mínima en cada paila.')
                                                        item.add_item('El nivel del jugo en las pailas semiesféricas, siempre debe estar por encima de la línea de contacto de los gases de combustión con la paila a fin de evitar quemadura en la panela.')
                                                        item.add_item('La paila clarificadora debe calentar lo más rápido posible para que permita remover la cachaza. Además, la velocidad mínima de calentamiento debe ser de 1.5°C/min.')
                                                        item.add_item('Elimine residuos de la caña o jugos presentes sobre la superficie de las pailas concentradoras de panela y cachaza periódicamente, para que el producto se pegue al fondo. Lo cual disminuye el paso del calor y deterioran la calidad del producto.')

                    tlg.append(LargeText(bold('Mantenimiento de la hornilla')))
                    
                    with tlg.create(Itemize()) as itemize:
                                            itemize.add_item('Después de cada molienda.')
                                            with itemize.create(Itemize()) as item:
                                                        item.add_item('Limpie y desinfecte las instalaciones, pailas, equipos y utensilios, antes de iniciar nuevamente la producción de panela.')
                                                        item.add_item('Un encelamiento de los moldes, utensilios de madera y prelimpiadores.')
                                                        item.add_item('Dejar en remojo con agua limpia las pailas durante el enfriamiento de la hornilla.')
                                                        item.add_item('Retirar la ceniza del cenicero y el ducto.')
                                                   
                    with tlg.create(Itemize()) as itemize:
                                            itemize.add_item('Cada seis moliendas.')
                                            with itemize.create(Itemize()) as item:
                                                        item.add_item('Retirar el hollín formado en la superficie de las pailas, por donde se transfiere el calor.')
                                                        item.add_item('Limpiar los ductos de las pailas piro-tubulares, con ayuda de un raspador o un costal de fique.')
    
                    with tlg.create(Itemize()) as itemize:
                                            itemize.add_item('Cada seis meses.')
                                            with itemize.create(Itemize()) as item:
                                                        item.add_item('Realice una limpieza general e inspección del estado de los ductos.')
                                                        item.add_item('Realice un mantenimiento de las paredes del ducto y la cámara.')
                                                        
                    tlg.append(LargeText(bold('Recomendaciones de construcción del trapiche')))
                    
                    with tlg.create(Itemize()) as itemize:
                                            itemize.add_item('Algunos parámetros para tener en cuenta son.')
                                            with itemize.create(Itemize()) as item:
                                                        item.add_item('El suministro de agua ser potable y continuo.')
                                                        item.add_item('Los alrededores de las fábricas deben estar libre de posibles focos de infección.')
                                                        item.add_item('Las áreas de trabajo de cada subproceso deben estar delimitadas.')
                                                        item.add_item('Las áreas de procesamiento y empaque deben estar separadas de las áreas de recepción y desechos.')
                                                        item.add_item('Las uniones de las baldosas deben recubrirse de materiales plásticos que faciliten la limpieza.')
                                                        item.add_item('Las salientes de las paredes, dinteles de ventanas y suspensiones del techo deben ser curvas e inclinadas.')
                                                        item.add_item('Los pisos y las paredes se deben construir con materiales anticorrosivos, no absorbentes y de alto transito.')
                                                        item.add_item('Las áreas de procesos deben tener en el centro un canal de drenaje con 3° de inclinación y una parrilla removible para realizar su limpieza.')
                                                        item.add_item('Los pisos deben tener una leve inclinación (3°) para realizar el drenado.')
                                                        item.add_item('Los desagües deben tener rejillas de seguridad para impedir el paso de animales.')
                                                        item.add_item('Los ambientes debe ser ventilados.')
                                                        item.add_item('Los vapores deben contar con su propio escape para evitar la presencia de moho en paredes y techos.')
                                                        item.add_item('Los ductos de ventilación deben estar cubiertos de mallas protectoras.')
                                                        item.add_item('Los ambientes deben estar bien iluminados.')
                                                        item.add_item('Las bases o cimientos deben ser lisos para evitar la presencia de insectos o residuos.')
                                                        item.add_item('Los espacios entre los equipos o equipos y paredes deben estar sellados.')
                                                        item.add_item('Los baños, habitaciones y casilleros, deben estar aseados y alejados de las áreas de procesamiento y producto terminado.')
                                                        item.add_item('Las diferentes áreas deben disponer de un sitio para el aseo de las manos con sus respectivos implementos, tales como; jabón líquido, cepillos y toallas desechables.')

                    tlg.append(LargeText(bold('Higiene y desinfección en el trapiche')))
                   
                    with tlg.create(Itemize()) as itemize:
                                            itemize.add_item('Tenga en cuenta las siguientes indicaciones para su cuidado personal.')
                                            with itemize.create(Itemize()) as item:
                                                        item.add_item('El objetivo de la higiene en los alimentos es alargar la vida útil del producto, y proteger al consumidor final de las enfermedades producidas al ingerir alimentos contaminados.')
                                                        item.add_item('La higienización de un trapiche requiere de una limpieza con detergente y de una esterilización industrial o satanización (desinfectante y bactericida).')
                                                        item.add_item('Los equipos y utensilios deben limpiarse y desinfectarse al final e inicio de cada molienda.')
                                                        item.add_item('La limpieza se realiza siguiendo estas pautas: proteger las materias prima y los productos terminados, raspar los residuos sólidos con una espátula sobre un recogedor y lavar con agua limpia, cepillo y detergente')
                                                        item.add_item('La esterilización se realiza con calor (vapor de agua, agua hirviendo), o un esterilizante químico (bactericida, desinfectante).Cuando se emplea agua caliente debe estar hirviendo (90°C) o en el caso del esterilizante químico puede usarse una solución clorada, de vinagre y una lechada de cal.')
                                                        item.add_item('Las soluciones desinfectantes deben aplicarse en solución con un rociador, empezando por la parte inferior.')
                                                        item.add_item('Antes de la esterilización la superficie debe estar limpia y totalmente escurrida.')
                                                        item.add_item('Las superficies en contacto con el alimento deben ser lisas, exentas de huecos, grietas y evitar las esquinas cuadradas.')
                                                        item.add_item('La industria de alimentos usa ampliamente el acero inoxidable y plásticos como el teflón por la facilidad de higienización, y su poca alteración al contacto con los alimentos.')
                                                        item.add_item('No debe usarse el cobre, bronce, estaño, aluminio, madera y zinc para las superficies que están en contacto con el alimento.')
                                                        item.add_item('No emplee en la limpieza esponjas o cepillos metálicos que rayen las superficies.')
                                                        item.add_item('Las pailas se lavan con arena de peña y esponja para desmancharla.')
                                                        item.add_item('Ningún tipo de rosca debe estar en contacto con el alimento.')
                                                        item.add_item('Se debe mantener una inclinación de superficies y tubería para el drenaje de 1 centímetro por metro.')
                                                        item.add_item('Se deben usar conexiones hidraulicas y uniones que sean de fácil limpieza.')
                                                        item.add_item('Se debe evitar la unión de acero inoxidable con otros metales.')
                                                        item.add_item('El hipoclorito ejerce una rápida acción bactericida sin dejar residuos tóxicos.')
                                                        item.add_item('No es aconsejable el uso de cloro en material de acero inoxidable.')
                                                        item.add_item('En la esterilización del acero inoxidable, puede utilizarse agua caliente, vapor o solución de 0.25 litros de vinagre en 10 litros de agua.')
                                                        item.add_item('Los materiales plásticos se deben lavar con una solución de 5.0 gramos de bicarbonato (2 cucharadas) en l0 litros de agua clorada y dejar secar durante 30 minutos.')
                                                        item.add_item('La esterilización del acero inoxidable puede hacerse con agua caliente, vapor o solución de 0.25 litros de vinagre en 10 litros de agua.')
                                                        item.add_item('Las superficies de madera se limpian con espátula para eliminar los residuos sólidos. Después remojar en detergente durante 5 minutos, luego cepillar, lavar con agua limpia, y finalmente rociar con solución de 12 gramos de cal (una cucharadita) en 10 litros de agua dejar secar.')  
                                                        item.add_item('Los utensilios de madera se dejan en un recipiente plástico limpio, con solución de 12 gramos de cal (una cucharadita) en 10 litros de agua.')  
                                                        item.add_item('Cambiar la solución donde se sumergen los utensilios de madera cada cuatro horas.') 
                                                        item.add_item('Los utensilios y gaveras no deben dejarse sobre el suelo o superficies no desinfectadas.') 
                                                        item.add_item('Evitar la caída de grasa mecánica en los alimentos.')

        doc.append(NewPage())