3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-24 20:33:12 +00:00

Fix diagramme profil

This commit is contained in:
Yoann Pétri 2019-01-06 04:39:30 +01:00
parent d94676d5ec
commit fb33396956
6 changed files with 54 additions and 22 deletions

View file

@ -0,0 +1,23 @@
# Generated by Django 2.1 on 2019-01-05 23:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('gestion', '0004_auto_20181223_1830'),
]
operations = [
migrations.AddField(
model_name='historicalproduct',
name='showingMultiplier',
field=models.PositiveIntegerField(default=1),
),
migrations.AddField(
model_name='product',
name='showingMultiplier',
field=models.PositiveIntegerField(default=1),
),
]

View file

@ -39,6 +39,7 @@ class Product(models.Model):
volume = models.PositiveIntegerField(default=0)
deg = models.DecimalField(default=0,max_digits=5, decimal_places=2, verbose_name="Degré", validators=[MinValueValidator(0)])
adherentRequired = models.BooleanField(default=True, verbose_name="Adhérent requis")
showingMultiplier = models.PositiveIntegerField(default=1)
history = HistoricalRecords()
def __str__(self):

View file

@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load static %}
{% load users_extra %}
{% block entete %}{% if self %}Mon Profil{% else %}Profil de {{user}}{% endif %}{%endblock%}
{% block navbar %}
@ -97,22 +98,10 @@
label: '# of Votes',
data: [{% for q in quantities %}{{q}}, {% endfor %}],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
{% for q in products %}
'rgb({% random_filter 0 255 %}, {% random_filter 0 255 %}, {% random_filter 0 255 %})',
{% endfor %}
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {

View file

View file

@ -0,0 +1,9 @@
import random
from django import template
register = template.Library()
@register.simple_tag
def random_filter(a, b):
return random.randint(a, b)

View file

@ -154,15 +154,25 @@ def profile(request, pk):
whitelists = WhiteListHistory.objects.filter(user=user)
reloads = Reload.objects.filter(customer=user).order_by('-date')[:5]
consumptionsChart = Consumption.objects.filter(customer=user)
products_pre = []
quantities_pre = []
for ch in consumptionsChart:
if ch.product in products_pre:
i = products_pre.index(ch.product)
quantities_pre[i] += int(ch.quantity/ch.product.showingMultiplier)
else:
products_pre.append(ch.product)
quantities_pre.append(int(ch.quantity/ch.product.showingMultiplier))
tot = len(products_pre)
totQ = sum(quantities_pre)
products = []
quantities = []
for ch in consumptionsChart:
if ch.product in products:
i = products.index(ch.product)
quantities[i] += ch.quantity
else:
products.append(ch.product)
quantities.append(ch.quantity)
for k in range(tot):
if quantities_pre[k]/totQ >= 0.01:
products.append(products_pre[k])
quantities.append(quantities_pre[k])
print(products)
print(quantities)
lastConsumptions = ConsumptionHistory.objects.filter(customer=user).order_by('-date')[:10]
lastMenus = MenuHistory.objects.filter(customer=user).order_by('-date')[:10]
return render(request, "users/profile.html",