# HG changeset patch # User hamidouk # Date 1328785777 -3600 # Node ID 7f0a19cf1d3d7b953483c4483f6710f8d3fdfd15 # Parent 0e27f37afd2fd2a73dbae3453f7f741892985735# Parent 96ca8ff7d7cc959300fcb43d7ae54778f001ad77 Merge with upstream diff -r 0e27f37afd2f -r 7f0a19cf1d3d .settings/org.eclipse.core.resources.prefs --- a/.settings/org.eclipse.core.resources.prefs Thu Feb 09 12:09:14 2012 +0100 +++ b/.settings/org.eclipse.core.resources.prefs Thu Feb 09 12:09:37 2012 +0100 @@ -1,4 +1,4 @@ -#Wed Feb 01 17:37:13 CET 2012 +#Tue Feb 07 18:07:06 CET 2012 eclipse.preferences.version=1 encoding//src/ldt/ldt/core/migrations/0001_initial.py=utf-8 encoding//src/ldt/ldt/core/migrations/0002_auto__del_owner.py=utf-8 @@ -11,6 +11,7 @@ encoding//src/ldt/ldt/ldt_utils/migrations/0009_auto__chg_field_content_image__chg_field_project_image.py=utf-8 encoding//src/ldt/ldt/ldt_utils/migrations/0010_auto__add_annotationstat.py=utf-8 encoding//src/ldt/ldt/ldt_utils/migrations/0011_gen_stat_annotation.py=utf-8 +encoding//src/ldt/ldt/ldt_utils/migrations/0015_auto__add_contentstat__del_field_content_last_annotated__del_field_con.py=utf-8 encoding//src/ldt/ldt/management/utils.py=utf-8 encoding//src/ldt/ldt/text/migrations/0001_initial.py=utf-8 encoding//src/ldt/ldt/user/migrations/0001_initial.py=utf-8 diff -r 0e27f37afd2f -r 7f0a19cf1d3d src/ldt/ldt/ldt_utils/migrations/0015_auto__add_contentstat__del_field_content_last_annotated__del_field_con.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ldt/ldt/ldt_utils/migrations/0015_auto__add_contentstat__del_field_content_last_annotated__del_field_con.py Thu Feb 09 12:09:37 2012 +0100 @@ -0,0 +1,173 @@ +# 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): + + # Adding model 'ContentStat' + db.create_table('ldt_utils_contentstat', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('content', self.gf('django.db.models.fields.related.ForeignKey')(related_name='stat_annotation', unique=True, to=orm['ldt_utils.Content'])), + ('annotation_volume_str', self.gf('django.db.models.fields.CommaSeparatedIntegerField')(max_length=1024, null=True, blank=True)), + ('polemics_volume_str', self.gf('django.db.models.fields.CommaSeparatedIntegerField')(max_length=1024, null=True, blank=True)), + ('nb_annotations', self.gf('django.db.models.fields.IntegerField')(default=0, db_index=True)), + ('last_annotated', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, null=True, blank=True)), + )) + db.send_create_signal('ldt_utils', ['ContentStat']) + + # Deleting field 'Content.last_annotated' + db.delete_column('ldt_utils_content', 'last_annotated') + + # Deleting field 'Content.nb_annotation' + db.delete_column('ldt_utils_content', 'nb_annotation') + + # Deleting field 'Content.stat_annotation' + db.delete_column('ldt_utils_content', 'stat_annotation') + + + def backwards(self, orm): + + # Deleting model 'ContentStat' + db.delete_table('ldt_utils_contentstat') + + # Adding field 'Content.last_annotated' + db.add_column('ldt_utils_content', 'last_annotated', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, null=True, blank=True), keep_default=False) + + # Adding field 'Content.nb_annotation' + db.add_column('ldt_utils_content', 'nb_annotation', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True), keep_default=False) + + # Adding field 'Content.stat_annotation' + db.add_column('ldt_utils_content', 'stat_annotation', self.gf('django.db.models.fields.CommaSeparatedIntegerField')(max_length=1024, null=True, blank=True), keep_default=False) + + + 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'161adb97-51ae-11e1-af22-58b035f6b93d'", 'unique': 'True', 'max_length': '1024'}), + 'iriurl': ('django.db.models.fields.CharField', [], {'max_length': '1024'}), + 'media_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['ldt_utils.Media']", '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.contentstat': { + 'Meta': {'object_name': 'ContentStat'}, + 'annotation_volume_str': ('django.db.models.fields.CommaSeparatedIntegerField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}), + 'content': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'stat_annotation'", 'unique': 'True', 'to': "orm['ldt_utils.Content']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_annotated': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'null': 'True', 'blank': 'True'}), + 'nb_annotations': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}), + 'polemics_volume_str': ('django.db.models.fields.CommaSeparatedIntegerField', [], {'max_length': '1024', 'null': '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'] diff -r 0e27f37afd2f -r 7f0a19cf1d3d src/ldt/ldt/ldt_utils/models.py --- a/src/ldt/ldt/ldt_utils/models.py Thu Feb 09 12:09:14 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/models.py Thu Feb 09 12:09:37 2012 +0100 @@ -131,9 +131,6 @@ tags = tagging.fields.TagField(max_length=2048, null=True, blank=True) media_obj = models.ForeignKey('Media', blank=True, null=True) image = ImageField(upload_to=settings.MEDIA_ROOT+"thumbnails/contents/", default=settings.DEFAULT_CONTENT_ICON, max_length=200) - stat_annotation = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content.stat_annotation")) - nb_annotation = models.IntegerField(null=True, blank=True, verbose_name=_('content.nb_annotation')) - last_annotated = models.DateTimeField(default=datetime.datetime.now, verbose_name=_('content.last_annotated'), blank=True, null=True) front_project = models.ForeignKey('Project', null=True, blank=True) class Meta: @@ -222,12 +219,7 @@ if not self.pk: create_front_project = True - - if not self.nb_annotation: - self.nb_annotation = 0 - if not self.stat_annotation: - self.__get_empty_stat() - + super(Content, self).save(*args, **kwargs) @@ -386,76 +378,115 @@ return Tag.objects.get_for_object(self) - __pol_indices = { - 'annotation_volume_begin' : 0, - 'annotation_volume_end' : settings.DIVISIONS_FOR_STAT_ANNOTATION, - 'pol_positive' : settings.DIVISIONS_FOR_STAT_ANNOTATION, - 'pol_negative' : settings.DIVISIONS_FOR_STAT_ANNOTATION + 1, - 'pol_reference' : settings.DIVISIONS_FOR_STAT_ANNOTATION + 2, - 'pol_question' : settings.DIVISIONS_FOR_STAT_ANNOTATION + 3, - } - # add polemic attributes and polemic attribute rates to class Content def __add_polemic_attributes(self): - for element in self.__pol_indices.keys(): + for element in POL_INDICES.keys(): if element.startswith('pol_'): - Content.add_to_class(element, property(self.__make_getter(element), self.__make_setter(element))) + Content.add_to_class(element, property(self.__make_getter(element))) Content.add_to_class("%s_rate" % element, property(self.__make_rate(element))) def __make_getter(self, i): def inner_getter(self): - if not self.stat_annotation: - self.__get_empty_stat() - l = self.__str2list(self.stat_annotation) - return l[Content.__pol_indices[i]] + if self.stat_annotation.count() == 0: + return 0; + else: + contentstate = self.stat_annotation.all()[0] + l = contentstate.polemics_volume + return l[POL_INDICES[i]] return inner_getter - - def __make_setter(self, i): - def inner_setter(self, value): - if not self.stat_annotation: - self.__get_empty_stat() - l = self.__str2list(self.stat_annotation) - l[Content.__pol_indices[i]] = value - self.stat_annotation = self.__list2str(l) - return inner_setter - + def __make_rate(self, i): def inner_rate(self): - if self.nb_annotation <= 0: + if self.stat_annotation.count() == 0 or self.stat_annotation.all()[0].nb_annotation <= 0: return 0 - return int(getattr(self, i) / float(self.nb_annotation) * 100 ) + return int(getattr(self, i) / float(self.stat_annotation.all()[0].nb_annotation) * 100 ) return inner_rate + + def annotation_volume(): #@NoSelf + + def fget(self): + if self.stat_annotation.count() == 0: + contentstate, created = ContentStat.objects.get_or_create(content=self) #@UnusedVariable + else: + contentstate = self.stat_annotation.all()[0] + return contentstate.annotation_volume + + return locals() + + annotation_volume = property(**annotation_volume()) + + + def nb_annotations(): #@NoSelf + def fget(self): + if self.stat_annotation.count() == 0: + return 0 + else: + return self.stat_annotation.all()[0].nb_annotations + + return locals() + + nb_annotations = property(**nb_annotations()) + +POL_INDICES = { + 'pol_positive' : 0, + 'pol_negative' : 1, + 'pol_reference' : 2, + 'pol_question' : 3, +} + + +class ContentStat(models.Model): + + def __init__(self, *args, **kwargs): + super(ContentStat, self).__init__(*args, **kwargs) + self.__init_empty_stat() + + content = models.ForeignKey(Content, blank=False, null=False, related_name='stat_annotation', verbose_name=_("content_stat.content"), unique=True) + annotation_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.annotations_volume")) + polemics_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.polemics_volume")) + nb_annotations = models.IntegerField(null=False, blank=False, verbose_name=_('content.nb_annotation'), default=0, db_index=True) + last_annotated = models.DateTimeField(default=datetime.datetime.now, verbose_name=_('content.last_annotated'), blank=True, null=True) #@UndefinedVariable + + def __init_empty_stat(self): + self.annotation_volume_str = ','.join(['0']*settings.DIVISIONS_FOR_STAT_ANNOTATION) + self.polemics_volume_str = ','.join(['0']*len(settings.SYNTAX.keys())) + self.nb_annotations = 0 + self.last_annotated = None + def __list2str(self, l): - return ("%s" % l)[1:-1].replace(' ','') + return ','.join([str(c) for c in l]) def __str2list(self, s): return [int(x) for x in s.split(',')] - - def __get_empty_stat(self): - self.stat_annotation = self.__list2str([0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + len(settings.SYNTAX.keys()))) - + def annotation_volume(): #@NoSelf def fget(self): - if not self.stat_annotation: - self.__get_empty_stat() - l = self.__str2list(self.stat_annotation) - return l[Content.__pol_indices['annotation_volume_begin']:Content.__pol_indices['annotation_volume_end']] - - def fset(self, value): # value is a list - if not self.stat_annotation: - self.__get_empty_stat() - l = self.__str2list(self.stat_annotation) - l[Content.__pol_indices['annotation_volume_begin']:Content.__pol_indices['annotation_volume_end']] = value - self.stat_annotation = self.__list2str(l) + return self.__str2list(self.annotation_volume_str) + + def fset(self, value): + self.annotation_volume_str = self.__list2str(value) return locals() annotation_volume = property(**annotation_volume()) + + def polemics_volume(): #@NoSelf + + def fget(self): + return self.__str2list(self.polemics_volume_str) + + def fset(self, value): + self.polemics_volume_str = self.__list2str(value) + + return locals() + + polemics_volume = property(**polemics_volume()) + class Project(Document, SafeModel): STATE_CHOICES = ( (1, 'edition'), diff -r 0e27f37afd2f -r 7f0a19cf1d3d src/ldt/ldt/ldt_utils/stat.py --- a/src/ldt/ldt/ldt_utils/stat.py Thu Feb 09 12:09:14 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/stat.py Thu Feb 09 12:09:37 2012 +0100 @@ -1,22 +1,23 @@ -from django.conf import settings -from ldt.ldt_utils.models import Segment +from django.conf import settings #@UnresolvedImport +from ldt.ldt_utils.models import Segment, ContentStat, POL_INDICES import datetime def update_stat_content(content): nb_division = settings.DIVISIONS_FOR_STAT_ANNOTATION - segments = Segment.objects.filter(content=content) + segments = Segment.objects.filter(content=content).select_related(depth=1) #@UndefinedVariable 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) - content.pol_positive = 0 - content.pol_negative = 0 - content.pol_question = 0 - content.pol_reference = 0 + contentstat, created = ContentStat.objects.get_or_create(content=content) + + pol_stats = [0]*len(POL_INDICES) + + min_update_ts = datetime.datetime.min for segment in segments: @@ -24,20 +25,24 @@ end = segment.start_ts + segment.duration if segment.is_polemic('OK'): - content.pol_positive += 1 + pol_stats[POL_INDICES['pol_positive']] += 1 if segment.is_polemic('KO'): - content.pol_negative += 1 + pol_stats[POL_INDICES['pol_negative']] += 1 if segment.is_polemic('Q'): - content.pol_question += 1 + pol_stats[POL_INDICES['pol_question']] += 1 if segment.is_polemic('REF'): - content.pol_reference += 1 + pol_stats[POL_INDICES['pol_reference']] += 1 buckets = find_buckets(buckets, limits, begin, end) - - content.annotation_volume = buckets - content.nb_annotation = nb_annotation + if segment.project_obj.modification_date > min_update_ts: + min_update_ts = segment.project_obj.modification_date - content.save() + contentstat.polemics_volume = pol_stats + contentstat.annotation_volume = buckets + contentstat.nb_annotations = nb_annotation + contentstat.last_annotated = min_update_ts + + contentstat.save() def update_stat_project(project, contents_only=[]): @@ -54,33 +59,20 @@ def add_annotation_to_stat(content, begin, end): nb_division = settings.DIVISIONS_FOR_STAT_ANNOTATION - - if not content.nb_annotation or not content.stat_annotation: - content.nb_annotation = 1 - content.stat_annotation = get_empty_stat_field() size_division = content.duration / nb_division limits = [x * size_division for x in range(nb_division+1)] buckets = find_buckets(content.annotation_volume, limits, begin, end) - content.annotation_volume = buckets - content.last_annotated = datetime.datetime.now() + + contentstat, created = ContentStat.objects.get_or_create(content=content) #@UnusedVariable @UndefinedVariable + contentstat.annotation_volume = buckets + contentstat.last_annotated = datetime.datetime.now() #@UndefinedVariable - content.save() + contentstat.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) # + 4 for polemic syntax - -def get_empty_stat_field(): - return ("%s" % get_empty_stat_vector())[1:-1].replace(' ', '') + return ','.join([str(b) for b in buckets]) def find_buckets(buckets, limits, begin, end): diff -r 0e27f37afd2f -r 7f0a19cf1d3d src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html --- a/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html Thu Feb 09 12:09:14 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html Thu Feb 09 12:09:37 2012 +0100 @@ -55,7 +55,7 @@ {{ content.annotation_volume|list2str }} -
{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}
diff -r 0e27f37afd2f -r 7f0a19cf1d3d src/ldt/ldt/ldt_utils/templates/front/front_group.html --- a/src/ldt/ldt/ldt_utils/templates/front/front_group.html Thu Feb 09 12:09:14 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/front/front_group.html Thu Feb 09 12:09:37 2012 +0100 @@ -24,7 +24,7 @@ {% for content in content_list %}{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}
{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}
@@ -78,7 +78,7 @@ -{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}
diff -r 0e27f37afd2f -r 7f0a19cf1d3d src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html --- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html Thu Feb 09 12:09:14 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html Thu Feb 09 12:09:37 2012 +0100 @@ -124,11 +124,12 @@