Removed object AnnotationStat + stats are computed when projects are published/unpublished
authorverrierj
Thu, 26 Jan 2012 16:01:12 +0100
changeset 467 a1e9f5e91791
parent 460 af360d447874
child 468 d1ff0694500b
Removed object AnnotationStat + stats are computed when projects are published/unpublished
src/ldt/ldt/ldt_utils/admin.py
src/ldt/ldt/ldt_utils/contentindexer.py
src/ldt/ldt/ldt_utils/migrations/0011_gen_stat_annotation.py
src/ldt/ldt/ldt_utils/migrations/0014_auto__del_annotationstat__chg_field_content_last_annotated.py
src/ldt/ldt/ldt_utils/models.py
src/ldt/ldt/ldt_utils/stat.py
src/ldt/ldt/ldt_utils/views/lignesdetemps.py
src/ldt/ldt/management/commands/statannotation.py
--- a/src/ldt/ldt/ldt_utils/admin.py	Thu Jan 26 15:04:38 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/admin.py	Thu Jan 26 16:01:12 2012 +0100
@@ -5,17 +5,13 @@
 from ldt.ldt_utils.contentindexer import ContentIndexer, ProjectIndexer
 from ldt.ldt_utils.fileimport import FileImport, FileImportError
 from ldt.ldt_utils.forms import LdtImportForm, ReindexForm, StatAnnotationForm
-from ldt.ldt_utils.models import Content, Project, Media, Author, AnnotationStat
+from ldt.ldt_utils.models import Content, Project, Media, Author
 import ldt.indexation
 from guardian.admin import GuardedModelAdmin
 
 
-class StatInlineAdmin(admin.TabularInline):
-    model = AnnotationStat
-    extra = 1
-
 class ProjectAdmin(GuardedModelAdmin):
-    inlines = [StatInlineAdmin, ]
+    pass
 
 class AuthorAdmin(GuardedModelAdmin):
     pass
--- a/src/ldt/ldt/ldt_utils/contentindexer.py	Thu Jan 26 15:04:38 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/contentindexer.py	Thu Jan 26 16:01:12 2012 +0100
@@ -3,6 +3,7 @@
 from django.dispatch import receiver
 from ldt.ldt_utils.models import Segment, Content, Project
 from ldt.ldt_utils.utils import reduce_text_node
+from ldt.ldt_utils.stat import update_stat_project
 import ldt.indexation
 import lucene
 import lxml.etree
@@ -192,8 +193,10 @@
             if instance.state != 2:
                 writer.deleteDocuments(lucene.Term("project_id", instance.ldt_id))
                 Segment.objects.filter(project_obj__ldt_id=instance.ldt_id).delete() #@UndefinedVariable
+                update_stat_project(instance)
             else:
                 projectIndexer = ProjectIndexer([instance], writer)
                 projectIndexer.index_all()
+                update_stat_project(instance)
         finally:
             writer.close()
--- a/src/ldt/ldt/ldt_utils/migrations/0011_gen_stat_annotation.py	Thu Jan 26 15:04:38 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/migrations/0011_gen_stat_annotation.py	Thu Jan 26 16:01:12 2012 +0100
@@ -4,7 +4,6 @@
 from south.db import db
 from south.v2 import DataMigration
 from django.db import models
-from ldt.ldt_utils.stat import update_stat_project, update_stat_content
 
 
 class Migration(DataMigration):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldt/ldt/ldt_utils/migrations/0014_auto__del_annotationstat__chg_field_content_last_annotated.py	Thu Jan 26 16:01:12 2012 +0100
