<file_sep>from django.urls import path
from .views import *

app_name = 'Furniture'

urlpatterns = [
    path('mdfwalldecor', mdfwalldecor, name='mdfwalldecor'),
    path('furniturecafestool', furniturecafestool, name='furniturecafestool'),
    path('woodkeyholder', woodkeyholder, name='woodkeyholder'),
    path('storagecase', storagecase, name='storagecase'),
    path('wallmirror', wallmirror, name='wallmirror'),
    path('entunit', entunit, name='entunit'),
]<file_sep># Generated by Django 3.2 on 2021-06-01 17:32

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Comments',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('pid', models.CharField(max_length=10)),
                ('uid', models.CharField(max_length=10)),
                ('rating', models.FloatField(default=0)),
                ('comment', models.CharField(blank=True, max_length=1000, null=True)),
                ('date', models.DateTimeField()),
            ],
        ),
        migrations.CreateModel(
            name='Mobiles',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('product_id', models.CharField(max_length=10, unique=True)),
                ('product_name', models.CharField(max_length=100)),
                ('product_desc', models.CharField(max_length=200)),
                ('price', models.CharField(max_length=10)),
                ('colour', models.CharField(max_length=20)),
                ('image1', models.ImageField(upload_to='')),
                ('image2', models.ImageField(upload_to='')),
                ('image3', models.ImageField(upload_to='')),
                ('image4', models.ImageField(upload_to='')),
                ('image5', models.ImageField(upload_to='')),
                ('os', models.CharField(max_length=10)),
                ('ram', models.CharField(max_length=10)),
                ('product_dimensions', models.CharField(max_length=50)),
                ('batteries', models.CharField(max_length=100)),
                ('item_model_number', models.CharField(max_length=10)),
                ('wireless_features', models.CharField(max_length=1000)),
                ('special_features', models.CharField(max_length=1000)),
                ('display', models.CharField(max_length=1000)),
                ('camera', models.CharField(max_length=200)),
                ('form_factor', models.CharField(max_length=100)),
                ('battery_power', models.IntegerField()),
                ('manufacturer', models.CharField(max_length=100)),
                ('origin', models.CharField(max_length=20)),
                ('asin', models.CharField(max_length=30)),
                ('average_customer_rating', models.FloatField(default=0)),
                ('best_sellers', models.CharField(max_length=200)),
                ('launch_date', models.CharField(max_length=50)),
                ('manufacture_address', models.CharField(max_length=200)),
                ('generic_name', models.CharField(max_length=20)),
                ('model_rating', models.FloatField(default=0)),
            ],
        ),
        migrations.CreateModel(
            name='Features',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('features', models.CharField(max_length=500)),
                ('pid', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Mobiles.mobiles', to_field='product_id')),
            ],
        ),
    ]
<file_sep># Generated by Django 3.2 on 2021-06-06 10:33

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Comments',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('pid', models.CharField(max_length=10)),
                ('uid', models.CharField(max_length=10)),
                ('rating', models.FloatField(default=0)),
                ('comment', models.CharField(blank=True, max_length=1000, null=True)),
                ('date', models.DateTimeField()),
            ],
        ),
    ]
<file_sep>from django.shortcuts import render
from .models import *
from django.contrib.auth.models import User
from datetime import date
import tensorflow as tf
import numpy as np
from django.db.models import Count

# Create your views here.

new_model = tf.keras.models.load_model('Machine learning models/stack.tf')

def zeellehenga(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'CLO1', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'CLO1', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'CLO1').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'CLO1').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Clothing.objects.get(product_id='CLO1').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Clothing.objects.update_or_create(product_id='CLO1', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='CLO1')
    row = Clothing.objects.get(product_id='CLO1')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'image1': '../static/images/clothing/taslarbabyjumpsuit/' + str(row.image1),
        'image2': '../static/images/clothing/taslarbabyjumpsuit/' + str(row.image2),
        'image3': '../static/images/clothing/taslarbabyjumpsuit/' + str(row.image3),
        'image4': '../static/images/clothing/taslarbabyjumpsuit/' + str(row.image4),
        'image5': '../static/images/clothing/taslarbabyjumpsuit/' + str(row.image5),
        'product_dimensions': row.product_dimensions,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Clothing/zeellehenga.html', context=context)

