diff --git a/sigi/apps/home/templates/home/dashboard/ufs_snippet.html b/sigi/apps/home/templates/home/dashboard/ufs_snippet.html
index 96c44f9..759d303 100644
--- a/sigi/apps/home/templates/home/dashboard/ufs_snippet.html
+++ b/sigi/apps/home/templates/home/dashboard/ufs_snippet.html
@@ -12,7 +12,7 @@
-
-
+
{% trans "Todo o país" %}
diff --git a/sigi/apps/home/urls.py b/sigi/apps/home/urls.py
index e8b8ad1..7596969 100644
--- a/sigi/apps/home/urls.py
+++ b/sigi/apps/home/urls.py
@@ -11,10 +11,15 @@ urlpatterns = [
path("home/resumoseit/", views.resumo_seit, name="home_resumoseit"),
path("home/chartseit/", views.chart_seit, name="home_chartseit"),
path(
- "home/cartusoservico/",
+ "home/chartusoservico/",
views.chart_uso_servico,
name="home_chartusoservico",
),
+ path(
+ "home/chartatualizacao/",
+ views.chart_atualizacao_servicos,
+ name="home_chartatualizacao",
+ ),
path(
"home/chartperformance/",
views.chart_performance,
diff --git a/sigi/apps/home/views.py b/sigi/apps/home/views.py
index edcd724..2747eae 100644
--- a/sigi/apps/home/views.py
+++ b/sigi/apps/home/views.py
@@ -409,7 +409,7 @@ def chart_seit(request):
@never_cache
@login_required
def chart_uso_servico(request):
- colors, highlights = color_palete()
+ colors, *__ = color_palete()
ufs = UnidadeFederativa.objects.all()
sigla_uf = request.GET.get("uf", "_all")
@@ -457,6 +457,61 @@ def chart_uso_servico(request):
return JsonResponse(chart)
+@never_cache
+@login_required
+def chart_atualizacao_servicos(request):
+ colors, *__ = color_palete()
+ intervalos = [
+ ("Na semana", 7),
+ ("No mês", 30),
+ ("No trimestre", 3 * 30),
+ ("No semestre", 6 * 30),
+ ("No ano", 365),
+ ("Mais de ano", None),
+ ]
+
+ counts = {}
+ hoje = timezone.localdate()
+ ate = hoje
+
+ for label, dias in intervalos:
+ if dias is not None:
+ de = hoje - datetime.timedelta(days=dias)
+ counts[slugify(label)] = Count(
+ "servico", Q(servico__data_ultimo_uso__range=(de, ate))
+ )
+ ate = de - datetime.timedelta(days=1)
+ else:
+ counts[slugify(label)] = Count(
+ "servico", Q(servico__data_ultimo_uso__lte=ate)
+ )
+
+ queryset = (
+ TipoServico.objects.exclude(string_pesquisa="")
+ .filter(servico__data_desativacao=None)
+ .annotate(**counts)
+ )
+
+ chart = {
+ "data": {
+ "datasets": [
+ {
+ "type": "bar",
+ "label": ts.sigla,
+ "data": [
+ getattr(ts, slugify(label)) for label, *__ in intervalos
+ ],
+ "backgroundColor": next(colors),
+ }
+ for ts in queryset
+ ],
+ "labels": [label for label, *__ in intervalos],
+ }
+ }
+
+ return JsonResponse(chart)
+
+
# @never_cache
# @login_required
# def chart_convenios(request):
diff --git a/sigi/apps/servicos/filters.py b/sigi/apps/servicos/filters.py
index dee8f2c..af22ac1 100644
--- a/sigi/apps/servicos/filters.py
+++ b/sigi/apps/servicos/filters.py
@@ -77,7 +77,7 @@ class DataUtimoUsoFilter(admin.SimpleListFilter):
if self.value() == "err":
queryset = queryset.exclude(erro_atualizacao="")
elif self.value() == "year":
- limite = date.today() - timedelta(days=365)
+ limite = date.today() - timedelta(days=366)
queryset = queryset.filter(data_ultimo_uso__lte=limite)
else:
de = date.today() - (
@@ -89,14 +89,14 @@ class DataUtimoUsoFilter(admin.SimpleListFilter):
if self.value() == "month"
else timedelta(days=30)
if self.value() == "week"
- else timedelta(days=0)
+ else timedelta(days=6)
)
ate = date.today() - (
- timedelta(days=6 * 30)
+ timedelta(days=6 * 30 + 1)
if self.value() == "semester"
- else timedelta(days=3 * 30)
+ else timedelta(days=3 * 30 + 1)
if self.value() == "quarter"
- else timedelta(days=30)
+ else timedelta(days=31)
if self.value() == "month"
else timedelta(days=7)
if self.value() == "week"