optimized food rating
This commit is contained in:
parent
ef59883834
commit
915f7a84fe
40
ofu_app/apps/food/migrations/0005_auto_20171020_0549.py
Normal file
40
ofu_app/apps/food/migrations/0005_auto_20171020_0549.py
Normal file
@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.2 on 2017-10-20 03:49
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0004_auto_20171020_0146'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='singlefood',
|
||||
name='fifth_star',
|
||||
field=models.SmallIntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='singlefood',
|
||||
name='first_star',
|
||||
field=models.SmallIntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='singlefood',
|
||||
name='fourth_star',
|
||||
field=models.SmallIntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='singlefood',
|
||||
name='second_star',
|
||||
field=models.SmallIntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='singlefood',
|
||||
name='third_star',
|
||||
field=models.SmallIntegerField(default=0),
|
||||
),
|
||||
]
|
||||
@ -25,6 +25,11 @@ class SingleFood(models.Model):
|
||||
name = models.CharField(unique=True, max_length=MAX_LENGTH)
|
||||
image = models.ImageField(upload_to='food/%Y/%m/', blank=True)
|
||||
rating = models.FloatField(default=0)
|
||||
first_star = models.SmallIntegerField(default=0)
|
||||
second_star = models.SmallIntegerField(default=0)
|
||||
third_star = models.SmallIntegerField(default=0)
|
||||
fourth_star = models.SmallIntegerField(default=0)
|
||||
fifth_star = models.SmallIntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@ -17,7 +17,27 @@ def daily_food(request):
|
||||
print("ID: %s, RATING: %s" % (id, rating))
|
||||
if id and rating:
|
||||
food = SingleFood.objects.get(id=id)
|
||||
food.rating = rating
|
||||
if rating == str(1):
|
||||
print("First Start")
|
||||
food.first_star = food.first_star + 1
|
||||
if rating == str(2):
|
||||
print("First Start")
|
||||
food.second_star += 1
|
||||
if rating == str(3):
|
||||
print("First Start")
|
||||
food.third_star += 1
|
||||
if rating == str(4):
|
||||
print("First Start")
|
||||
food.fourth_star += 1
|
||||
if rating == str(5):
|
||||
print("First Start")
|
||||
food.fifth_star += 1
|
||||
global_count = food.first_star + food.second_star + food.third_star + food.fourth_star + food.fifth_star
|
||||
print("GLOBAL_COUNT: " + str(global_count))
|
||||
sum = food.first_star * 1 + food.second_star * 2 + food.third_star * 3 + food.fourth_star * 4 + food.fifth_star * 5
|
||||
print("SUM: " + str(sum))
|
||||
food.rating = sum / global_count
|
||||
print("SUMME:------------------" + str(sum / global_count))
|
||||
food.save()
|
||||
print("DONE")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user