def babyjumpsuit(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'CLO6', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'CLO6', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'CLO6').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'CLO6').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Clothing.objects.get(product_id='CLO6').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Clothing.objects.update_or_create(product_id='CLO6', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='CLO6')
    row = Clothing.objects.get(product_id='CLO6')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'image1': row.image1,
        'image2': row.image2,
        'image3': row.image3,
        'image4': row.image4,
        'image5': row.image5,
        'product_dimensions': row.product_dimensions,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Clothing/babyjumpsuit.html', context=context)

def mensweatshirt(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'CLO3', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'CLO3', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'CLO3').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'CLO3').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Clothing.objects.get(product_id='CLO3').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Clothing.objects.update_or_create(product_id='CLO3', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='CLO3')
    row = Clothing.objects.get(product_id='CLO3')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'image1': row.image1,
        'image2': row.image2,
        'image3': row.image3,
        'image4': row.image4,
        'image5': row.image5,
        'product_dimensions': row.product_dimensions,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Clothing/mensweatshirt.html', context=context)

def menshirt(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'CLO4', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'CLO4', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'CLO4').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'CLO4').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Clothing.objects.get(product_id='CLO4').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Clothing.objects.update_or_create(product_id='CLO4', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='CLO4')
    row = Clothing.objects.get(product_id='CLO4')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'image1': row.image1,
        'image2': row.image2,
        'image3': row.image3,
        'image4': row.image4,
        'image5': row.image5,
        'product_dimensions': row.product_dimensions,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Clothing/menshirt.html', context=context)

def babyromper(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'CLO5', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'CLO5', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'CLO5').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'CLO5').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Clothing.objects.get(product_id='CLO5').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Clothing.objects.update_or_create(product_id='CLO5', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='CLO5')
    row = Clothing.objects.get(product_id='CLO5')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'image1': row.image1,
        'image2': row.image2,
        'image3': row.image3,
        'image4': row.image4,
        'image5': row.image5,
        'product_dimensions': row.product_dimensions,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Clothing/babyromper.html', context=context)

def bandhejsaree(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'CLO2', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'CLO2', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'CLO2').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'CLO2').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Clothing.objects.get(product_id='CLO2').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Clothing.objects.update_or_create(product_id='CLO2', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='CLO2')
    row = Clothing.objects.get(product_id='CLO2')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'image1': row.image1,
        'image2': row.image2,
        'image3': row.image3,
        'image4': row.image4,
        'image5': row.image5,
        'product_dimensions': row.product_dimensions,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Clothing/bandhejsaree.html', context=context)<file_sep>from django.shortcuts import render
from .models import *
from django.contrib.auth.models import User
from datetime import date
import tensorflow as tf
import numpy as np
from django.db.models import Count

# Create your views here.

new_model = tf.keras.models.load_model('Machine learning models/stack.tf')

def oneplus(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'MOB1', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'MOB1', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'MOB1').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'MOB1').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Mobiles.objects.get(product_id='MOB1').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Mobiles.objects.update_or_create(product_id='MOB1', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='MOB1')
    row = Mobiles.objects.get(product_id='MOB1')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': '../static/images/mobiles/onepluseightpro/' + str(row.image1),
        'image2': '../static/images/mobiles/onepluseightpro/' + str(row.image2),
        'image3': '../static/images/mobiles/onepluseightpro/' + str(row.image3),
        'image4': '../static/images/mobiles/onepluseightpro/' + str(row.image4),
        'image5': '../static/images/mobiles/onepluseightpro/' + str(row.image5),
        'os': row.os,
        'ram': row.ram,
        'product_dimensions': row.product_dimensions,
        'batteries': row.batteries,
        'item_model_number': row.item_model_number,
        'wireless': row.wireless_features,
        'special': row.special_features,
        'display': row.display,
        'camera': row.camera,
        'form_factor': row.form_factor,
        'battery_power': row.battery_power,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'manufacture_address': row.manufacture_address,
        'generic_name': row.generic_name,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Mobiles/onepluseightpro.html', context=context)

