From 562f25937c02b0563e033d9a6363bff0d7574688 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Thu, 14 May 2015 16:23:29 -0300 Subject: [PATCH] Add ad-hoc script to list services by year --- scripts/servicos_seit_ate_2013_2014.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/servicos_seit_ate_2013_2014.py diff --git a/scripts/servicos_seit_ate_2013_2014.py b/scripts/servicos_seit_ate_2013_2014.py new file mode 100644 index 0000000..24b4f7f --- /dev/null +++ b/scripts/servicos_seit_ate_2013_2014.py @@ -0,0 +1,22 @@ +from datetime import date +from django.db.models import Q + +from sigi.apps.servicos.models import TipoServico + +anos = range(2006, 2016) + +print '\t'.join(map(str, ['tipo'] + anos)) + + +def prim_jan_ano_seguinte(ano): + return date(ano + 1, 1, 1) + + +for tipo_servico in TipoServico.objects.all(): + print '\t'.join(map(str, + [tipo_servico] + + [tipo_servico.servico_set.filter( + Q(data_ativacao__lt=prim_jan_ano_seguinte(ano)), + Q(data_desativacao=None) | Q(data_desativacao__gte=prim_jan_ano_seguinte(ano)) + ).count() for ano in anos] + ))