@@ -0,0 +1,152 @@
+#@PydevCodeAnalysisIgnore
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        db.delete_column('ldt_utils_annotationstat', 'stat')
+        db.delete_column('ldt_utils_annotationstat', 'nb_annotation')
+        db.rename_table('ldt_utils_annotationstat', 'ldt_utils_project_contents')
+        
+        # Adding field 'Segment.polemics'
+        db.add_column('ldt_utils_segment', 'polemics', self.gf('django.db.models.fields.IntegerField')(default=0, null=True, blank=True), keep_default=False)
+
+
+        
+    def backwards(self, orm):
+        
+        db.rename_table('ldt_utils_project_contents', 'ldt_utils_annotationstat')
+        db.add_column('ldt_utils_annotationstat', 'stat', self.gf('django.db.models.fields.CommaSeparatedIntegerField')(max_length=1024, null=True, blank=True), keep_default=False)
+        db.add_column('ldt_utils_annotationstat', 'nb_annotation', self.gf('django.db.models.fields.IntegerField')(default=0), keep_default=False)
+        
+        # Deleting field 'Segment.polemics'
+        db.delete_column('ldt_utils_segment', 'polemics')
+       
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'ldt_utils.author': {
+            'Meta': {'object_name': 'Author'},
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+            'firstname': ('django.db.models.fields.CharField', [], {'max_length': '512', 'null': 'True', 'blank': 'True'}),
+            'handle': ('django.db.models.fields.CharField', [], {'max_length': '512', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lastname': ('django.db.models.fields.CharField', [], {'max_length': '512', 'null': 'True', 'blank': 'True'})
+        },
+        'ldt_utils.content': {
+            'Meta': {'ordering': "['title']", 'object_name': 'Content'},
+            'authors': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['ldt_utils.Author']", 'symmetrical': 'False', 'blank': 'True'}),
+            'content_creation_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'duration': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'front_project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Project']", 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'image': ('sorl.thumbnail.fields.ImageField', [], {'default': "'thumbnails/contents/content_default_icon.png'", 'max_length': '200'}),
+            'iri_id': ('django.db.models.fields.CharField', [], {'default': "u'eef4f4d1-482b-11e1-b09b-001485352c9a'", 'unique': 'True', 'max_length': '1024'}),
+            'iriurl': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'last_annotated': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'null': 'True', 'blank': 'True'}),
+            'media_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Media']", 'null': 'True', 'blank': 'True'}),
+            'nb_annotation': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'stat_annotation': ('django.db.models.fields.CommaSeparatedIntegerField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'tags': ('tagging.fields.TagField', [], {'max_length': '2048', 'null': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'update_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'ldt_utils.media': {
+            'Meta': {'object_name': 'Media'},
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'duration': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'external_id': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'external_permalink': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'external_publication_url': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'external_src_url': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'media_creation_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'mimetype_field': ('django.db.models.fields.CharField', [], {'max_length': '512', 'null': 'True', 'blank': 'True'}),
+            'src': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '1024'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'update_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'videopath': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'})
+        },
+        'ldt_utils.project': {
+            'Meta': {'ordering': "['title']", 'object_name': 'Project'},
+            'changed_by': ('django.db.models.fields.CharField', [], {'max_length': '70'}),
+            'contents': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['ldt_utils.Content']", 'symmetrical': 'False'}),
+            'created_by': ('django.db.models.fields.CharField', [], {'max_length': '70'}),
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'image': ('sorl.thumbnail.fields.ImageField', [], {'default': "'thumbnails/projects/project_default_icon.png'", 'max_length': '200'}),
+            'ldt': ('django.db.models.fields.TextField', [], {'null': 'True'}),
+            'ldt_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '1024'}),
+            'modification_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+            'state': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '1024'})
+        },
+        'ldt_utils.segment': {
+            'Meta': {'unique_together': "(('project_id', 'iri_id', 'ensemble_id', 'cutting_id', 'element_id'),)", 'object_name': 'Segment'},
+            'abstract': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'content': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Content']"}),
+            'cutting_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'date': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
+            'duration': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+            'element_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'ensemble_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'iri_id': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'polemics': ('django.db.models.fields.IntegerField', [], {'default': '0', 'null': 'True', 'blank': 'True'}),
+            'project_id': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'project_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Project']", 'null': 'True'}),
+            'start_ts': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+            'tags': ('tagging.fields.TagField', [], {'max_length': '2048', 'null': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'null': 'True', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['ldt_utils']
--- a/src/ldt/ldt/ldt_utils/models.py	Thu Jan 26 15:04:38 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py	Thu Jan 26 16:01:12 2012 +0100
@@ -390,7 +390,7 @@
     ldt_id = models.CharField(max_length=1024, unique=True)
     ldt = models.TextField(null=True)
     title = models.CharField(max_length=1024)
-    contents = models.ManyToManyField(Content, through='AnnotationStat')
+    contents = models.ManyToManyField(Content)
     creation_date = models.DateTimeField(auto_now_add=True)
     modification_date = models.DateTimeField(auto_now=True)
     created_by = models.CharField(_("created by"), max_length=70)
@@ -522,23 +522,6 @@
         else:
             return False
         
-    def add_contents(self, contents):
-        for content in contents:
-            contribution = AnnotationStat.objects.create(project=self, content=content)
-            contribution.save() 
-            
-    def remove_contents(self, contents):
-        AnnotationStat.objects.filter(project=self, content__in=contents).delete()
-         
-        
-class AnnotationStat(SafeModel):
-    project = models.ForeignKey(Project)
-    content = models.ForeignKey(Content)
-    stat = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content.stat_annotation"))
-    nb_annotation = models.IntegerField(default=0, verbose_name=_("content.nb_annotation"))
-    
-    def __unicode__(self):
-        return "%s::%s" % (self.project.ldt_id, self.content.iri_id)
 
 class Segment(SafeModel):
     
@@ -556,6 +539,7 @@
     author = models.CharField(max_length=1024, unique=False, null=True, blank=True)
     date = models.CharField(max_length=128, unique=False, null=True, blank=True)
     abstract = models.TextField(null=True, blank=True)
+    polemics = models.IntegerField(null=True, blank=True, default=0)
     
     def __unicode__(self):
         return "/".join((unicode(self.project_id), unicode(self.iri_id), unicode(self.ensemble_id), unicode(self.cutting_id), unicode(self.element_id)))
@@ -567,3 +551,4 @@
                        )
 
 
+
--- a/src/ldt/ldt/ldt_utils/stat.py	Thu Jan 26 15:04:38 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/stat.py	Thu Jan 26 16:01:12 2012 +0100
@@ -1,68 +1,71 @@
 from django.conf import settings
-from ldt.ldt_utils.models import AnnotationStat, Project
-from django.db.models.signals import pre_delete
-import lxml.etree
+from ldt.ldt_utils.models import Segment
 import datetime
 
-
-def update_stat_project(project, contents=None, doc=None, update_contents=[]):
-
-    if not contents:
-        contents = project.contents.all()
-     
-    if not doc:
-        doc = lxml.etree.fromstring(project.ldt)
+def update_stat_content(content):
+    
+    nb_division = settings.DIVISIONS_FOR_STAT_ANNOTATION
+    
+    segments = Segment.objects.filter(content=content)
+    buckets = [0] * nb_division 
+    
+    size_division = content.duration / nb_division
+    limits = [x * size_division for x in range(nb_division+1)]
+    nb_annotation = len(segments)
 
-    number_division = settings.DIVISIONS_FOR_STAT_ANNOTATION
-    contributions = list(AnnotationStat.objects.filter(project=project))    
+    for segment in segments:
+        
+        begin = segment.start_ts
+        end = segment.start_ts + segment.duration
+        
+        buckets = find_buckets(buckets, limits, begin, end)
+        
+    content.stat_annotation = get_string_from_buckets(buckets)
+    content.nb_annotation = nb_annotation
     
-    for content_node in doc.xpath('/iri/annotations/content'):
-        content_name = content_node.get('id')
-        content = filter_list(contents, 'iri_id', content_name)
-
-        # if the content referenced in the xml belongs to the
-        # fields contents of the project
-        if len(content) != 0:
-            content = content[0]
-            contribution_to_content = filter_list(contributions, 'content', content)[0]
+    content.save()     
+ 
+   
+def update_stat_project(project, contents_only=[]):
+        if project.state != 2:
+            return None
+    
+        if contents_only:
+            contents = contents_only
+        else:
+            contents = project.contents.all()
             
-            size_division = content.duration / number_division
-            limits = [x * size_division for x in range(number_division+1)]
-            buckets = [0] * number_division
-            nb_annotation = 0
-            
+        for c in contents:
+            update_stat_content(c)
             
-            for ann in content_node.xpath('ensemble/decoupage/elements/element'):
-                begin = int(ann.get('begin'))
-                end = int(ann.get('dur')) + begin
-                
-                text = ann.xpath('abstract')[0].text
-                if is_polemic(text):
-                    pass
-                        
-                buckets = find_buckets(buckets, limits, begin, end)
-                nb_annotation += 1        
-           
-            buckets = get_string_from_buckets(buckets)
-             
-            if contribution_to_content.stat != buckets or contribution_to_content.nb_annotation != nb_annotation:
-                contribution_to_content.stat = buckets
-                contribution_to_content.nb_annotation = nb_annotation
-                contribution_to_content.save()
-                update_stat_content(content)
+        return True
+    
+
+def add_annotation_to_stat(content, begin, end):
     
-    for content in update_contents:
-        update_stat_content(content)
-        
-        
+    if not content.nb_annotation or not content.stat_annotation:
+        content.nb_annotation = 1
+        content.stat_annotation = get_empty_stat_vector()
+    
+    buckets = find_buckets(content.stat_annotation, begin, end)
+    content.stat_annotation = get_string_from_buckets(buckets)
+    content.last_annotated = datetime.datetime.now()
+    
+    content.save()        
+    
+
 def get_string_from_buckets(buckets):
     s = "%s" % buckets
     s = s[1:-1].replace(' ', '')
     return s
 
+
 def get_buckets_from_string(string):
     return [int(x) for x in string.split(',')]
 
+def get_empty_stat_vector():
+    return [0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + 4)
+
 
 def find_buckets(buckets, limits, begin, end):
     
@@ -85,89 +88,3 @@
             
     return buckets
 
-def is_polemic(text):
-    if text:
-        polemic_tags = ['++', '--', '==', '??']
-        for tag in polemic_tags:
-            if tag in text:
-                return True
-    return False
-    
-    
-    
-def filter_list(list, criteria, value):
-    new_list = []
-    for l in list:
-        if getattr(l, criteria) == value:
-            new_list.append(l)
-    
-    return new_list
-       
-        
-def delete_stat_project(sender, instance, **kwargs):
-    
-    contents = list(instance.contents.all())
-    contributions = AnnotationStat.objects.filter(project=instance)
-    
-    for c in contributions:
-        result = [x for x in contents if x.id == c.content.id ]
-        if result:
-            content = result[0]
-            
-            if c.nb_annotation:        
-                content.nb_annotation -= c.nb_annotation
-            
-            if c.stat:
-                content_stat = get_buckets_from_string(content.stat_annotation)
-                proj_stat = get_buckets_from_string(c.stat)
-                content.stat_annotation = get_string_from_buckets([pair[0] - pair[1] for pair in zip(content_stat, proj_stat)])
-            
-            content.save()        
-
-pre_delete.connect(delete_stat_project, sender=Project)    
-        
-            
-def update_stat_content(content):
-    all_contributions = AnnotationStat.objects.filter(content=content)
-    content_stat = [0] * settings.DIVISIONS_FOR_STAT_ANNOTATION
-    nb_annotation = 0
-    
-    for project in all_contributions:
-        if project.stat and project.stat != '':
-            project_stat = get_buckets_from_string(project.stat)
-            content_stat = [sum(pair) for pair in zip(content_stat, project_stat)]
-        nb_annotation += project.nb_annotation  
-    
-    content.nb_annotation = nb_annotation
-    content.stat_annotation = get_string_from_buckets(content_stat)
-    content.last_annotated = datetime.datetime.now()
-    content.save()    
-
-
-def add_annotation_to_stat(content, project, begin, end):
-    contribution_project = AnnotationStat.objects.get(project=project, content=content)
-    
-    if not contribution_project.nb_annotation:
-        contribution_project.nb_annotation = 1
-    else:
-        contribution_project.nb_annotation += 1
-    content.nb_annotation += 1
-        
-    if contribution_project.stat:
-        
-        number_division = settings.DIVISIONS_FOR_STAT_ANNOTATION
-        size_division = content.duration / number_division
-        
-        limits = [x * size_division for x in range(number_division+1)]
-        buckets = [0] * number_division        
-        buckets = find_buckets(buckets, limits, begin, end)
-        
-        content_stat = get_buckets_from_string(content.stat_annotation)
-        content.stat_annotation = get_string_from_buckets([pair[0] + pair[1] for pair in zip(content_stat, buckets)])
-        contribution_project.stat = get_string_from_buckets(buckets)  
-
-    content.last_annotated = datetime.datetime.now()
-    content.save()
-    contribution_project.save()
-    
-
--- a/src/ldt/ldt/ldt_utils/views/lignesdetemps.py	Thu Jan 26 15:04:38 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/lignesdetemps.py	Thu Jan 26 16:01:12 2012 +0100
@@ -4,7 +4,7 @@
 from django.http import HttpResponse, HttpResponseRedirect
 from django.shortcuts import render_to_response, get_object_or_404
 from django.template import RequestContext
-from ldt.ldt_utils.models import Content, Project, AnnotationStat
+from ldt.ldt_utils.models import Content, Project
 from ldt.ldt_utils.utils import LdtUtils, LdtSearch, clean_description
 from ldt.security.utils import set_forbidden_stream
 from ldt.ldt_utils.stat import update_stat_project
--- a/src/ldt/ldt/management/commands/statannotation.py	Thu Jan 26 15:04:38 2012 +0100
+++ b/src/ldt/ldt/management/commands/statannotation.py	Thu Jan 26 16:01:12 2012 +0100
@@ -1,23 +1,22 @@
+from django.conf import settings
 from django.core.management.base import BaseCommand
-from ldt.ldt_utils.models import Content, Project
-from ldt.ldt_utils.stat import update_stat_content, update_stat_project
+from ldt.ldt_utils.models import Content
+from ldt.ldt_utils.stat import update_stat_content, get_empty_stat_vector
 
 class Command(BaseCommand):
-    help = 'Computes annotation for all contents and all projects'
+    help = 'Computes annotation for all contents'
     
     
     def handle(self, *args, **options):             
        
-        for proj in Project.objects.all():
-            print "Stat for project %s" % proj
-            update_stat_project(proj)
-        
-        # Sets fields nb_annotation and stat_annotation to 0 and 0,0,...,0
-        # for contents that do not have annotations
-        for content in Content.objects.all():
-            if not content.stat_annotation:
-                print "Stat for content %s" % content
-                update_stat_content(content)
+        size_stat = len(get_empty_stat_vector())
+       
+        for c in Content.objects.all():
+            if len( c.stat_annotation.split(',')) != size_stat:
+                c.stat_annotation = [0] * size_stat
+                c.save()
+            
+            update_stat_content(c)
                   
         return None
     
\ No newline at end of file