def redmi9power(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'MOB2', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'MOB2', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'MOB2').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'MOB2').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Mobiles.objects.get(product_id='MOB2').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Mobiles.objects.update_or_create(product_id='MOB2', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='MOB2')
    row = Mobiles.objects.get(product_id='MOB2')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': row.image1,
        'image2': row.image2,
        'image3': row.image3,
        'image4': row.image4,
        'image5': row.image5,
        'os': row.os,
        'ram': row.ram,
        'product_dimensions': row.product_dimensions,
        'batteries': row.batteries,
        'item_model_number': row.item_model_number,
        'wireless': row.wireless_features,
        'special': row.special_features,
        'display': row.display,
        'camera': row.camera,
        'form_factor': row.form_factor,
        'battery_power': row.battery_power,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'manufacture_address': row.manufacture_address,
        'generic_name': row.generic_name,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Mobiles/redmi9power.html', context=context)

def samsunggalaxym51(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'MOB3', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'MOB3', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'MOB3').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'MOB3').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Mobiles.objects.get(product_id='MOB3').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Mobiles.objects.update_or_create(product_id='MOB3', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='MOB3')
    row = Mobiles.objects.get(product_id='MOB3')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': row.image1,
        'image2': row.image2,
        'image3': row.image3,
        'image4': row.image4,
        'image5': row.image5,
        'os': row.os,
        'ram': row.ram,
        'product_dimensions': row.product_dimensions,
        'batteries': row.batteries,
        'item_model_number': row.item_model_number,
        'wireless': row.wireless_features,
        'special': row.special_features,
        'display': row.display,
        'camera': row.camera,
        'form_factor': row.form_factor,
        'battery_power': row.battery_power,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'manufacture_address': row.manufacture_address,
        'generic_name': row.generic_name,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Mobiles/samsunggalaxym51.html', context=context)

def iphone12mini(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'MOB6', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'MOB6', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'MOB6').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'MOB6').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Mobiles.objects.get(product_id='MOB6').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Mobiles.objects.update_or_create(product_id='MOB6', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='MOB6')
    row = Mobiles.objects.get(product_id='MOB6')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': row.image1,
        'image2': row.image2,
        'image3': row.image3,
        'image4': row.image4,
        'image5': row.image5,
        'os': row.os,
        'ram': row.ram,
        'product_dimensions': row.product_dimensions,
        'batteries': row.batteries,
        'item_model_number': row.item_model_number,
        'wireless': row.wireless_features,
        'special': row.special_features,
        'display': row.display,
        'camera': row.camera,
        'form_factor': row.form_factor,
        'battery_power': row.battery_power,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'manufacture_address': row.manufacture_address,
        'generic_name': row.generic_name,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Mobiles/iphone12mini.html', context=context)

def nokia34(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'MOB4', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'MOB4', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'MOB4').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'MOB4').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Mobiles.objects.get(product_id='MOB4').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Mobiles.objects.update_or_create(product_id='MOB4', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='MOB4')
    row = Mobiles.objects.get(product_id='MOB4')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': row.image1,
        'image2': row.image2,
        'image3': row.image3,
        'image4': row.image4,
        'image5': row.image5,
        'os': row.os,
        'ram': row.ram,
        'product_dimensions': row.product_dimensions,
        'batteries': row.batteries,
        'item_model_number': row.item_model_number,
        'wireless': row.wireless_features,
        'special': row.special_features,
        'display': row.display,
        'camera': row.camera,
        'form_factor': row.form_factor,
        'battery_power': row.battery_power,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'manufacture_address': row.manufacture_address,
        'generic_name': row.generic_name,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Mobiles/nokia3.4.html', context=context)

