From c7687f7b9aef7dc4092f7804877508ac27f89678 Mon Sep 17 00:00:00 2001 From: Welton Moura Date: Mon, 13 Jan 2025 10:34:16 -0300 Subject: [PATCH] grafico cozinha dinamico --- .../__pycache__/htmx_views.cpython-310.pyc | Bin 2864 -> 2864 bytes .../home/__pycache__/urls.cpython-310.pyc | Bin 281 -> 316 bytes .../home/__pycache__/views.cpython-310.pyc | Bin 962 -> 1600 bytes gestaoRaul/home/templates/home.html | 9 +++- gestaoRaul/home/urls.py | 1 + gestaoRaul/home/views.py | 35 +++++++++++- gestaoRaul/templates/static/home/js/home.js | 50 ++++++++++++++++-- 7 files changed, 88 insertions(+), 7 deletions(-) diff --git a/gestaoRaul/comandas/__pycache__/htmx_views.cpython-310.pyc b/gestaoRaul/comandas/__pycache__/htmx_views.cpython-310.pyc index 4eac452798929a01c78add1b32841bc462372a95..a98cb7692c20f335a9d7db81162a1a47b4866f92 100644 GIT binary patch delta 20 acmdlWwn2wqE9R zrYN=)j$j5&&WUl_g12~*GZKqRoJ%u{GxJjYG}$NiC`uP`0QKJDE-lI_NGvHyEy^oi c$xy@%6f5GMc-V^%WH%234Bk@rGGGOA9Dul3Z=$v)S2|-9YYKZXgC@ts9BpPl uO}2?E6vb|Fmlov|B$kw<7UdPMWGDg|Sj08)i5CwCkj2Bm!^p?X@gD$Dg%$(= diff --git a/gestaoRaul/home/__pycache__/views.cpython-310.pyc b/gestaoRaul/home/__pycache__/views.cpython-310.pyc index 459257b5f818f0dd5d6caf588fb9e2aac3ffa8f8..41433ac3600884ee126cd69f519968f56ce338ff 100644 GIT binary patch delta 896 zcmYk4O=}b}7{`;z&Rch8c5AiPw!R~}D7^^^#eM4iw3VyC!8GIx)VH;Jb%e#!E?zvSVvvKY1va7 ze3;}k0b;)pl!?iYW89n`;Lq5f-m`9Fclz48zZ$`*qHUyQXOmf)$B?_vin>W|}8i`Yxfo6KT5;DIDOzVzB_Cot-pOOlT)53YJst z7xnry?`wOnWaXIYP;r%H+miKoPNnvC(ma*B4CbD>(gb$ZM3zHMGL{R+nDfOY=we$L zcX3nAoWaM;m3Fu(5~=OF7gvn8t46MYbj7k6*0KU49rSh+p*G4?ra8L^MBV`LaHDRK zZ^Hso+GDO{Kz whbP`nnK$L+!c$X!bye1T{%3IJ(p!gJ%8WfSbt_G62PnX89N>UJV$TYKzo`Y}9RL6T delta 270 zcmX@WbBLWUpO=@50SL4%m8Z8dPvnzfjF_k$z{{S((ZUeLlfoIypvg6Hj;a)2Kv8~5 zX>y5ker{r3N}?v?Eq18L#FqycxhAh-T+GNZ*^fz`k!^Arlc@|Z(99x!5Wxo`1VMxV zkXXr3BsuvwlM^H7WG-e|PL?8RprD^7@8n`ui<&6@WQg&_db#;2sX4_(Y(Uv4{sM^I za8Y)MXkuk +

DashBoard

@@ -45,11 +46,15 @@ RRB&C - DashBoard

Gráficos de vendas

- - +
+
+

Gráficos cozinha

+
+ +
diff --git a/gestaoRaul/home/urls.py b/gestaoRaul/home/urls.py index 3bcaa2f..3351dac 100644 --- a/gestaoRaul/home/urls.py +++ b/gestaoRaul/home/urls.py @@ -3,5 +3,6 @@ from . import views urlpatterns = [ path('', views.home, name='home'), + path('chartCuisine', views.chartCuisine, name='chartCuisine'), ] diff --git a/gestaoRaul/home/views.py b/gestaoRaul/home/views.py index 2c55673..48756a2 100644 --- a/gestaoRaul/home/views.py +++ b/gestaoRaul/home/views.py @@ -1,9 +1,11 @@ from django.shortcuts import render from django.db.models import Sum from django.db.models import Count, F +from django.http import JsonResponse + from comandas.models import ProductComanda -from products.models import Product +from orders.models import Order from payments.models import Payments def home(request): @@ -15,5 +17,34 @@ def home(request): produtos_mais_vendidos = ProductComanda.objects.values('product').annotate( quantidade=Count('product'), nome=F('product__name') ).order_by('-quantidade')[:5] - return render(request, 'home.html', {'total_pagamentos': total_pagamentos, 'pagamentos': pagamentos, 'qdt_pagamentos': qdt_pagamentos, 'produtos_mais_vendidos': produtos_mais_vendidos, 'ticekMedio': ticekMedio}) + + +def chartCuisine(request): + print('entrooooooouuuuu') + tFila = [] + tPreparando = [] + tFinalizado = [] + + orders = Order.objects.filter(delivered__isnull=False) + + for order in orders: + tFila.append((order.preparing - order.queue).total_seconds()) + tPreparando.append((order.finished - order.preparing).total_seconds()) + tFinalizado.append((order.delivered - order.finished).total_seconds()) + + mediaFila = int((sum(tFila) / len(tFila))/60) + mediaPreparando = int((sum(tPreparando) / len(tPreparando))/60) + mediaFinalizado = int((sum(tFinalizado) / len(tFinalizado))/60) + + # orders = Order.objects.filter( + # created_at__gte='a', + # created_at__lte='b', + # delivered__isnull=False + # ) + + return JsonResponse({ + 'mediaFila': mediaFila, + 'mediaPreparando': mediaPreparando, + 'mediaFinalizado': mediaFinalizado, + }) \ No newline at end of file diff --git a/gestaoRaul/templates/static/home/js/home.js b/gestaoRaul/templates/static/home/js/home.js index 24e7080..85c4fdd 100644 --- a/gestaoRaul/templates/static/home/js/home.js +++ b/gestaoRaul/templates/static/home/js/home.js @@ -1,7 +1,6 @@ -console.log(document.getElementById('n-0')) - +function productsPlus(){ var xValues = [document.getElementById('n-0').innerText, document.getElementById('n-1').innerText, @@ -34,4 +33,49 @@ new Chart("vendas", { }, } - }); \ No newline at end of file + }); +} + + +function mediaCuisine(){ + +var yValues = []; +var xValues = ['Fila', 'Preparando', 'Entregar']; +var barColors = ["red", "green","blue","orange","brown"]; + +var resposta = fetch('/chartCuisine', {method: 'GET', + headers: {'Content-Type': 'application/json', + },}) + .then(response => response.json()) + .then(data => { + yValues.push(data['mediaFila']) + yValues.push(data['mediaPreparando']) + yValues.push(data['mediaFinalizado']) + + new Chart("cuisine", { + type: "doughnut", + data: { + labels: xValues, + datasets: [{ + backgroundColor: barColors, + data: yValues + }] + }, + options: { + legend: {display: true}, + title: { + display: true, + text: "Tempo médio (em minutos) do pedido em cada etapa." + }, + } + }); + }) + .catch(error => { + alert('Erro ao trazer dados da cozinha:', error) + console.error('Erro ao trazer dados da cozinha:', error); + }); +} + + +productsPlus() +mediaCuisine() \ No newline at end of file