{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Plots'offline and notebook's style configs\n", "from IPython.core.display import HTML\n", "from sigi.apps.servicos.models import Servico\n", "from django.db import connection\n", "from django.core.urlresolvers import reverse\n", "from django.db.models import Q, Count\n", "from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot\n", "import plotly \n", "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "import pandas as pd\n", "import cufflinks as cf\n", "import numpy as np\n", "import datetime\n", "import calendar\n", "\n", "init_notebook_mode(connected=True)\n", "css = open('style-table.css').read() + open('style-notebook.css').read()\n", "HTML(''.format(css))" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "''' Function defined on sigi/sigi/sigi/apps/home/views.py line 322 to line 364\n", " All rights reserved.\n", " Obs.: Added number of deactivated types of services per month/year.\n", "'''\n", "def busca_informacoes_seit(mes_atual=None):\n", " if mes_atual is None:\n", " mes_atual = datetime.date.today().replace(day=1)\n", " mes_anterior = mes_atual - datetime.timedelta(days=1)\n", " proximo_mes = mes_atual + datetime.timedelta(days=calendar.monthrange(mes_atual.year, mes_atual.month)[1])\n", " \n", " meses = []\n", " mes = mes_atual\n", " for i in range(1, 13):\n", " meses.append(mes)\n", " mes = (mes - datetime.timedelta(days=1)).replace(day=1)\n", " \n", " result = {\n", " 'mes_atual': mes_atual,\n", " 'mes_anterior': mes_anterior,\n", " 'proximo_mes': proximo_mes,\n", " 'servicos': [],\n", " } \n", "\n", " for tipo_servico in TipoServico.objects.all():\n", " result['servicos'].append(\n", " {'nome': tipo_servico.nome,\n", " 'total_desativados': tipo_servico.servico_set.filter(data_desativacao__year=mes_atual.year, data_desativacao__month=mes_atual.month).count(),\n", " 'total': tipo_servico.servico_set.filter(Q(data_ativacao__lt=proximo_mes)&(Q(data_desativacao=None)|Q(data_desativacao__gt=proximo_mes))).count(),\n", " 'novos_mes_anterior': tipo_servico.servico_set.filter(data_ativacao__year=mes_anterior.year, data_ativacao__month=mes_anterior.month).count(),\n", " 'novos_mes_atual': tipo_servico.servico_set.filter(data_ativacao__year=mes_atual.year, data_ativacao__month=mes_atual.month).count(),\n", " }\n", " )\n", "\n", " return result" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Define periods for data frame's indexes and variables\n", "di = pd.date_range('2008-11', periods=((datetime.date.today().year - datetime.date(2008,11, 30).year) * 12) - (12 - datetime.date.today().month - 2), freq='M')\n", "period = {}\n", "period_formated = []\n", "tabela_resumo_seit = []\n", "services_names = []\n", "services_names = []\n", "period['year'] = di.year\n", "period['month'] = di.month\n", "dataframe_data = []\n", "# Build of the data frame's data as a dictionary\n", "for i in range(0, len(period['year'])):\n", " period_formated.append('{year}/{month}'.format(year = str(period['year'][i]), month = str(period['month'][i])))\n", " try:\n", " mes = datetime.date(year=period['year'][i], month=period['month'][i], day=1)\n", " tabela_resumo_seit.append(busca_informacoes_seit(mes))\n", " except:\n", " tabela_resumo_seit.append(busca_informacoes_seit())" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Dominio.GOV.br(Ativados)Dominio.GOV.br(Ativos)Dominio.GOV.br(Desativados)Dominio.Leg.br(Ativados)Dominio.Leg.br(Ativos)Dominio.Leg.br(Desativados)PortalModelo(Ativados)PortalModelo(Ativos)PortalModelo(Desativados)SAAP(Ativados)SAAP(Ativos)SAAP(Desativados)SAPL(Ativados)SAPL(Ativos)SAPL(Desativados)SPDO(Ativados)SPDO(Ativos)SPDO(Desativados)
2008/11000000110000000000
2008/12000000010000000000
2009/1000000230000000000
2009/2000000250000000000
2009/30000006110000000000
2009/40000004150000000000
2009/50000008230000000000
2009/60000002250000000000
2009/70000006310000000000
2009/800000010410000000000
2009/90000002430000000000
2009/100000001440000000000
2009/110000003470000000000
2009/120000000470000000000
2010/10000001480000000000
2010/20000003510000000000
2010/30000002530000000000
2010/40000001540000000000
2010/50000003570000000000
2010/60000003600000000000
2010/70000001610000000000
2010/80000000610000000000
2010/90000000610000330000
2010/100000001620000360000
2010/1100000046600008140000
2010/1200000047000004180000
2011/100000037300002200000
2011/200000047700003230000
2011/300000038000005280000
2011/400000018100001290000
.........................................................
2014/31140013551084570128053740000
2014/4014001156201146800280123860000
2014/5014004566054730028043900000
2014/6014001567034760028003900000
2014/7014005572044800129003900000
2014/80140010582084880029073970000
2014/901400158301326200029054020000
2014/1001400506330656832130074090000
2014/110140022085306674720300314391000
2014/12014002788002877502320174551000
2015/1014004192103881121330104641000
2015/201400539740618711033084711000
2015/3014003410080479180437094800000
2015/40140037104505496930370215001000
2015/501400531098062102922390405400000
2015/601400361134047107512410415810000
2015/701400171151022109521420155960000
2015/80140010512560114120541430376330000
2015/901400421297133123805480176500000
2015/1001400621358162129913510196690000
2015/110140041139902813270253086770000
2015/120140017141511513393154086850000
2016/10140015143001513531155026870000
2016/20140023145302213741156086950000
2016/30140028148102713983157087030000
2016/401400211501116141221580107121000
2016/501400321533021143301590857970000
2016/601400441576128146010590138100000
2016/701400311607037149700590308400000
2016/801400316100214981059098490000
\n", "

94 rows × 18 columns

\n", "
" ], "text/plain": [ " Dominio.GOV.br(Ativados) Dominio.GOV.br(Ativos) \\\n", "2008/11 0 0 \n", "2008/12 0 0 \n", "2009/1 0 0 \n", "2009/2 0 0 \n", "2009/3 0 0 \n", "2009/4 0 0 \n", "2009/5 0 0 \n", "2009/6 0 0 \n", "2009/7 0 0 \n", "2009/8 0 0 \n", "2009/9 0 0 \n", "2009/10 0 0 \n", "2009/11 0 0 \n", "2009/12 0 0 \n", "2010/1 0 0 \n", "2010/2 0 0 \n", "2010/3 0 0 \n", "2010/4 0 0 \n", "2010/5 0 0 \n", "2010/6 0 0 \n", "2010/7 0 0 \n", "2010/8 0 0 \n", "2010/9 0 0 \n", "2010/10 0 0 \n", "2010/11 0 0 \n", "2010/12 0 0 \n", "2011/1 0 0 \n", "2011/2 0 0 \n", "2011/3 0 0 \n", "2011/4 0 0 \n", "... ... ... \n", "2014/3 1 140 \n", "2014/4 0 140 \n", "2014/5 0 140 \n", "2014/6 0 140 \n", "2014/7 0 140 \n", "2014/8 0 140 \n", "2014/9 0 140 \n", "2014/10 0 140 \n", "2014/11 0 140 \n", "2014/12 0 140 \n", "2015/1 0 140 \n", "2015/2 0 140 \n", "2015/3 0 140 \n", "2015/4 0 140 \n", "2015/5 0 140 \n", "2015/6 0 140 \n", "2015/7 0 140 \n", "2015/8 0 140 \n", "2015/9 0 140 \n", "2015/10 0 140 \n", "2015/11 0 140 \n", "2015/12 0 140 \n", "2016/1 0 140 \n", "2016/2 0 140 \n", "2016/3 0 140 \n", "2016/4 0 140 \n", "2016/5 0 140 \n", "2016/6 0 140 \n", "2016/7 0 140 \n", "2016/8 0 140 \n", "\n", " Dominio.GOV.br(Desativados) Dominio.Leg.br(Ativados) \\\n", "2008/11 0 0 \n", "2008/12 0 0 \n", "2009/1 0 0 \n", "2009/2 0 0 \n", "2009/3 0 0 \n", "2009/4 0 0 \n", "2009/5 0 0 \n", "2009/6 0 0 \n", "2009/7 0 0 \n", "2009/8 0 0 \n", "2009/9 0 0 \n", "2009/10 0 0 \n", "2009/11 0 0 \n", "2009/12 0 0 \n", "2010/1 0 0 \n", "2010/2 0 0 \n", "2010/3 0 0 \n", "2010/4 0 0 \n", "2010/5 0 0 \n", "2010/6 0 0 \n", "2010/7 0 0 \n", "2010/8 0 0 \n", "2010/9 0 0 \n", "2010/10 0 0 \n", "2010/11 0 0 \n", "2010/12 0 0 \n", "2011/1 0 0 \n", "2011/2 0 0 \n", "2011/3 0 0 \n", "2011/4 0 0 \n", "... ... ... \n", "2014/3 0 13 \n", "2014/4 0 11 \n", "2014/5 0 4 \n", "2014/6 0 1 \n", "2014/7 0 5 \n", "2014/8 0 10 \n", "2014/9 0 1 \n", "2014/10 0 50 \n", "2014/11 0 220 \n", "2014/12 0 27 \n", "2015/1 0 41 \n", "2015/2 0 53 \n", "2015/3 0 34 \n", "2015/4 0 37 \n", "2015/5 0 53 \n", "2015/6 0 36 \n", "2015/7 0 17 \n", "2015/8 0 105 \n", "2015/9 0 42 \n", "2015/10 0 62 \n", "2015/11 0 41 \n", "2015/12 0 17 \n", "2016/1 0 15 \n", "2016/2 0 23 \n", "2016/3 0 28 \n", "2016/4 0 21 \n", "2016/5 0 32 \n", "2016/6 0 44 \n", "2016/7 0 31 \n", "2016/8 0 3 \n", "\n", " Dominio.Leg.br(Ativos) Dominio.Leg.br(Desativados) \\\n", "2008/11 0 0 \n", "2008/12 0 0 \n", "2009/1 0 0 \n", "2009/2 0 0 \n", "2009/3 0 0 \n", "2009/4 0 0 \n", "2009/5 0 0 \n", "2009/6 0 0 \n", "2009/7 0 0 \n", "2009/8 0 0 \n", "2009/9 0 0 \n", "2009/10 0 0 \n", "2009/11 0 0 \n", "2009/12 0 0 \n", "2010/1 0 0 \n", "2010/2 0 0 \n", "2010/3 0 0 \n", "2010/4 0 0 \n", "2010/5 0 0 \n", "2010/6 0 0 \n", "2010/7 0 0 \n", "2010/8 0 0 \n", "2010/9 0 0 \n", "2010/10 0 0 \n", "2010/11 0 0 \n", "2010/12 0 0 \n", "2011/1 0 0 \n", "2011/2 0 0 \n", "2011/3 0 0 \n", "2011/4 0 0 \n", "... ... ... \n", "2014/3 551 0 \n", "2014/4 562 0 \n", "2014/5 566 0 \n", "2014/6 567 0 \n", "2014/7 572 0 \n", "2014/8 582 0 \n", "2014/9 583 0 \n", "2014/10 633 0 \n", "2014/11 853 0 \n", "2014/12 880 0 \n", "2015/1 921 0 \n", "2015/2 974 0 \n", "2015/3 1008 0 \n", "2015/4 1045 0 \n", "2015/5 1098 0 \n", "2015/6 1134 0 \n", "2015/7 1151 0 \n", "2015/8 1256 0 \n", "2015/9 1297 1 \n", "2015/10 1358 1 \n", "2015/11 1399 0 \n", "2015/12 1415 1 \n", "2016/1 1430 0 \n", "2016/2 1453 0 \n", "2016/3 1481 0 \n", "2016/4 1501 1 \n", "2016/5 1533 0 \n", "2016/6 1576 1 \n", "2016/7 1607 0 \n", "2016/8 1610 0 \n", "\n", " PortalModelo(Ativados) PortalModelo(Ativos) \\\n", "2008/11 1 1 \n", "2008/12 0 1 \n", "2009/1 2 3 \n", "2009/2 2 5 \n", "2009/3 6 11 \n", "2009/4 4 15 \n", "2009/5 8 23 \n", "2009/6 2 25 \n", "2009/7 6 31 \n", "2009/8 10 41 \n", "2009/9 2 43 \n", "2009/10 1 44 \n", "2009/11 3 47 \n", "2009/12 0 47 \n", "2010/1 1 48 \n", "2010/2 3 51 \n", "2010/3 2 53 \n", "2010/4 1 54 \n", "2010/5 3 57 \n", "2010/6 3 60 \n", "2010/7 1 61 \n", "2010/8 0 61 \n", "2010/9 0 61 \n", "2010/10 1 62 \n", "2010/11 4 66 \n", "2010/12 4 70 \n", "2011/1 3 73 \n", "2011/2 4 77 \n", "2011/3 3 80 \n", "2011/4 1 81 \n", "... ... ... \n", "2014/3 8 457 \n", "2014/4 11 468 \n", "2014/5 5 473 \n", "2014/6 3 476 \n", "2014/7 4 480 \n", "2014/8 8 488 \n", "2014/9 132 620 \n", "2014/10 65 683 \n", "2014/11 66 747 \n", "2014/12 28 775 \n", "2015/1 38 811 \n", "2015/2 61 871 \n", "2015/3 47 918 \n", "2015/4 54 969 \n", "2015/5 62 1029 \n", "2015/6 47 1075 \n", "2015/7 22 1095 \n", "2015/8 114 1205 \n", "2015/9 33 1238 \n", "2015/10 62 1299 \n", "2015/11 28 1327 \n", "2015/12 15 1339 \n", "2016/1 15 1353 \n", "2016/2 22 1374 \n", "2016/3 27 1398 \n", "2016/4 16 1412 \n", "2016/5 21 1433 \n", "2016/6 28 1460 \n", "2016/7 37 1497 \n", "2016/8 2 1498 \n", "\n", " PortalModelo(Desativados) SAAP(Ativados) SAAP(Ativos) \\\n", "2008/11 0 0 0 \n", "2008/12 0 0 0 \n", "2009/1 0 0 0 \n", "2009/2 0 0 0 \n", "2009/3 0 0 0 \n", "2009/4 0 0 0 \n", "2009/5 0 0 0 \n", "2009/6 0 0 0 \n", "2009/7 0 0 0 \n", "2009/8 0 0 0 \n", "2009/9 0 0 0 \n", "2009/10 0 0 0 \n", "2009/11 0 0 0 \n", "2009/12 0 0 0 \n", "2010/1 0 0 0 \n", "2010/2 0 0 0 \n", "2010/3 0 0 0 \n", "2010/4 0 0 0 \n", "2010/5 0 0 0 \n", "2010/6 0 0 0 \n", "2010/7 0 0 0 \n", "2010/8 0 0 0 \n", "2010/9 0 0 0 \n", "2010/10 0 0 0 \n", "2010/11 0 0 0 \n", "2010/12 0 0 0 \n", "2011/1 0 0 0 \n", "2011/2 0 0 0 \n", "2011/3 0 0 0 \n", "2011/4 0 0 0 \n", "... ... ... ... \n", "2014/3 0 1 28 \n", "2014/4 0 0 28 \n", "2014/5 0 0 28 \n", "2014/6 0 0 28 \n", "2014/7 0 1 29 \n", "2014/8 0 0 29 \n", "2014/9 0 0 29 \n", "2014/10 2 1 30 \n", "2014/11 2 0 30 \n", "2014/12 0 2 32 \n", "2015/1 2 1 33 \n", "2015/2 1 0 33 \n", "2015/3 0 4 37 \n", "2015/4 3 0 37 \n", "2015/5 2 2 39 \n", "2015/6 1 2 41 \n", "2015/7 2 1 42 \n", "2015/8 4 1 43 \n", "2015/9 0 5 48 \n", "2015/10 1 3 51 \n", "2015/11 0 2 53 \n", "2015/12 3 1 54 \n", "2016/1 1 1 55 \n", "2016/2 1 1 56 \n", "2016/3 3 1 57 \n", "2016/4 2 1 58 \n", "2016/5 0 1 59 \n", "2016/6 1 0 59 \n", "2016/7 0 0 59 \n", "2016/8 1 0 59 \n", "\n", " SAAP(Desativados) SAPL(Ativados) SAPL(Ativos) SAPL(Desativados) \\\n", "2008/11 0 0 0 0 \n", "2008/12 0 0 0 0 \n", "2009/1 0 0 0 0 \n", "2009/2 0 0 0 0 \n", "2009/3 0 0 0 0 \n", "2009/4 0 0 0 0 \n", "2009/5 0 0 0 0 \n", "2009/6 0 0 0 0 \n", "2009/7 0 0 0 0 \n", "2009/8 0 0 0 0 \n", "2009/9 0 0 0 0 \n", "2009/10 0 0 0 0 \n", "2009/11 0 0 0 0 \n", "2009/12 0 0 0 0 \n", "2010/1 0 0 0 0 \n", "2010/2 0 0 0 0 \n", "2010/3 0 0 0 0 \n", "2010/4 0 0 0 0 \n", "2010/5 0 0 0 0 \n", "2010/6 0 0 0 0 \n", "2010/7 0 0 0 0 \n", "2010/8 0 0 0 0 \n", "2010/9 0 3 3 0 \n", "2010/10 0 3 6 0 \n", "2010/11 0 8 14 0 \n", "2010/12 0 4 18 0 \n", "2011/1 0 2 20 0 \n", "2011/2 0 3 23 0 \n", "2011/3 0 5 28 0 \n", "2011/4 0 1 29 0 \n", "... ... ... ... ... \n", "2014/3 0 5 374 0 \n", "2014/4 0 12 386 0 \n", "2014/5 0 4 390 0 \n", "2014/6 0 0 390 0 \n", "2014/7 0 0 390 0 \n", "2014/8 0 7 397 0 \n", "2014/9 0 5 402 0 \n", "2014/10 0 7 409 0 \n", "2014/11 0 31 439 1 \n", "2014/12 0 17 455 1 \n", "2015/1 0 10 464 1 \n", "2015/2 0 8 471 1 \n", "2015/3 0 9 480 0 \n", "2015/4 0 21 500 1 \n", "2015/5 0 40 540 0 \n", "2015/6 0 41 581 0 \n", "2015/7 0 15 596 0 \n", "2015/8 0 37 633 0 \n", "2015/9 0 17 650 0 \n", "2015/10 0 19 669 0 \n", "2015/11 0 8 677 0 \n", "2015/12 0 8 685 0 \n", "2016/1 0 2 687 0 \n", "2016/2 0 8 695 0 \n", "2016/3 0 8 703 0 \n", "2016/4 0 10 712 1 \n", "2016/5 0 85 797 0 \n", "2016/6 0 13 810 0 \n", "2016/7 0 30 840 0 \n", "2016/8 0 9 849 0 \n", "\n", " SPDO(Ativados) SPDO(Ativos) SPDO(Desativados) \n", "2008/11 0 0 0 \n", "2008/12 0 0 0 \n", "2009/1 0 0 0 \n", "2009/2 0 0 0 \n", "2009/3 0 0 0 \n", "2009/4 0 0 0 \n", "2009/5 0 0 0 \n", "2009/6 0 0 0 \n", "2009/7 0 0 0 \n", "2009/8 0 0 0 \n", "2009/9 0 0 0 \n", "2009/10 0 0 0 \n", "2009/11 0 0 0 \n", "2009/12 0 0 0 \n", "2010/1 0 0 0 \n", "2010/2 0 0 0 \n", "2010/3 0 0 0 \n", "2010/4 0 0 0 \n", "2010/5 0 0 0 \n", "2010/6 0 0 0 \n", "2010/7 0 0 0 \n", "2010/8 0 0 0 \n", "2010/9 0 0 0 \n", "2010/10 0 0 0 \n", "2010/11 0 0 0 \n", "2010/12 0 0 0 \n", "2011/1 0 0 0 \n", "2011/2 0 0 0 \n", "2011/3 0 0 0 \n", "2011/4 0 0 0 \n", "... ... ... ... \n", "2014/3 0 0 0 \n", "2014/4 0 0 0 \n", "2014/5 0 0 0 \n", "2014/6 0 0 0 \n", "2014/7 0 0 0 \n", "2014/8 0 0 0 \n", "2014/9 0 0 0 \n", "2014/10 0 0 0 \n", "2014/11 0 0 0 \n", "2014/12 0 0 0 \n", "2015/1 0 0 0 \n", "2015/2 0 0 0 \n", "2015/3 0 0 0 \n", "2015/4 0 0 0 \n", "2015/5 0 0 0 \n", "2015/6 0 0 0 \n", "2015/7 0 0 0 \n", "2015/8 0 0 0 \n", "2015/9 0 0 0 \n", "2015/10 0 0 0 \n", "2015/11 0 0 0 \n", "2015/12 0 0 0 \n", "2016/1 0 0 0 \n", "2016/2 0 0 0 \n", "2016/3 0 0 0 \n", "2016/4 0 0 0 \n", "2016/5 0 0 0 \n", "2016/6 0 0 0 \n", "2016/7 0 0 0 \n", "2016/8 0 0 0 \n", "\n", "[94 rows x 18 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Build list of desired values into tabela_resumo_seit\n", "ativados_temp = []\n", "ativados = []\n", "desativados_temp = []\n", "desativados = []\n", "ativos_temp = []\n", "ativos = []\n", "\n", "for i in range(0, len(period['year'])):\n", " for j in range (0,6):\n", " ativados_temp.append(tabela_resumo_seit[i]['servicos'][j]['novos_mes_atual'])\n", " desativados_temp.append(tabela_resumo_seit[i]['servicos'][j]['total_desativados'])\n", " ativos_temp.append(tabela_resumo_seit[i]['servicos'][j]['total'])\n", "\n", "# Create an iterator\n", "it = [iter(ativados_temp)] * 6 \n", "# Unpack the copies of the iterator, and pass them as parameters to zip\n", "ativados = zip(*it)\n", "# Create an iterator\n", "it2 = [iter(desativados_temp)] * 6 \n", "# Unpack the copies of the iterator, and pass them as parameters to zip\n", "desativados = zip(*it2)\n", "# Create an iterator\n", "it3 = [iter(ativos_temp)] * 6 \n", "# Unpack the copies of the iterator, and pass them as parameters to zip\n", "ativos = zip(*it3)\n", " \n", "# Creation of the data frame\n", "df_final = pd.DataFrame(ativados, index=period_formated, columns=['PortalModelo(Ativados)', 'SAPL(Ativados)', 'SAAP(Ativados)', 'SPDO(Ativados)', 'Dominio.Leg.br(Ativados)', 'Dominio.GOV.br(Ativados)'])\n", "df_desativados = pd.DataFrame(desativados, index=period_formated, columns=['PortalModelo(Desativados)', 'SAPL(Desativados)', 'SAAP(Desativados)', 'SPDO(Desativados)', 'Dominio.Leg.br(Desativados)', 'Dominio.GOV.br(Desativados)'])\n", "df_ativos = pd.DataFrame(ativos, index=period_formated, columns=['PortalModelo(Ativos)', 'SAPL(Ativos)', 'SAAP(Ativos)', 'SPDO(Ativos)', 'Dominio.Leg.br(Ativos)', 'Dominio.GOV.br(Ativos)'])\n", "\n", "df_final['PortalModelo(Desativados)'] = df_desativados['PortalModelo(Desativados)']\n", "df_final['SAPL(Desativados)'] = df_desativados['SAPL(Desativados)']\n", "df_final['SAAP(Desativados)'] = df_desativados['SAAP(Desativados)']\n", "df_final['SPDO(Desativados)'] = df_desativados['SPDO(Desativados)']\n", "df_final['Dominio.Leg.br(Desativados)'] = df_desativados['Dominio.Leg.br(Desativados)']\n", "df_final['Dominio.GOV.br(Desativados)'] = df_desativados['Dominio.GOV.br(Desativados)']\n", "\n", "df_final['PortalModelo(Ativos)'] = df_ativos['PortalModelo(Ativos)']\n", "df_final['SAPL(Ativos)'] = df_ativos['SAPL(Ativos)']\n", "df_final['SAAP(Ativos)'] = df_ativos['SAAP(Ativos)']\n", "df_final['SPDO(Ativos)'] = df_ativos['SPDO(Ativos)']\n", "df_final['Dominio.Leg.br(Ativos)'] = df_ativos['Dominio.Leg.br(Ativos)']\n", "df_final['Dominio.GOV.br(Ativos)'] = df_ativos['Dominio.GOV.br(Ativos)']\n", "\n", "cols = df_final.columns.tolist()\n", "\n", "cols.sort()\n", "\n", "df_final = df_final[cols]\n", "\n", "df_final\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TotalTipoServico
Dominio.GOV.br(Ativados)160Dominio.GOV.br(Ativados)
Dominio.GOV.br(Ativos)5957Dominio.GOV.br(Ativos)
Dominio.GOV.br(Desativados)20Dominio.GOV.br(Desativados)
Dominio.Leg.br(Ativados)1615Dominio.Leg.br(Ativados)
Dominio.Leg.br(Ativos)38918Dominio.Leg.br(Ativos)
Dominio.Leg.br(Desativados)5Dominio.Leg.br(Desativados)
PortalModelo(Ativados)1547PortalModelo(Ativados)
PortalModelo(Ativos)41070PortalModelo(Ativos)
PortalModelo(Desativados)49PortalModelo(Desativados)
SAAP(Ativados)59SAAP(Ativados)
SAAP(Ativos)1486SAAP(Ativos)
SAAP(Desativados)0SAAP(Desativados)
SAPL(Ativados)855SAPL(Ativados)
SAPL(Ativos)24105SAPL(Ativos)
SAPL(Desativados)6SAPL(Desativados)
SPDO(Ativados)0SPDO(Ativados)
SPDO(Ativos)0SPDO(Ativos)
SPDO(Desativados)0SPDO(Desativados)
\n", "
" ], "text/plain": [ " Total TipoServico\n", "Dominio.GOV.br(Ativados) 160 Dominio.GOV.br(Ativados)\n", "Dominio.GOV.br(Ativos) 5957 Dominio.GOV.br(Ativos)\n", "Dominio.GOV.br(Desativados) 20 Dominio.GOV.br(Desativados)\n", "Dominio.Leg.br(Ativados) 1615 Dominio.Leg.br(Ativados)\n", "Dominio.Leg.br(Ativos) 38918 Dominio.Leg.br(Ativos)\n", "Dominio.Leg.br(Desativados) 5 Dominio.Leg.br(Desativados)\n", "PortalModelo(Ativados) 1547 PortalModelo(Ativados)\n", "PortalModelo(Ativos) 41070 PortalModelo(Ativos)\n", "PortalModelo(Desativados) 49 PortalModelo(Desativados)\n", "SAAP(Ativados) 59 SAAP(Ativados)\n", "SAAP(Ativos) 1486 SAAP(Ativos)\n", "SAAP(Desativados) 0 SAAP(Desativados)\n", "SAPL(Ativados) 855 SAPL(Ativados)\n", "SAPL(Ativos) 24105 SAPL(Ativos)\n", "SAPL(Desativados) 6 SAPL(Desativados)\n", "SPDO(Ativados) 0 SPDO(Ativados)\n", "SPDO(Ativos) 0 SPDO(Ativos)\n", "SPDO(Desativados) 0 SPDO(Desativados)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_stats = pd.DataFrame(df_final.loc[:,:].sum(numeric_only=True), columns=['Total'])\n", "df_stats['TipoServico'] = df_final.columns[:]\n", "\n", "df_stats" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Obs.: Layout dos plots sao normalmente configurados como\n", "# dicionarios e encapsulados pela func. abaixo\n", "layout = go.Layout(\n", " title='Detalhamento do Programa Interlegis',\n", " xaxis=dict(\n", " title='Periodo',\n", " titlefont=dict(\n", " family='Courier New, monospace',\n", " size=18,\n", " color='#7f7f7f'\n", " )\n", " ),\n", " yaxis=dict(\n", " title='Quantidade',\n", " titlefont=dict(\n", " family='Courier New, monospace',\n", " size=18,\n", " color='#7f7f7f'\n", " )\n", " )\n", ")\n", "\n", "py.iplot(dict(data = [{\n", " 'x': df_final.index,\n", " 'y': df_final[col],\n", " 'name': col\n", "} for col in df_final.columns[:]], layout = layout), kind='scatter', asFigure=True)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Kind = tipo de plot; labels = nome dos valores; values = os valores a serem colocados no plot;\n", "df_stats.iplot(kind='pie', labels='TipoServico', values='Total', pull=.1, hole=.1,\n", " colorscale='blues', textposition='outside', textinfo='value+percent', title='Detalhamento do Programa Interlegis')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Obs.: Usar sudo pip install XlsxWriter no seu Virtualenv\n", "writer = pd.ExcelWriter('output.xlsx', engine='xlsxwriter')\n", "df_final.loc[:,:].to_excel(writer,'Sheet1')\n", "df_stats.to_excel(writer,'Sheet2')\n", "writer.save()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Django Shell-Plus", "language": "python", "name": "django_extensions" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 1 }