def vivoy20(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'MOB5', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'MOB5', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'MOB5').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'MOB5').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Mobiles.objects.get(product_id='MOB5').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Mobiles.objects.update_or_create(product_id='MOB5', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='MOB5')
    row = Mobiles.objects.get(product_id='MOB5')
    features = list(Features.objects.filter(pid=row))
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': row.image1,
        'image2': row.image2,
        'image3': row.image3,
        'image4': row.image4,
        'image5': row.image5,
        'os': row.os,
        'ram': row.ram,
        'product_dimensions': row.product_dimensions,
        'batteries': row.batteries,
        'item_model_number': row.item_model_number,
        'wireless': row.wireless_features,
        'special': row.special_features,
        'display': row.display,
        'camera': row.camera,
        'form_factor': row.form_factor,
        'battery_power': row.battery_power,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'manufacture_address': row.manufacture_address,
        'generic_name': row.generic_name,
        'features': features,
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Mobiles/vivoy20.html', context=context)<file_sep>from django.urls import path
from .views import *

app_name = 'Clothing'

urlpatterns = [
    path('zeellehenga', zeellehenga, name='zeellehenga'),
    path('babyjumpsuit', babyjumpsuit, name='babyjumpsuit'),
    path('mensweatshirt', mensweatshirt, name='mensweatshirt'),
    path('menshirt', menshirt, name='menshirt'),
    path('babyromper', babyromper, name='babyromper'),
    path('bandhejsaree', bandhejsaree, name='bandhejsaree'),
]<file_sep>from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class Clothing(models.Model):
    product_id = models.CharField(max_length=10, unique=True)
    product_name = models.CharField(max_length=100)
    product_desc = models.CharField(max_length=200)
    price = models.CharField(max_length=10)
    image1 = models.ImageField()
    image2 = models.ImageField()
    image3 = models.ImageField()
    image4 = models.ImageField()
    image5 = models.ImageField()
    product_dimensions = models.CharField(max_length=50)
    launch_date = models.CharField(max_length=50)
    manufacturer = models.CharField(max_length=100)
    asin = models.CharField(max_length=30)
    origin = models.CharField(max_length=20)
    department = models.CharField(max_length=10)
    weight = models.CharField(max_length=20)
    average_customer_rating = models.FloatField(default=0)
    best_sellers = models.CharField(max_length=200, blank=True)
    model_rating = models.FloatField(default=0)

class Features(models.Model):
    pid = models.ForeignKey(Clothing, on_delete=models.CASCADE, to_field='product_id')
    features = models.CharField(max_length=500)

class Comments(models.Model):
    # pid = models.ForeignKey(Clothing, on_delete=models.CASCADE, to_field='product_id')
    pid = models.CharField(max_length=10)
    # uid = models.ForeignKey(User, on_delete=models.CASCADE, to_field='username', related_name='clothing_uid')
    uid = models.CharField(max_length=10)
    rating = models.FloatField(default=0)
    comment = models.CharField(max_length=1000, blank=True, null=True)
    date = models.DateTimeField()<file_sep>from django.conf.urls import include
from django.urls import path
from . import views as login_views

app_name = 'Register_Login'

urlpatterns = [
    path('register', login_views.register, name='register'),
    path('login', login_views.user_login, name='user_login'),
    path('logout', login_views.user_logout, name='user_logout'),
]<file_sep># Generated by Django 3.2 on 2021-06-08 19:12

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('Clothing', '0001_initial'),
    ]

    operations = [
    ]
<file_sep>from django.contrib import admin
from .models import *

# Register your models here.

admin.site.register(Clothing)
admin.site.register(Features)
admin.site.register(Comments)<file_sep>from django.shortcuts import render
from .forms import UserForm
from django.contrib.auth.models import User
from .models import *


