Ejemplo n.º 1
0
def fazer_tree(lista: list, lista_pai: LISTA_TREE_VIEW, db, collection_aux):
    total = 0
    for item in lista:
        if item['percentContaining'] == 100:
            total = item['totalOccurrences']
        if not "." in item['_id']['key']:
            nova_lista = lista_pai.add_lista()
            aux_occoridos = Alib.format_numero(item['totalOccurrences'])
            nova_lista.add_texto(
                f"""<strong>{item['_id']['key']}</strong> <br>QTD:{aux_occoridos}<br>{Alib.format_numero(item["percentContaining"])}%"""
            )
            for tipo in item['value']['types']:
                tipo_list = nova_lista.add_lista()
                aux_txt = f"""class <strong>{tipo}</strong> <br>{fazer_str_porcentagem(item['value']['types'][tipo],item['totalOccurrences'])}"""
                tipo_list.add_texto(aux_txt)
                if tipo == 'Object' or tipo == 'Array':
                    fazer_tree_extra(lista, tipo_list,
                                     item['totalOccurrences'],
                                     item['_id']['key'], tipo, db,
                                     collection_aux)
                else:
                    fazer_list_aggregate(item['_id']['key'], nova_lista, db,
                                         collection_aux,
                                         item['totalOccurrences'])
    lista_pai.add_texto(f"""<br>QTD: {Alib.format_numero(total)}""")
Ejemplo n.º 2
0
def fazer_tree_extra(lista: list, lista_pai: LISTA_TREE_VIEW, universo_total,
                     key: str, tipo_extra: str, db, collection_aux):
    lista_feitos = []
    lista_feitos_2 = []
    aux_empty_array = False
    if tipo_extra == 'Array':
        aux_empty_array = True
    for item in lista:
        condicao = False
        if tipo_extra == 'Object':
            if item['_id']['key'].startswith(
                    key +
                    ".") and not item['_id']['key'].startswith(key + ".XX."):
                condicao = True
        elif tipo_extra == 'Array':
            if item['_id']['key'].startswith(key + ".XX."):
                condicao = True
                aux_empty_array = False
        if condicao and comparacao_feitos(item['_id']['key'], lista_feitos):
            nova_lista = lista_pai.add_lista()
            aux_occoridos = Alib.format_numero(item['totalOccurrences'])
            nova_lista.add_texto(
                f"""<strong>{item['_id']['key']}</strong> <br>QTD:{aux_occoridos}<br>{Alib.format_numero(item['totalOccurrences']*100/universo_total)}%"""
            )
            for tipo in item['value']['types']:
                tipo_list = nova_lista.add_lista()
                aux_txt = f"""class <strong>{tipo}</strong> <br>{fazer_str_porcentagem(item['value']['types'][tipo],item['totalOccurrences'])}"""
                tipo_list.add_texto(aux_txt)
                if tipo == 'Object' or tipo == 'Array':
                    fazer_tree_extra(lista, tipo_list,
                                     item['totalOccurrences'],
                                     item['_id']['key'], tipo, db,
                                     collection_aux)
                    lista_feitos.append(item['_id']['key'] + ".")
                else:
                    if not item['_id']['key'] in lista_feitos_2:
                        lista_feitos_2.append(item['_id']['key'])
                        fazer_list_aggregate(item['_id']['key'], nova_lista,
                                             db, collection_aux,
                                             item['totalOccurrences'])
    if aux_empty_array:
        lista_pai.add_texto("<br>ARRAY(s) VAZIO")
Ejemplo n.º 3
0
def fazer_list_aggregate(key: str, lista_pai: LISTA_TREE_VIEW, db,
                         collection_aux, total):
    key = key.replace('.XX.', ".$.")
    id_auxiliar = key.replace(".$.", '.')
    lista_aux = lista_pai.add_lista()
    lista_aux.add_texto('COMMON ITENS')
    itens_list = lista_aux.add_lista()
    aggregate_array_end = []
    key_split = key.split('.$.')[:-1]
    soma_key = ''
    for unwind in key_split:
        soma_key += unwind
        aux = {'$unwind': {'path': '$' + soma_key}}
        aggregate_array_end.append(aux)
        soma_key += '.'
    aggregate_array_end.append(
        {'$group': {
            '_id': '$' + id_auxiliar,
            'SOMA': {
                '$sum': 1
            }
        }})
    aggregate_array_end.append({'$sort': {'SOMA': -1}})
    aggregate_array_end.append({'$limit': 30})

    table_aux = FAZER_TABLE()
    table_aux.tabela_completa(class_table='')
    line_aux = table_aux.add_line_head()
    line_aux.aling_center()
    line_aux.celulas_head()
    line_aux.adicionar_celula('ITEM')
    line_aux.adicionar_celula('CONT')
    line_aux.adicionar_celula('%')
    for item in DB_CLIENT[db][collection_aux].aggregate(aggregate_array_end):
        line_aux = table_aux.add_line_body()
        line_aux.aling_center()
        line_aux.adicionar_celula(format_item(item["_id"]))
        line_aux.adicionar_celula(str(item["SOMA"]))
        line_aux.adicionar_celula(
            Alib.format_numero(item["SOMA"] * 100 / total))
    itens_list.add_texto(table_aux.end())