Browse Source

Chart frequência de atualização dos produtos

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
1f477b7001
  1. 2
      sigi/apps/home/templates/home/dashboard/ufs_snippet.html
  2. 7
      sigi/apps/home/urls.py
  3. 57
      sigi/apps/home/views.py
  4. 10
      sigi/apps/servicos/filters.py

2
sigi/apps/home/templates/home/dashboard/ufs_snippet.html

@ -12,7 +12,7 @@
<div class="collapsible-body"> <div class="collapsible-body">
<ul> <ul>
<li> <li>
<a class="dashlink" href="{% url "home_chartusoservico" %}?uf=_all" data-target="chartusoservico"> <a class="dashlink" href="{% url "home_chartusoservico" %}?uf=_all" data-target="chartusoservico-chart">
{% trans "Todo o país" %} {% trans "Todo o país" %}
</a> </a>
</li> </li>

7
sigi/apps/home/urls.py

@ -11,10 +11,15 @@ urlpatterns = [
path("home/resumoseit/", views.resumo_seit, name="home_resumoseit"), path("home/resumoseit/", views.resumo_seit, name="home_resumoseit"),
path("home/chartseit/", views.chart_seit, name="home_chartseit"), path("home/chartseit/", views.chart_seit, name="home_chartseit"),
path( path(
"home/cartusoservico/", "home/chartusoservico/",
views.chart_uso_servico, views.chart_uso_servico,
name="home_chartusoservico", name="home_chartusoservico",
), ),
path(
"home/chartatualizacao/",
views.chart_atualizacao_servicos,
name="home_chartatualizacao",
),
path( path(
"home/chartperformance/", "home/chartperformance/",
views.chart_performance, views.chart_performance,

57
sigi/apps/home/views.py

@ -409,7 +409,7 @@ def chart_seit(request):
@never_cache @never_cache
@login_required @login_required
def chart_uso_servico(request): def chart_uso_servico(request):
colors, highlights = color_palete() colors, *__ = color_palete()
ufs = UnidadeFederativa.objects.all() ufs = UnidadeFederativa.objects.all()
sigla_uf = request.GET.get("uf", "_all") sigla_uf = request.GET.get("uf", "_all")
@ -457,6 +457,61 @@ def chart_uso_servico(request):
return JsonResponse(chart) 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 # @never_cache
# @login_required # @login_required
# def chart_convenios(request): # def chart_convenios(request):

10
sigi/apps/servicos/filters.py

@ -77,7 +77,7 @@ class DataUtimoUsoFilter(admin.SimpleListFilter):
if self.value() == "err": if self.value() == "err":
queryset = queryset.exclude(erro_atualizacao="") queryset = queryset.exclude(erro_atualizacao="")
elif self.value() == "year": elif self.value() == "year":
limite = date.today() - timedelta(days=365) limite = date.today() - timedelta(days=366)
queryset = queryset.filter(data_ultimo_uso__lte=limite) queryset = queryset.filter(data_ultimo_uso__lte=limite)
else: else:
de = date.today() - ( de = date.today() - (
@ -89,14 +89,14 @@ class DataUtimoUsoFilter(admin.SimpleListFilter):
if self.value() == "month" if self.value() == "month"
else timedelta(days=30) else timedelta(days=30)
if self.value() == "week" if self.value() == "week"
else timedelta(days=0) else timedelta(days=6)
) )
ate = date.today() - ( ate = date.today() - (
timedelta(days=6 * 30) timedelta(days=6 * 30 + 1)
if self.value() == "semester" if self.value() == "semester"
else timedelta(days=3 * 30) else timedelta(days=3 * 30 + 1)
if self.value() == "quarter" if self.value() == "quarter"
else timedelta(days=30) else timedelta(days=31)
if self.value() == "month" if self.value() == "month"
else timedelta(days=7) else timedelta(days=7)
if self.value() == "week" if self.value() == "week"

Loading…
Cancel
Save