from django.urls import reverse
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth import authenticate, login, logout

# Create your views here.
def index(request):
    return render(request, 'Register_Login/index.html')

def register(request):
    registered = False
    first_name = ''
    last_name = ''
    email = ''
    username = ''
    password = ''
    if request.method == "POST":
        user_form = UserForm(data=request.POST)

        if user_form.is_valid():
            # print(User.objects.get(username=request.POST.get('username')).exists())
            user = user_form.save()
            user.set_password(user.<PASSWORD>)        # Hashing the passwords -> Encrypting them
            user.save()
            length = len(Customer.objects.all())
            customer = Customer.objects.create(uid='CUS' + str(length + 1), user=user)
            customer.save()
            registered = True
            if user.is_authenticated:
                return HttpResponseRedirect(reverse('Register_Login:user_login'))
        else:
            errors = [(k, v[0]) for k, v in user_form.errors.items()]
            # print(errors[0][1])
            print(errors)
            for i in errors:
                print(f'i = {i[0]}, first_name = {first_name}, last_name = {last_name}, email = {email}, username = {username}, password = {password}')
                if i[0] == 'first_name':
                    first_name = i[1]
                if i[0] == 'last_name':
                    last_name = i[1]
                if i[0] == 'email':
                    email = i[1]
                if i[0] == 'username':
                    username = i[1]
                if i[0] == 'password':
                    password = i[1]
            # print(f'Error = {user_form.errors}')
    else:
        user_form = UserForm()

    return render(request, 'Register_Login/register.html', {'user_form': user_form, 'registered': registered, 'first_name': first_name, 'last_name': last_name, 'email': email, 'username': username, 'password': <PASSWORD>})

def user_login(request):
    if request.method == "POST":
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username, password=<PASSWORD>)
        if user:
            login(request, user)
            return HttpResponseRedirect(reverse('index'))
        else:
            print("Someone tried to login and failed")
            print(f'Username: {username} and Password: {password}')
            return HttpResponse("Invalid login details supplied")
    return render(request, 'Register_Login/login.html', {})

@login_required
def user_logout(request):
    logout(request)
    return HttpResponseRedirect(reverse('index'))<file_sep>from django.contrib import admin
from django.conf.urls import include
from django.urls import path
from .views import *

app_name = 'Mobiles'

urlpatterns = [
    path('oneplus', oneplus, name = 'oneplus'),
    path('redmi9power', redmi9power, name = 'redmi9power'),
    path('samsunggalaxym51', samsunggalaxym51, name = 'samsunggalaxym51'),
    path('iphone12mini', iphone12mini, name = 'iphone12mini'),
    path('nokia3.4', nokia34, name = 'nokia3.4'),
    path('vivoy20', vivoy20, name = 'vivoy20'),
]<file_sep># Generated by Django 3.2 on 2021-06-08 18:06

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('Furniture', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='Furniture',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('product_id', models.CharField(max_length=10, unique=True)),
                ('product_name', models.CharField(max_length=100)),
                ('product_desc', models.CharField(max_length=200)),
                ('price', models.CharField(max_length=10)),
                ('colour', models.CharField(max_length=20)),
                ('image1', models.ImageField(upload_to='')),
                ('image2', models.ImageField(upload_to='')),
                ('image3', models.ImageField(upload_to='')),
                ('image4', models.ImageField(upload_to='')),
                ('image5', models.ImageField(upload_to='')),
                ('product_dimensions', models.CharField(max_length=50)),
                ('assembly_required', models.CharField(max_length=200)),
                ('primary_material', models.CharField(max_length=50)),
                ('finish_type', models.CharField(max_length=50)),
                ('item_shape', models.CharField(max_length=20)),
                ('manufacturer', models.CharField(max_length=100)),
                ('origin', models.CharField(max_length=20)),
                ('asin', models.CharField(max_length=30)),
                ('average_customer_rating', models.FloatField(default=0)),
                ('best_sellers', models.CharField(blank=True, max_length=200)),
                ('launch_date', models.CharField(max_length=50)),
                ('model_rating', models.FloatField(default=0)),
            ],
        ),
        migrations.CreateModel(
            name='Features',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('material', models.CharField(max_length=50)),
                ('dimensions', models.CharField(max_length=70)),
                ('weight', models.CharField(max_length=20)),
                ('brand', models.CharField(max_length=20)),
                ('assembly_required', models.CharField(max_length=200)),
                ('pid', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Furniture.furniture', to_field='product_id')),
            ],
        ),
    ]
