Ejemplo n.º 1
0
    def addDocumento(self, nome, text):
        posicao = self.pesquisarDocumento(nome)
        if posicao == -1:
            doc = Documento(nome, text)
            doc.remove_stopwords()
            doc.processar(self)

            self.qtToken += doc.qtTokenTotal
            self.qtStopword += doc.qtStopwordTotal
            self.qtAdverbio += doc.qtAdverbioTotal

            self.listDocuments.append(doc)
            self.qtDocumentos += 1
            self.updateIdf()
            return doc
        else:
            print('O documento %s já está na coleção' % (nome))
            return -1
Ejemplo n.º 2
0
import os
from time import perf_counter
from xml.etree.ElementTree import parse

from yattag.indentation import indent
from documento import Documento

inicio_tempo = perf_counter()

if 'tools' in os.getcwd():
    os.chdir('../')

# Constituição
caminho_documento = os.path.join(os.getcwd(), 'constituicao.xml')

constituicao = Documento(parse(caminho_documento).getroot())

with open('docs/constituicao.html', mode='w', encoding='utf-8') as f:
    f.write(indent(constituicao.gerar_html().getvalue(), indentation='    '))

# Código de Disciplina
caminho_documento = os.path.join(os.getcwd(), 'codigo_de_disciplina.xml')

codigo_de_disciplina = Documento(parse(caminho_documento).getroot())

with open('docs/codigo_de_disciplina.html', mode='w', encoding='utf-8') as f:
    f.write(
        indent(codigo_de_disciplina.gerar_html().getvalue(),
               indentation='    '))

# Princípios de Liturgia
Ejemplo n.º 3
0
print(" (1) CPF")
print(" (2) CNPJ")
print(" (3) Telefone")
print(" (4) CEP", end="\n\n")

while (True):

    var_opcao = int(input("Digite a sua opção de validação: "))

    if (var_opcao >= 1 and var_opcao <= 4):
        print("", end="\n")

        if (var_opcao == 1):

            #Cria uma instância da classe Documento
            obj_documento = Documento(input("Digite um número de CPF: "))
            print(obj_documento)

        elif (var_opcao == 2):

            #Cria uma instância da classe Documento
            obj_documento = Documento(input("Digite um número de CNPJ: "))
            print(obj_documento)

        elif (var_opcao == 3):

            #Cria uma instância da classe Telefone
            obj_telefone = Telefone(input("Digite um número de Telefone: "))
            print(obj_telefone)

        else:
Ejemplo n.º 4
0
def processa_planilha(nome_disciplina, nome_fase, complete):

    # constroi um data frame a partir de um arquivo

    print("Disciplina", nome_disciplina)
    original = os.getcwd()
    try:
        doc = Documento(nome_disciplina)
        path = os.path.join(nome_fase, nome_disciplina)
        try:
            os.makedirs(path)
        except FileExistsError:
            pass
        os.chdir(path)

        data_fase = complete[complete["fase"] == nome_fase]
        data = data_fase[data_fase["disciplina"] == nome_disciplina]
        # data = complete[complete["disciplina"] == nome_disciplina]
        data = data.drop(['disciplina', 'fase'], axis=1)

        for d in data:
            logging.info("SERIES ={}".format(d))
        for i, series in enumerate(natsorted(d for d in data)):
            if series:
                print("Pergunta:", series)

                group_planilha = agrupa(complete, series)
                group_fase = agrupa(data_fase, series)
                group = agrupa(data, series)
                # import pdb; pdb.set_trace()

                nomefig = Path("figura{}.svg".format(i))
                if group.empty:
                    pass
                    # doc.add_pergunta_textual(series, ["Nao houve respostas."])

                elif testa_resposta_textual(group):
                    doc.add_pergunta_textual(series, group.index)

                else:

                    def tot(g):
                        return g.drop([''], errors='ignore').sum()

                    def html(g):
                        return pd.DataFrame(g.drop([''],
                                                   errors='ignore')).to_html()

                    cria_grafico_generico(group, group_fase, group_planilha,
                                          nomefig)
                    doc.add_pergunta(series,
                                     (nomefig, tot(group), tot(group_fase),
                                      tot(group_planilha)))
                    # doc.add_pergunta_textual(series, map(html, [group, group_fase, group_planilha]))
                # break

        with open("index.html", "w") as f:
            f.write(doc.texto())
        os.chdir(original)
    except:
        print("falhei processando {}".format(nome_disciplina))
        traceback.print_exc()
        import pdb
        pdb.set_trace()
        os.chdir(original)
        exit(0)
