Forráskód Böngészése

Added a field to custom reply and fix all issues associate with it

Mohidul Islam 5 éve
szülő
commit
cf6aa09c8f

+ 0 - 25
dashboard/templates/_reportsidebar.html

@@ -30,31 +30,6 @@
       </div>
   </div>
 </div>
-<!--  ================================================================================================================================-->
-<!--  This is for temporary use, It will be remove in future release.-->
-<!--  This part of code block is used for show all reviews as intent classifier make mistake sometime. -->
-  <div class="card">
-  <div class="card-body">
-    <h5 class="card-title">Not classified</h5>
-    <hr>
-        {% for key, data in replies2.items %}
-        <div class="card">
-          <h5 class="card-header">{{key}}</h5>
-          <div class="card-body" style="padding: 1px">
-            <ul class="list-group list-group-item-action">
-                {% for reply in data %}
-                  <li class="list-group-item" style="font-size: 14px" ><p>{{ reply.reply }}</p></li>
-                {% endfor %}
-            </ul>
-        </div>
-      {% endfor %}
-      </div>
-  </div>
-  </div>
-
-<!--  End of the temporary code block-->
-<!--  ================================================================================================================================-->
-
 </div>
 
 

+ 30 - 36
nlu_job/views.py

@@ -16,13 +16,36 @@ from .nlu_utils import (
 
 @login_required
 def predict_report(request, review_id):
-    review = Review.objects.filter(review_id=review_id).first()
-    if review is None:
-        return redirect('un-replied-review')
-    location_id = review.location.location_id
-    text = review.comment.lower()
-    res = model_inference(text=text)
-    intents = analyze_inference(res)
+    review = Review.objects.get(review_id=review_id)
+    location_id = review.location_id
+    replies = {}
+    if review.star_rating == 5:
+        text = review.comment.lower()
+        res = model_inference(text=text)
+        intents = analyze_inference(res)
+        for intent in intents.keys():
+            r = CustomReply.objects.filter(reply_category=intent)
+            filtered_replies = filter_with_last_ten_reviews(location_id, r)
+            replies[intent] = filtered_replies
+
+    elif review.star_rating == 4:
+        intents = {'four_star': 100}
+        cr = CustomReply.objects.filter(reply_star=4)
+        filtered_replies = filter_with_last_ten_reviews(location_id, cr)
+        replies = {'four_star': filtered_replies}
+
+    elif review.star_rating == 3:
+        intents = {'three_star': 100}
+        cr = CustomReply.objects.filter(reply_star=3)
+        filtered_replies = filter_with_last_ten_reviews(location_id, cr)
+        replies = {'three_star': filtered_replies}
+
+    else:
+        intents = {'negative': 100}
+        cr = CustomReply.objects.filter(reply_star__lte=2)
+        filtered_replies = filter_with_last_ten_reviews(location_id, cr)
+        replies = {'negative': filtered_replies}
+
     now = timezone.now()
     form = ReplyForm()
     date = now - timezone.timedelta(days=30)
@@ -39,40 +62,11 @@ def predict_report(request, review_id):
         reviews = paginator.page(1)
     except EmptyPage:
         reviews = paginator.page(paginator.num_pages)
-    if review.star_rating == 5:
-        replies = {}
-        for intent in intents.keys():
-            r = CustomReply.objects.filter(reply_category=intent)
-            filtered_replies = filter_with_last_ten_reviews(location_id, r)
-            replies[intent] = filtered_replies
 
-        # ================================================================================================================================
-        # This is for temporary use, It will be remove in future release.
-        # This part of code block is used for show all reviews as intent classifier make mistake sometime.
-        replies2 = {}
-        rep_cls = {'staff', 'facility', 'kids', 'quick', 'general_review', 'open_24', 'continuous_visit'}.difference(set(intents.keys()))
-        for c in rep_cls:
-            r = CustomReply.objects.filter(reply_category=c)
-            filtered_replies = filter_with_last_ten_reviews(location_id, r)
-            replies2[c] = filtered_replies
-
-        # End of the temporary code block
-        # ================================================================================================================================
-    else:
-        cr = CustomReply.objects.values('reply_category').distinct()
-        cr_li = {c_r['reply_category'] for c_r in cr}
-        rep_cls = cr_li.difference({'staff', 'facility', 'kids', 'quick', 'general_review', 'open_24', 'continuous_visit', 'no_comment'})
-        replies = {}
-        replies2 = None
-        for c in rep_cls:
-            r = CustomReply.objects.filter(reply_category=c)
-            filtered_replies = filter_with_last_ten_reviews(location_id, r)
-            replies[c] = filtered_replies
     context = {
         'reviews': reviews,
         'form': form,
         'intents': intents,
         'replies': replies,
-        'replies2': replies2         # This context is associate with the temporary code that mentioned above.
     }
     return render(request, 'dashboard.html', context)

+ 18 - 0
review/migrations/0010_customreply_reply_star.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.0.4 on 2020-04-09 08:02
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('review', '0009_auto_20200204_0638'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='customreply',
+            name='reply_star',
+            field=models.IntegerField(default=5),
+        ),
+    ]

+ 1 - 0
review/models.py

@@ -28,6 +28,7 @@ class Review(models.Model):
 class CustomReply(models.Model):
     reply = models.TextField()
     reply_category = models.CharField(max_length=120)
+    reply_star = models.IntegerField(default=5)
 
     def __str__(self):
         return f'{self.reply_category} - {self.reply}'