|
@ -1,12 +1,13 @@ |
|
|
# -*- coding: utf8 -*- |
|
|
# -*- coding: utf8 -*- |
|
|
|
|
|
|
|
|
import new |
|
|
import json |
|
|
from django.http import HttpResponse, QueryDict |
|
|
from itertools import cycle |
|
|
|
|
|
|
|
|
|
|
|
from django.http import HttpResponse |
|
|
from django.utils import simplejson |
|
|
from django.utils import simplejson |
|
|
from django.shortcuts import render_to_response, get_object_or_404, redirect |
|
|
from django.shortcuts import render_to_response, get_object_or_404 |
|
|
from django.template import RequestContext |
|
|
from django.template import RequestContext |
|
|
from django.views.decorators.cache import never_cache |
|
|
from django.views.decorators.cache import never_cache |
|
|
from geraldo.generators import PDFGenerator |
|
|
|
|
|
|
|
|
|
|
|
from sigi.apps.diagnosticos.urls import LOGIN_REDIRECT_URL |
|
|
from sigi.apps.diagnosticos.urls import LOGIN_REDIRECT_URL |
|
|
from sigi.apps.utils.decorators import login_required |
|
|
from sigi.apps.utils.decorators import login_required |
|
@ -223,6 +224,7 @@ def categoria_contatos(request, id_diagnostico): |
|
|
return render_to_response('diagnosticos/diagnosticos_categoria_contatos_form.html', |
|
|
return render_to_response('diagnosticos/diagnosticos_categoria_contatos_form.html', |
|
|
context) |
|
|
context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def diagnostico_pdf(request, id_diagnostico): |
|
|
def diagnostico_pdf(request, id_diagnostico): |
|
|
diagnostico = Diagnostico.objects.get(pk=id_diagnostico) |
|
|
diagnostico = Diagnostico.objects.get(pk=id_diagnostico) |
|
|
categorias = Categoria.objects.all() |
|
|
categorias = Categoria.objects.all() |
|
@ -263,6 +265,7 @@ def diagnostico_pdf(request, id_diagnostico): |
|
|
return render_to_pdf('diagnosticos/diagnostico_pdf.html', context) |
|
|
return render_to_pdf('diagnosticos/diagnostico_pdf.html', context) |
|
|
#return render_to_response('diagnosticos/diagnostico_pdf.html', context) |
|
|
#return render_to_response('diagnosticos/diagnostico_pdf.html', context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def graficos(request): |
|
|
def graficos(request): |
|
|
categorias = Categoria.objects.all() |
|
|
categorias = Categoria.objects.all() |
|
|
|
|
|
|
|
@ -277,67 +280,57 @@ def graficos(request): |
|
|
return render_to_response('diagnosticos/graficos.html', |
|
|
return render_to_response('diagnosticos/graficos.html', |
|
|
context) |
|
|
context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def percentage(fraction, population): |
|
|
def percentage(fraction, population): |
|
|
try: |
|
|
try: |
|
|
return "%.0f%%" % ((float(fraction) / float(population)) * 100) |
|
|
return "%.0f%%" % ((float(fraction) / float(population)) * 100) |
|
|
except ValueError: |
|
|
except ValueError: |
|
|
return '' |
|
|
return '' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def grafico_api(request): |
|
|
def grafico_api(request): |
|
|
colors = ['ffff00', 'cc7900', 'ff0000', '92d050', '006600', '0097cc', '002776', 'ae78d6', 'ff00ff', '430080', |
|
|
|
|
|
'28d75c', '0000ff', 'fff200'] |
|
|
|
|
|
graph_url = "http://chart.apis.google.com/chart" |
|
|
|
|
|
#graph_params = QueryDict("chxt=y&chbh=a&chco=A2C180,3D7930") |
|
|
|
|
|
graph_params = QueryDict("") |
|
|
|
|
|
graph_params = graph_params.copy() # to make it mutable |
|
|
|
|
|
|
|
|
|
|
|
width = request.REQUEST.get('width', '800') |
|
|
colors = cycle(['#7cb5ec', |
|
|
height = request.REQUEST.get('height', '300') |
|
|
'#434348', |
|
|
graph_params.update({'chs': width + 'x' + height}) |
|
|
'#90ed7d', |
|
|
|
|
|
'#f7a35c', |
|
|
|
|
|
'#8085e9', |
|
|
|
|
|
'#f15c80', |
|
|
|
|
|
'#e4d354', |
|
|
|
|
|
'#8085e8', |
|
|
|
|
|
'#8d4653', |
|
|
|
|
|
'#91e8e1', ]) |
|
|
|
|
|
|
|
|
|
|
|
highlights = cycle(['#B0D3F4', |
|
|
|
|
|
'#8E8E91', |
|
|
|
|
|
'#BCF4B1', |
|
|
|
|
|
'#FAC89D', |
|
|
|
|
|
'#B3B6F2', |
|
|
|
|
|
'#F79DB3', |
|
|
|
|
|
'#EFE598', |
|
|
|
|
|
'#B3B6F1', |
|
|
|
|
|
'#BB9098', |
|
|
|
|
|
'#BDF1ED', ]) |
|
|
|
|
|
|
|
|
pergunta_slug = request.REQUEST.get('id', None) |
|
|
pergunta_slug = request.REQUEST.get('id', None) |
|
|
pergunta = get_object_or_404(Pergunta, name=pergunta_slug) |
|
|
pergunta = get_object_or_404(Pergunta, name=pergunta_slug) |
|
|
|
|
|
|
|
|
if pergunta.datatype == 'one': |
|
|
if pergunta.datatype == 'one': |
|
|
total = sum([r[1] for r in pergunta.group_choices()]) |
|
|
|
|
|
choices = [str(r[1]) for r in pergunta.group_choices()] |
|
|
|
|
|
legend = [percentage(r[1],total) + " " + str(r[0]) for r in pergunta.group_choices()] |
|
|
|
|
|
colors = ['ff0000', 'fff200', '0000ff', '28d75c'] + ["%0.6x" % (0x48d1 + (0xda74 * c)) |
|
|
|
|
|
for c in range(0,len(pergunta.group_choices()))] |
|
|
|
|
|
graph_params.update({ |
|
|
|
|
|
'cht': 'p', |
|
|
|
|
|
'chd': 't:' + ",".join(choices), |
|
|
|
|
|
'chdl': '' + "|".join(legend), |
|
|
|
|
|
'chco': '' + '|'.join(colors[:len(pergunta.group_choices())]) |
|
|
|
|
|
}) |
|
|
|
|
|
elif pergunta.datatype == 'many': |
|
|
|
|
|
total = sum([r[1] for r in pergunta.group_choices()]) |
|
|
|
|
|
percent = [str(float(r[1])*100/total) for r in pergunta.group_choices()] |
|
|
|
|
|
choices = [str(r[1]) for r in pergunta.group_choices()] |
|
|
|
|
|
legend = [str(r[0]) for r in pergunta.group_choices()] |
|
|
|
|
|
colors = ['ffff00', 'cc7900', 'ff0000', '92d050', '006600', '0097cc', '002776', 'ae78d6', 'ff00ff', '430080'] + \ |
|
|
|
|
|
["%0.6x" % (0x48d1 + (0xda74 * c)) for c in range(0,len(pergunta.group_choices()))] |
|
|
|
|
|
graph_params.update({ |
|
|
|
|
|
'cht': 'bvg', |
|
|
|
|
|
'chxt': 'y', |
|
|
|
|
|
'chd': 't:' + ",".join(percent), |
|
|
|
|
|
'chdl': '' + "|".join(legend), |
|
|
|
|
|
'chl': '' + "|".join(choices), |
|
|
|
|
|
'chco': '' + '|'.join(colors[:len(pergunta.group_choices())]) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
response = { |
|
|
list_perguntas = pergunta.group_choices() |
|
|
"type": "photo", |
|
|
list_perguntas = [{'label': k.title, |
|
|
"width": width, |
|
|
'value': v, |
|
|
"height": height, |
|
|
'color': colors.next(), |
|
|
"title": pergunta.title, |
|
|
'highlight': highlights.next()} |
|
|
"url": graph_url + "?" + graph_params.urlencode(), |
|
|
for k, v in list_perguntas] |
|
|
"provider_name": "SIGI", |
|
|
|
|
|
"provider_url": "https://intranet.interlegis.gov.br/sigi/" |
|
|
# list_perguntas = [[k.title, v, colors.next(), highlights.next()] for k, v in list_perguntas] |
|
|
} |
|
|
|
|
|
|
|
|
# elif pergunta.datatype == 'many': |
|
|
|
|
|
|
|
|
|
|
|
jsonn = json.dumps(list_perguntas, sort_keys=True, indent=4, separators=(',', ': ')) |
|
|
|
|
|
return HttpResponse(jsonn, content_type="application/json") |
|
|
|
|
|
|
|
|
json = simplejson.dumps(response) |
|
|
|
|
|
return HttpResponse(json, mimetype="application/json") |
|
|
|
|
|
|
|
|
|
|
|
def municipios_diagnosticados(self): |
|
|
def municipios_diagnosticados(self): |
|
|
municipios = [] |
|
|
municipios = [] |
|
|