Ejemplo n.º 5
0
    def __init__(self, json, input_enable):
        documento = Documento(self.src_template)
        json_gral_table = {
            "rows": 4,
            "cols": 6,
            "thead": { # Headers by rows
                0: {
                    "style": "bold",
                    "text": {
                        0: "Proyeccion de Crecimiento de Base de Datos"
                    }
                },
                1: {
                    "style": "bold",
                    "text": {
                        0: "Nombre",
                        1: "Motor de Base de Datos",
                        2: "Tamanio inicial",
                        3: "Modelo de crecimiento",
                        4: "Proyeccion",
                    }
                },
                2: {
                    "style": "bold",
                    "text": {
                        4: "1 anio",
                        5: "2 anios",
                    }
                },
            },
            "tbody": {
                3: {
                    "style": "normal",
                    "text": {
                        0: str(json["schema"]),
                        1: str(json["db_engine"]),
                        2: documento.bytesToMb(json["initial_size"]),
                        3: "FORMULA",
                        4: documento.bytesToMb(json["proyection"]["1y"]),
                        5: documento.bytesToMb(json["proyection"]["2y"])
                    }
                },
            },
            "merge": [
                {"a": [0, 0], "b": [0, 5]},

                {"a": [1, 0], "b": [2, 0]},
                {"a": [1, 1], "b": [2, 1]},
                {"a": [1, 2], "b": [2, 2]},
                {"a": [1, 3], "b": [2, 3]},

                {"a": [1, 4], "b": [1, 5]},
            ]
        }

        documento.createHeading("\n\t1.1 General\n")
        documento.createTable(json_gral_table)
        documento.createHeading("\n\t1.2 Espesificacion\n")

        json_espesification_table = {
            "rows": len(json["tables"]) + 1,
            "cols": 8,
            "thead": {  # Headers by rows
                0: {
                    "style": "bold",
                    "text": {
                        0: "Nombre Tabla",
                        1: "Numero Registros",
                        2: "Tamanio Registro",
                        3: "Tamanio Tabla",
                        4: "Tamanio indices",
                        5: "Tamanio total",
                        6: "Proyeccion a 1 ano",
                        7: "Proyeccion a 2 anos"
                    }
                }
            },
            "tbody": {}
        }
        t = 1  # Because thead is 0
        for json_table in json["tables"]:
            json_espesification_table["tbody"][t] = {
                "style": "normal",
                "text": {
                    0: str(json_table["name"]),
                    1: str(json_table["rows_count"]),
                    2: documento.bytesToMb(json_table["row_size"]),
                    3: documento.bytesToMb(json_table["table_size"]),
                    4: documento.bytesToMb(json_table["table_index"]),
                    5: documento.bytesToMb(json_table["total_size"]),
                    6: documento.bytesToMb(json_table["proyection"]["1y"]),
                    7: documento.bytesToMb(json_table["proyection"]["2y"])
                }
            }
            t += 1

        documento.createTable(json_espesification_table)
        # TODO - add parapraph
        documento.createHeading(
            "\n2. Anexos: Estimar el tamanio de una base de datos\n")
        for json_table in json["tables"]:
            json_table_table = {
                "rows": 2 + len(json_table["rows"]) + 1,
                "cols": 3,
                "thead": {  # Headers by rows
                    0: {
                        "style": "center",
                        "text": {
                            0: str(json_table["name"])
                        }
                    },
                    1: {
                        "style": "bold",
                        "text": {
                            0: "Columna",
                            1: "Tipo",
                            2: "Tamanio en bytes"
                        }
                    }
                },
                "tbody": {},
                "merge": [
                    {
                        "a": [0, 0],
                        "b": [0, 2]
                    },
                ]
            }
            r = 2
            for row in json_table["rows"]:
                json_table_table["tbody"][r] = {
                    "style": "normal",
                    "text": {
                        0: row["name"],
                        1: row["type"],
                        2: documento.bytesToMb(row["full_size"], True)
                    }
                }
                r += 1
            json_table_table["merge"].append({"a": [r, 0], "b": [r, 1]})
            json_table_table["tbody"][r] = {
                "style": "normal",
                "text": {
                    0: "Tamanio total en bytes:",
                    2: documento.bytesToMb(json_table["total_size_bytes"],
                                           True)
                }
            }

            string_dimen = "(  No Registros al anio) * " + str(
                json_table["total_size_bytes"]
            ) + " = Dimensionamiento de crecimiento de Tabla"
            if input_enable == 1:
                year_rows = input("\tNumero de registros al año:")
                bytes_dimen = year_rows * json_table["total_size_bytes"]
                string_dimen = str(year_rows) + " * " + str(
                    json_table["total_size_bytes"]) + " = " + bytesToMb(
                        bytes_dimen, bytes_dimen, True, 1) + " = " + bytesToMb(
                            bytes_dimen, True, 2)

            documento.createTable(json_table_table)
            documento.createParagraph("\n" + string_dimen + "\n")
        documento.save(self.output.replace("{schema}", json["schema"]))