corrected problem with tags count on annotation creation + added relevant tags and accurate tags stats displayed
authordurandn
Fri, 14 Oct 2016 11:50:39 +0200
changeset 228 64940145bf13
parent 227 b67ea0d6c621
child 229 320c307a57ec
corrected problem with tags count on annotation creation + added relevant tags and accurate tags stats displayed
src/iconolab/models.py
src/iconolab/settings/__init__.py
src/iconolab/settings/dev.py.tmpl
src/iconolab/templates/partials/annotation_stats_panel.html
--- a/src/iconolab/models.py	Thu Oct 13 13:51:43 2016 +0200
+++ b/src/iconolab/models.py	Fri Oct 14 11:50:39 2016 +0200
@@ -6,8 +6,9 @@
 from django_comments_xtd.models import XtdComment
 from django.utils.text import slugify
 import iconolab.signals.handlers as iconolab_signals
-import uuid, json, re, requests, urllib
+import uuid, json, re, requests, urllib, logging
 
+logger = logging.getLogger(__name__)
 
 class Tag(models.Model):
     label = models.CharField(max_length=255, blank=True, null=True)
@@ -194,8 +195,8 @@
         
         # Create stats object
         new_annotation_stats = AnnotationStats(annotation=new_annotation)
+        new_annotation_stats.set_tags_stats()
         new_annotation_stats.save()
-        new_annotation_stats.set_tags_stats()
         
         # Link everything to parent
         new_annotation.current_revision = initial_revision
@@ -229,7 +230,15 @@
         return User.objects.filter(id__in=user_ids_list).distinct()
     
     def set_tags_stats(self):
-        self.tag_count = Tag.objects.filter(tagginginfo__revision__annotation = self.annotation).distinct().count()
+        self.tag_count = Tag.objects.filter(tagginginfo__revision = self.annotation.current_revision).distinct().count()
+    
+    @property
+    def relevant_tags_count(self, score=settings.RELEVANT_TAGS_MIN_SCORE):
+        return TaggingInfo.objects.filter(revision=self.annotation.current_revision, relevancy__gte=score).distinct().count()
+    
+    @property
+    def accurate_tags_count(self, score=settings.ACCURATE_TAGS_MIN_SCORE):
+        return TaggingInfo.objects.filter(revision=self.annotation.current_revision, accuracy__gte=score).distinct().count()
     
     @transaction.atomic
     def update_stats(self):
@@ -248,8 +257,7 @@
         # contributors_count
         self.contributors_count = len(self.contributors)
         # tag_count
-        self.tag_count = Tag.objects.filter(tagginginfo__revision__annotation = self.annotation).distinct().count()
-        
+        self.set_tags_stats()
         self.save()
 
 
--- a/src/iconolab/settings/__init__.py	Thu Oct 13 13:51:43 2016 +0200
+++ b/src/iconolab/settings/__init__.py	Fri Oct 14 11:50:39 2016 +0200
@@ -224,3 +224,6 @@
 IMG_JPG_DEFAULT_QUALITY = 80
 
 DJANGO_RUNSERVER = (len(sys.argv)>1 and sys.argv[1] == 'runserver')
+
+RELEVANT_TAGS_MIN_SCORE = 3
+ACCURATE_TAGS_MIN_SCORE = 3
--- a/src/iconolab/settings/dev.py.tmpl	Thu Oct 13 13:51:43 2016 +0200
+++ b/src/iconolab/settings/dev.py.tmpl	Fri Oct 14 11:50:39 2016 +0200
@@ -256,3 +256,6 @@
 
 INTERNAL_TAGS_URL = BASE_URL
 JOCONDE_NOTICE_BASE_URL = "http://www.culture.gouv.fr/public/mistral/joconde_fr?ACTION=CHERCHER&FIELD_98=REF&VALUE_98="
+
+RELEVANT_TAGS_MIN_SCORE = 3
+ACCURATE_TAGS_MIN_SCORE = 3
--- a/src/iconolab/templates/partials/annotation_stats_panel.html	Thu Oct 13 13:51:43 2016 +0200
+++ b/src/iconolab/templates/partials/annotation_stats_panel.html	Fri Oct 14 11:50:39 2016 +0200
@@ -12,6 +12,10 @@
       <dd><span class="badge">{{ annotation.stats.accepted_revisions_count }}</span></dd>
       <dt>Nombre de mots-clés :</dt>
       <dd><span class="badge">{{ annotation.stats.tag_count }}</span></dd>
+      <dt>... dont pertinents:</dt>
+      <dd><span class="badge {% if annotation.stats.relevant_tags_count > 0 %}badge-warning{% endif %}">{{ annotation.stats.relevant_tags_count }}</span></dd>
+      <dt>... dont précis:</dt>
+      <dd><span class="badge {% if annotation.stats.accurate_tags_count > 0 %}badge-warning{% endif %}">{{ annotation.stats.accurate_tags_count }}</span></dd>
     </dl>
   </div>
 </div>
\ No newline at end of file