<file_sep>from django.shortcuts import render
from .models import *
from django.contrib.auth.models import User
from datetime import date
import tensorflow as tf
import numpy as np
from django.db.models import Count

# Create your views here.

new_model = tf.keras.models.load_model('Machine learning models/stack.tf')

def mdfwalldecor(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'FUR1', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'FUR1', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'FUR1').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    # print(rating_count)
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'FUR1').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    print(f'rate1 = {rate1}, rate2 = {rate2}, rate3 = {rate3}, rate4 = {rate4}, rate5 = {rate5}')
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Furniture.objects.get(product_id='FUR1').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Furniture.objects.update_or_create(product_id='FUR1', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='FUR1')
    row = Furniture.objects.get(product_id='FUR1')
    features = Features.objects.filter(pid=row)
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': '../static/images/furniture/mdfwalldecor/' + str(row.image1),
        'image2': '../static/images/furniture/mdfwalldecor/' + str(row.image2),
        'image3': '../static/images/furniture/mdfwalldecor/' + str(row.image3),
        'image4': '../static/images/furniture/mdfwalldecor/' + str(row.image4),
        'image5': '../static/images/furniture/mdfwalldecor/' + str(row.image5),
        'product_dimensions': row.product_dimensions,
        'assembly_required': row.assembly_required,
        'primary_material': row.primary_material,
        'finish_type': row.finish_type,
        'item_shape': row.item_shape,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features[0],
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Furniture/mdfwalldecor.html', context=context)

def furniturecafestool(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'FUR2', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'FUR2', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'FUR2').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    # print(rating_count)
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'FUR2').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    print(f'rate1 = {rate1}, rate2 = {rate2}, rate3 = {rate3}, rate4 = {rate4}, rate5 = {rate5}')
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Furniture.objects.get(product_id='FUR2').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Furniture.objects.update_or_create(product_id='FUR2', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='FUR2')
    row = Furniture.objects.get(product_id='FUR2')
    features = Features.objects.filter(pid=row)
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': '../static/images/furniture/mdfwalldecor/' + str(row.image1),
        'image2': '../static/images/furniture/mdfwalldecor/' + str(row.image2),
        'image3': '../static/images/furniture/mdfwalldecor/' + str(row.image3),
        'image4': '../static/images/furniture/mdfwalldecor/' + str(row.image4),
        'image5': '../static/images/furniture/mdfwalldecor/' + str(row.image5),
        'product_dimensions': row.product_dimensions,
        'assembly_required': row.assembly_required,
        'primary_material': row.primary_material,
        'finish_type': row.finish_type,
        'item_shape': row.item_shape,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features[0],
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Furniture/furniturecafestool.html', context=context)

