Commit 6efc2d3ccd7e546e869c89fa6418bdfebd627e17

Authored by Macieski
1 parent ee3558b5
Exists in master

contagem campo da colta

wscacicneo/__init__.py
... ... @@ -28,6 +28,7 @@ def main(global_config, **settings):
28 28 cfg.add_route('root', '/')
29 29  
30 30 cfg.add_route('home', 'home')
  31 + cfg.add_route('error', 'error')
31 32 cfg.add_route('graficop', 'graficop')
32 33 cfg.add_route('notifications', 'notifications')
33 34 cfg.add_route('admin', 'admin')
... ...
wscacicneo/model/reports.py
... ... @@ -25,18 +25,62 @@ class Reports():
25 25 self.rest_url = config.REST_URL
26 26 else:
27 27 self.rest_url = rest_url
28   - self.base = coleta_manual.ColetaManualBase(nm_base, self.rest_url).lbbase
  28 + self.coleta_manual_base = coleta_manual.ColetaManualBase(nm_base, self.rest_url)
  29 + self.base = self.coleta_manual_base.lbbase
29 30 print(type(self.base))
30 31 self.documentrest = DocumentREST(self.rest_url, self.base, response_object=True)
31 32  
32 33  
33 34 def get_base_orgao(self):
34 35 """
35   - retorna todos os documentos da base
  36 + Retorna todos os documentos da base
36 37 """
  38 + # A resposta nao pode ser object aqui
  39 + self.documentrest.response_object = False
37 40 search = Search(
38 41 limit=None
39 42 )
40 43 get = self.documentrest.get_collection(search_obj=search)
41 44  
42 45 return get
  46 +
  47 + def get_attribute(self, attr):
  48 + """
  49 + Testa recuperar atributo do Documento
  50 + """
  51 + # A resposta nao pode ser object aqui
  52 + self.documentrest.response_object = False
  53 +
  54 + # FIXME: Adicionar lista de atributos obrigatórios nos campos que vao retornar na busca
  55 + # Referência: http://dev.lightbase.cc/projects/liblightbase/repository/revisions/master/entry/liblightbase/lbbase/content.py#L34
  56 +
  57 + # A busca deve obrigatoriamente retornar todos os atributos obrigatórios
  58 + search = Search(
  59 + limit=None,
  60 + select=[attr, "data_coleta"]
  61 + )
  62 + get = self.documentrest.get_collection(search_obj=search)
  63 +
  64 + return get
  65 +
  66 + def count_attribute(self, attr, child=None):
  67 + """
  68 + retorna dicionário de atributos agrupados por contador
  69 + """
  70 + attr_dict = self.get_attribute(attr)
  71 + results = attr_dict.results
  72 +
  73 + saida = dict()
  74 + for elm in results:
  75 + if child:
  76 + parent = getattr(elm, attr)
  77 + attribute = getattr(parent, child)
  78 + else:
  79 + attribute = getattr(elm, attr)
  80 +
  81 + if saida.get(attribute):
  82 + saida[attribute] = saida.get(attribute) + 1
  83 + else:
  84 + saida[attribute] = 1
  85 +
  86 + return saida
... ...
wscacicneo/templates/error.pt 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +<metal:main use-macro="load: master.pt">
  2 + <metal:content fill-slot="conteudo">
  3 +<div class="container">
  4 +
  5 + <div class="row">
  6 + <div class="col-md-12">
  7 + <!-- Widget starts -->
  8 + <div class="widget">
  9 + <!-- Widget head -->
  10 + <div class="widget-head">
  11 + <i class="fa fa-question-circle"></i> Error
  12 + </div>
  13 +
  14 + <div class="widget-content">
  15 + <div class="padd error">
  16 +
  17 + <h1>Opps!!! It's 404</h1>
  18 + <p>Aliquam consequat, purus vitae auctor ullamcorper, sem velit convallis quam, a pharetra justo nunc et mauris. </p>
  19 + <br>
  20 +
  21 + <div class="input-group input-group-width">
  22 + <input type="text" class="form-control">
  23 + <span class="input-group-btn">
  24 + <button class="btn btn-default" type="button">Search</button>
  25 + </span>
  26 + </div>
  27 +
  28 + <br>
  29 + <div class="horizontal-links">
  30 + <a href="index.html">Home</a></div>
  31 + </div>
  32 + <div class="widget-foot">
  33 + <!-- Footer goes here -->
  34 + </div>
  35 + </div>
  36 + </div>
  37 + </div>
  38 + </div>
  39 + </div>
  40 + </metal:content>
  41 + <metal:content fill-slot="javascript">
  42 + <script type="text/javascript">
  43 + </script>
  44 + </metal:content>
  45 +</metal:main>
... ...
wscacicneo/test/test_reports.py
... ... @@ -3,11 +3,12 @@
3 3 __author__ = 'eduardo'
4 4  
5 5 import unittest
  6 +import json
6 7 from wscacicneo.model import reports
7 8 from liblightbase.lbbase.struct import Base
8 9 from liblightbase.lbutils import conv
9 10  
10   -class TestOrgaoBase(unittest.TestCase):
  11 +class TestRelatorio(unittest.TestCase):
11 12 """
12 13 Testa base do órgão no LB
13 14 """
... ... @@ -22,8 +23,34 @@ class TestOrgaoBase(unittest.TestCase):
22 23 """
23 24 Testa busca o documento completo da base
24 25 """
25   - get_doc = reports.Reports(self.rest_url, self.nm_base)
26   - lbbase = get_doc.get_base_orgao
  26 + get_doc = reports.Reports(self.nm_base, self.rest_url)
  27 + lbbase = get_doc.get_base_orgao()
  28 + self.assertGreater(len(lbbase.results), 0)
  29 +
  30 + def test_get_attribute(self):
  31 + """
  32 + Teste recuperar um atributo específico da base
  33 + """
  34 + get_doc = reports.Reports(self.nm_base, self.rest_url)
  35 + coleta = get_doc.get_base_orgao()
  36 + hd = get_doc.get_attribute('hd')
  37 + self.assertGreater(len(hd.results), 0)
  38 +
  39 + def test_count_attribute(self):
  40 + """
  41 + Método que retora um dicionário de atributos agrupados com o valor
  42 + de ocorrência de cada um deles
  43 + """
  44 + get_doc = reports.Reports(self.nm_base, self.rest_url)
  45 + coleta = get_doc.get_base_orgao()
  46 + hd = get_doc.get_attribute('hd')
  47 + self.assertGreater(len(hd.results), 0)
  48 +
  49 + hd_count = get_doc.count_attribute('hd', 'tipo_hd')
  50 + fd = open('/tmp/teste.json', 'w+')
  51 + fd.write(json.dumps(hd_count))
  52 + fd.close()
  53 + self.assertGreater(len(hd_count.keys()), 0)
27 54  
28 55 def tearDown(self):
29 56 """
... ...
wscacicneo/utils/utils.py
... ... @@ -17,3 +17,4 @@ class Utils:
17 17 return True
18 18 else:
19 19 return False
  20 +
... ...