Browse Source

Adicionado novo dashboard de metas e gatilhos

stable/1.0
Sesostris Vieira 12 years ago
parent
commit
9f772bd2d9
  1. 44
      sigi/apps/metas/views.py
  2. 39
      sigi/templates/metas/dashboard.html
  3. 40
      sigi/templates/metas/snippets.html
  4. 1
      sigi/urls.py

44
sigi/apps/metas/views.py

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.http import HttpResponse from django.http import HttpResponse
from django.core.exceptions import PermissionDenied
from django.utils import simplejson from django.utils import simplejson
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
@ -12,10 +13,51 @@ from sigi.apps.convenios.models import Projeto, Convenio
from sigi.apps.contatos.models import UnidadeFederativa from sigi.apps.contatos.models import UnidadeFederativa
from sigi.apps.casas.models import CasaLegislativa from sigi.apps.casas.models import CasaLegislativa
from sigi.apps.utils import to_ascii from sigi.apps.utils import to_ascii
from apps.financeiro.models import Desembolso
from django.db.models.aggregates import Sum
from django.contrib.auth.decorators import user_passes_test, login_required
from sigi.settings import MEDIA_ROOT from sigi.settings import MEDIA_ROOT
JSON_FILE_NAME = MEDIA_ROOT + 'apps/metas/map_data.json' JSON_FILE_NAME = MEDIA_ROOT + 'apps/metas/map_data.json'
@login_required
def dashboard(request):
if request.user.groups.filter(name__in=['SPDT-Servidores', 'SSPLF']).count() <= 0:
raise PermissionDenied
desembolsos_max = 0
matriz = SortedDict()
dados = SortedDict()
projetos = Projeto.objects.all()
meses = Desembolso.objects.dates('data', 'month', 'DESC')[:6]
colors = ['ffff00', 'cc7900', 'ff0000', '92d050', '006600', '0097cc', '002776', 'ae78d6', 'ff00ff', '430080',
'28d75c', '0000ff', 'fff200']
for date in reversed(meses):
mes_ano = '%s/%s' % (date.month, date.year)
dados[mes_ano] = 0
for p in projetos:
matriz[p.id] = (p.sigla, dados.copy())
g_desembolsos = {'labels': [], 'legends': [p.sigla for p in projetos], 'data': [], 'max': 0, 'coisa': [] }
for date in meses:
mes_ano = '%s/%s' % (date.month, date.year)
g_desembolsos['labels'].append(mes_ano)
data = {p.id: 0 for p in projetos}
for d in Desembolso.objects.filter(data__year=date.year, data__month=date.month).values('projeto').annotate(total_dolar=Sum('valor_dolar')):
data[d['projeto']] = int(d['total_dolar'])
if int(d['total_dolar']) > desembolsos_max:
desembolsos_max = int(d['total_dolar'])
p = Projeto.objects.get(pk=d['projeto'])
matriz[d['projeto']][1][mes_ano] += int(d['total_dolar'])
g_desembolsos['data'].append(data.values())
meses = ["%s/%s" % (m.month, m.year) for m in reversed(meses)]
extra_context = {'desembolsos': matriz, 'desembolsos_max': desembolsos_max, 'meses': meses, 'colors': ','.join(colors[:len(matriz)])}
return render_to_response('metas/dashboard.html', extra_context, context_instance=RequestContext(request))
def mapa(request): def mapa(request):
""" """
Mostra o mapa com filtros carregados com valores default Mostra o mapa com filtros carregados com valores default

39
sigi/templates/metas/dashboard.html