def woodkeyholder(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'FUR3', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'FUR3', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'FUR3').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    # print(rating_count)
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'FUR3').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    print(f'rate1 = {rate1}, rate2 = {rate2}, rate3 = {rate3}, rate4 = {rate4}, rate5 = {rate5}')
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Furniture.objects.get(product_id='FUR3').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Furniture.objects.update_or_create(product_id='FUR3', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='FUR3')
    row = Furniture.objects.get(product_id='FUR3')
    features = Features.objects.filter(pid=row)
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': '../static/images/furniture/mdfwalldecor/' + str(row.image1),
        'image2': '../static/images/furniture/mdfwalldecor/' + str(row.image2),
        'image3': '../static/images/furniture/mdfwalldecor/' + str(row.image3),
        'image4': '../static/images/furniture/mdfwalldecor/' + str(row.image4),
        'image5': '../static/images/furniture/mdfwalldecor/' + str(row.image5),
        'product_dimensions': row.product_dimensions,
        'assembly_required': row.assembly_required,
        'primary_material': row.primary_material,
        'finish_type': row.finish_type,
        'item_shape': row.item_shape,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features[0],
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Furniture/a10keyholder.html', context=context)

def storagecase(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'FUR4', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'FUR4', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'FUR4').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    # print(rating_count)
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'FUR4').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    print(f'rate1 = {rate1}, rate2 = {rate2}, rate3 = {rate3}, rate4 = {rate4}, rate5 = {rate5}')
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Furniture.objects.get(product_id='FUR4').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Furniture.objects.update_or_create(product_id='FUR4', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='FUR4')
    row = Furniture.objects.get(product_id='FUR4')
    features = Features.objects.filter(pid=row)
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': '../static/images/furniture/mdfwalldecor/' + str(row.image1),
        'image2': '../static/images/furniture/mdfwalldecor/' + str(row.image2),
        'image3': '../static/images/furniture/mdfwalldecor/' + str(row.image3),
        'image4': '../static/images/furniture/mdfwalldecor/' + str(row.image4),
        'image5': '../static/images/furniture/mdfwalldecor/' + str(row.image5),
        'product_dimensions': row.product_dimensions,
        'assembly_required': row.assembly_required,
        'primary_material': row.primary_material,
        'finish_type': row.finish_type,
        'item_shape': row.item_shape,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features[0],
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Furniture/storagecase.html', context=context)

def wallmirror(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'FUR5', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'FUR5', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'FUR5').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    # print(rating_count)
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'FUR5').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    print(f'rate1 = {rate1}, rate2 = {rate2}, rate3 = {rate3}, rate4 = {rate4}, rate5 = {rate5}')
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Furniture.objects.get(product_id='FUR5').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Furniture.objects.update_or_create(product_id='FUR5', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='FUR5')
    row = Furniture.objects.get(product_id='FUR5')
    features = Features.objects.filter(pid=row)
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': '../static/images/furniture/mdfwalldecor/' + str(row.image1),
        'image2': '../static/images/furniture/mdfwalldecor/' + str(row.image2),
        'image3': '../static/images/furniture/mdfwalldecor/' + str(row.image3),
        'image4': '../static/images/furniture/mdfwalldecor/' + str(row.image4),
        'image5': '../static/images/furniture/mdfwalldecor/' + str(row.image5),
        'product_dimensions': row.product_dimensions,
        'assembly_required': row.assembly_required,
        'primary_material': row.primary_material,
        'finish_type': row.finish_type,
        'item_shape': row.item_shape,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features[0],
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Furniture/wallmirror.html', context=context)

