mirror of
https://github.com/nanoy42/coope
synced 2024-11-22 03:13:12 +00:00
Fix diagramme profil
This commit is contained in:
parent
d94676d5ec
commit
fb33396956
6 changed files with 54 additions and 22 deletions
23
gestion/migrations/0005_auto_20190106_0018.py
Normal file
23
gestion/migrations/0005_auto_20190106_0018.py
Normal 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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -39,6 +39,7 @@ class Product(models.Model):
|
||||||
volume = models.PositiveIntegerField(default=0)
|
volume = models.PositiveIntegerField(default=0)
|
||||||
deg = models.DecimalField(default=0,max_digits=5, decimal_places=2, verbose_name="Degré", validators=[MinValueValidator(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")
|
adherentRequired = models.BooleanField(default=True, verbose_name="Adhérent requis")
|
||||||
|
showingMultiplier = models.PositiveIntegerField(default=1)
|
||||||
history = HistoricalRecords()
|
history = HistoricalRecords()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
{% load users_extra %}
|
||||||
{% block entete %}{% if self %}Mon Profil{% else %}Profil de {{user}}{% endif %}{%endblock%}
|
{% block entete %}{% if self %}Mon Profil{% else %}Profil de {{user}}{% endif %}{%endblock%}
|
||||||
|
|
||||||
{% block navbar %}
|
{% block navbar %}
|
||||||
|
@ -97,22 +98,10 @@
|
||||||
label: '# of Votes',
|
label: '# of Votes',
|
||||||
data: [{% for q in quantities %}{{q}}, {% endfor %}],
|
data: [{% for q in quantities %}{{q}}, {% endfor %}],
|
||||||
backgroundColor: [
|
backgroundColor: [
|
||||||
'rgba(255, 99, 132, 0.2)',
|
{% for q in products %}
|
||||||
'rgba(54, 162, 235, 0.2)',
|
'rgb({% random_filter 0 255 %}, {% random_filter 0 255 %}, {% random_filter 0 255 %})',
|
||||||
'rgba(255, 206, 86, 0.2)',
|
{% endfor %}
|
||||||
'rgba(75, 192, 192, 0.2)',
|
|
||||||
'rgba(153, 102, 255, 0.2)',
|
|
||||||
'rgba(255, 159, 64, 0.2)'
|
|
||||||
],
|
],
|
||||||
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: {
|
options: {
|
||||||
|
|
0
users/templatetags/__init__;py
Normal file
0
users/templatetags/__init__;py
Normal file
9
users/templatetags/users_extra.py
Normal file
9
users/templatetags/users_extra.py
Normal 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)
|
|
@ -154,15 +154,25 @@ def profile(request, pk):
|
||||||
whitelists = WhiteListHistory.objects.filter(user=user)
|
whitelists = WhiteListHistory.objects.filter(user=user)
|
||||||
reloads = Reload.objects.filter(customer=user).order_by('-date')[:5]
|
reloads = Reload.objects.filter(customer=user).order_by('-date')[:5]
|
||||||
consumptionsChart = Consumption.objects.filter(customer=user)
|
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 = []
|
products = []
|
||||||
quantities = []
|
quantities = []
|
||||||
for ch in consumptionsChart:
|
for k in range(tot):
|
||||||
if ch.product in products:
|
if quantities_pre[k]/totQ >= 0.01:
|
||||||
i = products.index(ch.product)
|
products.append(products_pre[k])
|
||||||
quantities[i] += ch.quantity
|
quantities.append(quantities_pre[k])
|
||||||
else:
|
print(products)
|
||||||
products.append(ch.product)
|
print(quantities)
|
||||||
quantities.append(ch.quantity)
|
|
||||||
lastConsumptions = ConsumptionHistory.objects.filter(customer=user).order_by('-date')[:10]
|
lastConsumptions = ConsumptionHistory.objects.filter(customer=user).order_by('-date')[:10]
|
||||||
lastMenus = MenuHistory.objects.filter(customer=user).order_by('-date')[:10]
|
lastMenus = MenuHistory.objects.filter(customer=user).order_by('-date')[:10]
|
||||||
return render(request, "users/profile.html",
|
return render(request, "users/profile.html",
|
||||||
|
|
Loading…
Reference in a new issue