grafico cozinha dinamico

This commit is contained in:
2025-01-13 10:34:16 -03:00
parent 7b01316834
commit c7687f7b9a
7 changed files with 88 additions and 7 deletions

View File

@@ -26,6 +26,7 @@ RRB&C - DashBoard
{% block 'body' %} {% block 'body' %}
<body> <body>
<h1>DashBoard</h1> <h1>DashBoard</h1>
<div class="grid-container"> <div class="grid-container">
@@ -45,11 +46,15 @@ RRB&C - DashBoard
<h4> Gráficos de vendas </h4> <h4> Gráficos de vendas </h4>
<div></div> <div></div>
<canvas id="vendas" style="width:100%;height: 85%;max-width:100%; background-color: rgb(191, 225, 255);border-radius: 5px;"> <canvas id="vendas" style="width:100%;height: 85%;max-width:100%; background-color: rgb(191, 225, 255);border-radius: 5px;">
</canvas> </canvas>
</div>
<div class="card">
<h4> Gráficos cozinha </h4>
<div></div>
<canvas id="cuisine" style="width:100%;height: 85%;max-width:100%; background-color: rgb(191, 225, 255);border-radius: 5px;">
</canvas>
</div> </div>
<div class="card"> <div class="card">

View File

@@ -3,5 +3,6 @@ from . import views
urlpatterns = [ urlpatterns = [
path('', views.home, name='home'), path('', views.home, name='home'),
path('chartCuisine', views.chartCuisine, name='chartCuisine'),
] ]

View File

@@ -1,9 +1,11 @@
from django.shortcuts import render from django.shortcuts import render
from django.db.models import Sum from django.db.models import Sum
from django.db.models import Count, F from django.db.models import Count, F
from django.http import JsonResponse
from comandas.models import ProductComanda from comandas.models import ProductComanda
from products.models import Product from orders.models import Order
from payments.models import Payments from payments.models import Payments
def home(request): def home(request):
@@ -15,5 +17,34 @@ def home(request):
produtos_mais_vendidos = ProductComanda.objects.values('product').annotate( produtos_mais_vendidos = ProductComanda.objects.values('product').annotate(
quantidade=Count('product'), quantidade=Count('product'),
nome=F('product__name') ).order_by('-quantidade')[:5] 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}) 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,
})

View File

@@ -1,7 +1,6 @@
console.log(document.getElementById('n-0')) function productsPlus(){
var xValues = [document.getElementById('n-0').innerText, var xValues = [document.getElementById('n-0').innerText,
document.getElementById('n-1').innerText, document.getElementById('n-1').innerText,
@@ -34,4 +33,49 @@ new Chart("vendas", {
}, },
} }
}); });
}
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()