def entunit(request):
    rating = 0
    required = ''
    if request.method == "POST":
        # product_id can also be received with this code (with correct code - not implemented yet)
        # Check request.POST -> product_id is also returned
        data = request.POST.get('rate_value')
        cmt = request.POST.get('comment')
        if data and cmt:
            predictions = new_model.predict([cmt])
            rating = np.argmax(predictions[0])
            print(f'COMMENT = {cmt}, MODEL PREDICTED RATING = {rating}')
            comment = Comments(pid = 'FUR6', uid = request.user, comment = cmt, rating = data, date = date.today())
            comment.save()
        elif cmt:
            required = '<i class="fas fa-exclamation-triangle" style="color: orange;"></i>   Please provide a rating first to submit your review!'
        elif data:
            comment = Comments(pid = 'FUR6', uid = request.user, rating = data, date = date.today())
            comment.save()
    fieldname = 'rating'
    rating_count = Comments.objects.filter(pid = 'FUR6').values(fieldname).order_by(fieldname).annotate(the_count = Count(fieldname))
    # print(rating_count)
    rate1 = 0
    rate2 = 0
    rate3 = 0
    rate4 = 0
    rate5 = 0
    for i in rating_count:
        if i.get("rating") == 1.0:
            rate1 = i.get("the_count")
        elif i.get("rating") == 2.0:
            rate2 = i.get("the_count")
        elif i.get("rating") == 3.0:
            rate3 = i.get("the_count")
        elif i.get("rating") == 4.0:
            rate4 = i.get("the_count")
        elif i.get("rating") == 5.0:
            rate5 = i.get("the_count")
    rating_sum = rate1 * 1 + rate2 * 2 + rate3 * 3 + rate4 * 4 + rate5 * 5
    total_ratings = rate1 + rate2 + rate3 + rate4 + rate5
    word_comments = Comments.objects.filter(pid = 'FUR6').exclude(comment = 'NULL')
    total_comments = len(word_comments)
    # for i in word_comments:
    #     print(i.comment)
    print(f'rate1 = {rate1}, rate2 = {rate2}, rate3 = {rate3}, rate4 = {rate4}, rate5 = {rate5}')
    final_rating = round((rating_sum / total_ratings), 2)
    prev_model_rating = Furniture.objects.get(product_id='FUR6').model_rating
    if rating != 0:
        model_rating = round(((prev_model_rating * total_comments) + rating) / (total_comments + 1), 2)
    else:
        model_rating = prev_model_rating
    obj, created = Furniture.objects.update_or_create(product_id='FUR6', defaults={'average_customer_rating':final_rating, 'model_rating': model_rating})
    obj.save()
    rating1 = (rate1 / (total_ratings)) * 100
    rating2 = (rate2 / (total_ratings)) * 100
    rating3 = (rate3 / (total_ratings)) * 100
    rating4 = (rate4 / (total_ratings)) * 100
    rating5 = (rate5 / (total_ratings)) * 100
    final_star = final_rating * 20                          # () * 100 / 5 = () * 20
    model_star = model_rating * 20
    comments = Comments.objects.filter(pid='FUR6')
    row = Furniture.objects.get(product_id='FUR6')
    features = Features.objects.filter(pid=row)
    context = {
        'product_name': row.product_name,
        'product_specs': row.product_desc,
        'price': row.price,
        'color': row.colour,
        'image1': '../static/images/furniture/mdfwalldecor/' + str(row.image1),
        'image2': '../static/images/furniture/mdfwalldecor/' + str(row.image2),
        'image3': '../static/images/furniture/mdfwalldecor/' + str(row.image3),
        'image4': '../static/images/furniture/mdfwalldecor/' + str(row.image4),
        'image5': '../static/images/furniture/mdfwalldecor/' + str(row.image5),
        'product_dimensions': row.product_dimensions,
        'assembly_required': row.assembly_required,
        'primary_material': row.primary_material,
        'finish_type': row.finish_type,
        'item_shape': row.item_shape,
        'manufacturer': row.manufacturer,
        'origin': row.origin,
        'asin': row.asin,
        'average_customer_rating': row.average_customer_rating,
        'best_sellers': row.best_sellers,
        'launch_date': row.launch_date,
        'features': features[0],
        'comments': comments,
        'final_rating': row.average_customer_rating,
        'total_ratings': total_ratings,
        'rating1': rating5,
        'rating2': rating4,
        'rating3': rating3,
        'rating4': rating2,
        'rating5': rating1,
        'final_star': final_star,
        'model_rating': row.model_rating,
        'model_star': model_star,
        'comments': word_comments,
        'required': required,
    }
    return render(request, 'Furniture/tventunit.html', context=context)<file_sep>//jshint esversion:6

$(function () {
    $('[data-toggle="tooltip"]').tooltip();
});