# HG changeset patch # User verrierj # Date 1327656472 -3600 # Node ID d1ff0694500b226498ba47b762526da6d4b0887d # Parent a1e9f5e91791844fd161edf70c1e3d8e1edaa8bf Add polemic properties to contents diff -r a1e9f5e91791 -r d1ff0694500b src/ldt/ldt/ldt_utils/contentindexer.py --- a/src/ldt/ldt/ldt_utils/contentindexer.py Thu Jan 26 16:01:12 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/contentindexer.py Fri Jan 27 10:27:52 2012 +0100 @@ -83,6 +83,7 @@ title = reduce_text_node(elementNode, "title/text()") abstract = reduce_text_node(elementNode, "abstract/text()") + polemics = elementNode.xpath('meta/polemics/polemic/text()') author = elementNode.get("author", "") start_ts = int(float(elementNode.get("begin", "-1"))) @@ -120,6 +121,7 @@ date=date_str, project_obj=project, project_id=ldt_id) + seg.polemics = seg.get_polemic(polemics) seg.save() self.writer.addDocument(doc) diff -r a1e9f5e91791 -r d1ff0694500b src/ldt/ldt/ldt_utils/models.py --- a/src/ldt/ldt/ldt_utils/models.py Thu Jan 26 16:01:12 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/models.py Fri Jan 27 10:27:52 2012 +0100 @@ -376,6 +376,68 @@ def get_tags(self): return Tag.objects.get_for_object(self) + 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, + } + + def annotation_volume(): #@NoSelf + + def fget(self): + l = self.str2list(self.stat_annotation) + return l[Content.indices['annotation_volume_begin']:Content.indices['annotation_volume_end']] + + def fset(self, value): # value is a list + l = self.str2list(self.stat_annotation) + l[Content.indices['annotation_volume_begin']:Content.indices['annotation_volume_end']] = value + self.stat_annotation = self.list2str(l) + + return locals() + + annotation_volume = property(**annotation_volume()) + + def polemic_positive(): #@NoSelf + + def fget(self): + l = self.str2list(self.stat_annotation) + return l[Content.indices['pol_positive']] + + def fset(self, value): + l = self.str2list(self.stat_annotation) + l[Content.indices['pol_positive']] = value + self.stat_annotation = self.list2str(l) + + return locals() + + polemic_positive = property(**polemic_positive()) + + + def polemic_negative(): #@NoSelf + + def fget(self): + l = self.str2list(self.stat_annotation) + return l[Content.indices['pol_negative']] + + def fset(self, value): + l = self.str2list(self.stat_annotation) + l[Content.indices['pol_negative']] = value + self.stat_annotation = self.list2str(l) + + return locals() + + polemic_negative = property(**polemic_negative()) + + + + def list2str(self, l): + return ("%s" % l)[1:-1].replace(' ','') + + def str2list(self, s): + return [int(x) for x in s.split(',')] @@ -521,8 +583,8 @@ return True else: return False - - + + class Segment(SafeModel): project_obj = models.ForeignKey(Project, null=True) @@ -541,6 +603,32 @@ abstract = models.TextField(null=True, blank=True) polemics = models.IntegerField(null=True, blank=True, default=0) + + # Mask is 0000, representing OK|KO|Q|REF + mask = { + 'OK': set([8,9,10,11,12,13,14,15]), + 'KO': set([4,5,6,7,12,13,14,15]), + 'Q': set([2,3,6,7,10,11,14,15]), + 'REF': set([1,3,5,7,9,11,13,15]), + } + + def is_polemic(self, polemic_keyword): # OK, KO, Q, REF + if self.polemics in self.mask[polemic_keyword]: + return True + return False + + def get_polemic(self, polemic_keywords): + value = set(range(16)) + + for keyword in self.mask.keys(): + if keyword in polemic_keywords: + value = value.intersection(self.mask[keyword]) + else: + value.difference_update(self.mask[keyword]) + + return value.pop() + + 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))) diff -r a1e9f5e91791 -r d1ff0694500b src/ldt/ldt/ldt_utils/segmentserializer.py --- a/src/ldt/ldt/ldt_utils/segmentserializer.py Thu Jan 26 16:01:12 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/segmentserializer.py Fri Jan 27 10:27:52 2012 +0100 @@ -1,5 +1,4 @@ from django.conf import settings -from django.utils.datastructures import SortedDict from ldt.ldt_utils.models import Project import lxml.etree import uuid diff -r a1e9f5e91791 -r d1ff0694500b src/ldt/ldt/ldt_utils/stat.py --- a/src/ldt/ldt/ldt_utils/stat.py Thu Jan 26 16:01:12 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/stat.py Fri Jan 27 10:27:52 2012 +0100 @@ -12,16 +12,26 @@ size_division = content.duration / nb_division limits = [x * size_division for x in range(nb_division+1)] nb_annotation = len(segments) + + polemic_positive = 0 + polemic_negative = 0 for segment in segments: begin = segment.start_ts end = segment.start_ts + segment.duration + if segment.is_polemic('OK'): + polemic_positive += 1 + if segment.is_polemic('KO'): + polemic_negative += 1 + buckets = find_buckets(buckets, limits, begin, end) - content.stat_annotation = get_string_from_buckets(buckets) + content.annotation_volume = buckets content.nb_annotation = nb_annotation + content.polemic_positive = polemic_positive + content.polemic_negative = polemic_negative content.save() @@ -48,7 +58,7 @@ content.stat_annotation = get_empty_stat_vector() buckets = find_buckets(content.stat_annotation, begin, end) - content.stat_annotation = get_string_from_buckets(buckets) + content.annotation_volume = buckets content.last_annotated = datetime.datetime.now() content.save() @@ -64,7 +74,7 @@ return [int(x) for x in string.split(',')] def get_empty_stat_vector(): - return [0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + 4) + return [0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + 4) # + 4 for polemic syntax def find_buckets(buckets, limits, begin, end): diff -r a1e9f5e91791 -r d1ff0694500b src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html --- a/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html Thu Jan 26 16:01:12 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html Fri Jan 27 10:27:52 2012 +0100 @@ -37,7 +37,7 @@