<commit_before>import operator
import re
from pprint import pprint

from django.shortcuts import render
from django.urls import reverse
from django.views import View

from utils.views import group_rowspan, totalize_grouped_data

import lotes.models


class VisaoCd(View):

    def __init__(self):
        self.template_name = 'cd/visao_cd.html'
        self.title_name = 'Visão do CD'

    def mount_context(self):
        context = {}

        lotes_recs = lotes.models.Lote.objects.all().exclude(
            local__isnull=True
        ).exclude(
            local__exact=''
        ).values(
            'local', 'lote', 'qtd'
        ).order_by('local')
        if len(lotes_recs) == 0:
            return context

        ruas = {}
        for lote in lotes_recs:
            try:
                rua = re.search('^[A-Z]+', lote['local']).group(0)
            except AttributeError:
                rua = '#'
            if rua in ruas:
                ruas[rua]['ends'].add(lote['local'])
                ruas[rua]['qlotes'] += 1
                ruas[rua]['qtdsum'] += lote['qtd']
            else:
                ruas[rua] = {
                    'ends': set([lote['local']]),
                    'qlotes': 1,
                    'qtdsum': lote['qtd'],
                }

        data = [
            {
                'rua': rua,
                'qenderecos': len(ruas[rua]['ends']),
                'qlotes': ruas[rua]['qlotes'],
                'qtdsum': ruas[rua]['qtdsum'],
            }
            for rua in ruas
        ]

        for row in data:
            if row['rua'] in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']:
                row['order'] = 1
                row['area'] = 'Estantes'
            elif row['rua'].startswith('Q'):
                row['order'] = 2
                row['area'] = 'Quarto andar'
            elif (
                    row['rua'].startswith('S') or
                    row['rua'].startswith('Y')
                 ):
                row['order'] = 3
                row['area'] = 'Externo'
            else:
                row['order'] = 4
                row['area'] = 'Indefinido'

        data.sort(key=operator.itemgetter('order', 'rua'))

        headers = ['Área', 'Rua', 'Endereços', 'Lotes (caixas)', 'Qtd. itens']
        fields = ['area', 'rua', 'qenderecos', 'qlotes', 'qtdsum']

        for row in data:
            row['qenderecos|LINK'] = reverse(<commit_msg>view VisaoCd identificando endereços como lateral<commit_after>import operator
import re
from pprint import pprint

from django.shortcuts import render
from django.urls import reverse
from django.views import View

from utils.views import group_rowspan, totalize_grouped_data

import lotes.models


class VisaoCd(View):

    def __init__(self):
        self.template_name = 'cd/visao_cd.html'
        self.title_name = 'Visão do CD'

    def mount_context(self):
        context = {}

        lotes_recs = lotes.models.Lote.objects.all().exclude(
            local__isnull=True
        ).exclude(
            local__exact=''
        ).values(
            'local', 'lote', 'qtd'
        ).order_by('local')
        if len(lotes_recs) == 0:
            return context

        ruas = {}
        for lote in lotes_recs:
            try:
                rua = re.search('^[A-Z]+', lote['local']).group(0)
            except AttributeError:
                rua = '#'
            if rua in ruas:
                ruas[rua]['ends'].add(lote['local'])
                ruas[rua]['qlotes'] += 1
                ruas[rua]['qtdsum'] += lote['qtd']
            else:
                ruas[rua] = {
                    'ends': set([lote['local']]),
                    'qlotes': 1,
                    'qtdsum': lote['qtd'],
                }

        data = [
            {
                'rua': rua,
                'qenderecos': len(ruas[rua]['ends']),
                'qlotes': ruas[rua]['qlotes'],
                'qtdsum': ruas[rua]['qtdsum'],
            }
            for rua in ruas
        ]

        for row in data:
            if row['rua'] in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']:
                row['order'] = 1
                row['area'] = 'Estantes'
            elif row['rua'].startswith('QA'):
                row['order'] = 2
                row['area'] = 'Quarto andar'
            elif row['rua'].startswith('LB'):
                row['order'] = 3
                row['area'] = 'Lateral'
            elif (
                    row['rua'].startswith('S') or
                    row['rua'].startswith('Y')
                 ):
                row['order'] = 4
                row['area'] = 'Externo'
            else:
                row['order'] = 5
                row['area'] = 'Indefinido'

        data.sort(key=operator.itemgetter('order', 'rua'))

        headers = ['Área', 'Rua', 'Endereços', 'Lotes (caixas)', 'Qtd. itens']
        fields = ['area', 'rua', 'qenderecos', 'qlotes', 'qtdsum']

        for row in data:
            row['qenderecos|LINK'] = reverse(
{'fraction_non_alphanumeric': 0.152555910543131, 'fraction_numerical': 0.0033945686900958465, 'mean_word_length': 1.4590083456062837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7024896', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1542, 'n_words': 326}