@ -0,0 +1,39 @@
{% extends "admin/index.html" %}
{% load adminmedia %}
{% block title %}SIGI{% endblock %}
{% block extrahead %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelists.css" />
{% endblock %}
{% block content_title %}
<h1>Triggers e indicadores de progresso</h1>
<div id="changelist">
<div id="toolbar">
<p>Esta é a toolbar da changelist</p>
</div>
</div>
{% endblock %}
{% block content %}
<div class="colMS" id="content">
<div id="content-main">
{% include "metas/snippets.html" %}
</div>
</div>
{% endblock %}
{% block sidebar %}
<div id="content-related">
{% comment %}
<div class="module" id="filters">
<h2>Filtros</h2>
<h3>Filtro 1</h3>
</div>
{% endcomment %}
</div>
{% endblock %}

40
sigi/templates/metas/snippets.html

@ -0,0 +1,40 @@
{% load charts %}
{# ------------- Todas as metas ------------- #}
<div style="height: 300px;" class="module">
<h2>Todas as metas</h2>
<h3>Estado das metas do contrato BID</h3>
<table style="margin: auto;">
{% for meta in metas %}
<tr>
<td><strong>{{ meta.titulo }}</strong></td>
<td>
<img src="//chart.googleapis.com/chart?chf=c,s,CDCDCD&chbh=a&chs=250x18&cht=bhs&chco={{ meta.saude }}&chd=t:{{ meta.percentual_concluido|stringformat:'d' }}&chm=r,00000034,0,{{ meta.percentual_desejado_low|stringformat:'f' }},{{ meta.percentual_desejado_high|stringformat:'f' }},1"
width="100%" alt="" />
</td>
<td style="text-align: center;"><font color="{{ meta.saude }}">{{ meta.percentual_concluido }}%</font></td>
</tr>
{% endfor %}
</table>
<div class="legend">
<span><div style="background-color: #E74A69;">&nbsp;</div>Ruim</span>
<span><div style="background-color: #FFDB6E;">&nbsp;</div>Preocupante</span>
<span><div style="background-color: #89D7AF;">&nbsp;</div>Bom</span>
<span><div style="background-color: #A2BBED;">&nbsp;</div>Atingido</span>
</div>
</div>
{# ------------- Evolução dos desembolsos ------------- #}
<div style="height: 300px;" class="module">
<h2>Evolução dos desembolsos</h2>
<h3>Desembolsos últimos seis meses</h3>
<img src="//chart.googleapis.com/chart?chxr=0,0,{{ desembolsos_max }}&chxl=1:{% for m in meses %}|{{ m }}{% endfor %}&chxt=y,x&chbh=a&chs=400x240&cht=bvg&chd=t:{% for serie in desembolsos.values %}{% for v in serie.1.values %}{{ v }}{% if not forloop.last %},{% endif %}{% endfor %}{% if not forloop.last %}|{% endif %}{% endfor %}&chdl={% for l in desembolsos.values %}{{ l.0 }}{% if not forloop.last %}|{% endif %}{% endfor %}&chdlp=t&chds={% for d in desembolsos %}0,{{ desembolsos_max }}{% if not forloop.last %},{% endif %}{% endfor %}&chco={{ colors }}" />
</div>
{% comment %}
{# ------------- Evolução dos desembolsos ------------- #}
<div style="height: 300px;" class="module">
<h2>Todas as metas</h2>
<h3>Estado das metas do contrato BID</h3>
</div>
{% endcomment %}

1
sigi/urls.py

@ -117,6 +117,7 @@ urlpatterns = patterns(
(r'^sigi/dashboard/mapsearch/$', 'sigi.apps.metas.views.map_search'), (r'^sigi/dashboard/mapsearch/$', 'sigi.apps.metas.views.map_search'),
(r'^sigi/dashboard/mapsum/$', 'sigi.apps.metas.views.map_sum'), (r'^sigi/dashboard/mapsum/$', 'sigi.apps.metas.views.map_sum'),
(r'^sigi/dashboard/maplist/$', 'sigi.apps.metas.views.map_list'), (r'^sigi/dashboard/maplist/$', 'sigi.apps.metas.views.map_list'),
(r'^sigi/dashboard/$', 'sigi.apps.metas.views.dashboard'),
# automatic interface based on admin # automatic interface based on admin
#(r'^sigi/(.*)', sites.default.root), #(r'^sigi/(.*)', sites.default.root),
(r'^sigi/', include(sites.default.urls)), (r'^sigi/', include(sites.default.urls)),

Loading…
Cancel
Save