# HG changeset patch # User veltr # Date 1339410233 -7200 # Node ID a8cca505882da3e53c53d172e5df35e7e29f2342 # Parent 8eea0d7de41cc92ad27f66b94d2ee3ceb02db813 Modified stats display diff -r 8eea0d7de41c -r a8cca505882d web/tralalere/static/tralalere/metadataplayer/LdtPlayer-core.js --- a/web/tralalere/static/tralalere/metadataplayer/LdtPlayer-core.js Mon Jun 11 01:17:44 2012 +0200 +++ b/web/tralalere/static/tralalere/metadataplayer/LdtPlayer-core.js Mon Jun 11 12:23:53 2012 +0200 @@ -611,8 +611,26 @@ _SOURCE_STATUS_WAITING : 1, _SOURCE_STATUS_READY : 2, _ID_AUTO_INCREMENT : 0, + _ID_BASE : (function(_d) { + function pad(n){return n<10 ? '0'+n : n} + function fillrand(n) { + var _res = '' + for (var i=0; i 1) { - _matches = IriSP._(_matches.slice(1)).reject(function(_txt) { - return /\?$/.test(_txt); - }); - } - if (_matches.length > 0) { - _url += '?' + _matches.join('&'); - } - this.namespaceUrl = _url; - } - } - if (typeof this.namespaceUrl === "undefined") { - this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/"; - } - this.directory.addNamespace(this.namespace, this.namespaceUrl); this.get(); } } -IriSP.Model.Source.prototype.getNamespaced = function(_id) { - var _tab = _id.split(':'); - if (_tab.length > 1) { - return { - namespace : _tab[0], - name : _tab[1], - fullname : _id - } - } else { - return { - namespace : this.namespace, - name : _id, - fullname : this.namespace + ':' + _id - } - } -} - -IriSP.Model.Source.prototype.unNamespace = function(_id) { - if (typeof _id !== "undefined") { - return _id.replace(this.namespace + ':', ''); - } -} - IriSP.Model.Source.prototype.addList = function(_listId, _contents) { if (typeof this.contents[_listId] === "undefined") { this.contents[_listId] = new IriSP.Model.List(this.directory); @@ -1291,7 +1261,7 @@ } IriSP.Model.Source.prototype.getElement = function(_elId) { - return this.directory.getElement(this.getNamespaced(_elId).fullname); + return this.directory.getElement(_elId); } IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { @@ -1306,21 +1276,6 @@ } } -IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) { - var _this = this, - _nsls = [], - _excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf); - this.forEach(function(_list) { - IriSP._(_list).forEach(function(_el) { - var _ns = _el.id.replace(/:.*$/,''); - if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) { - _nsls.push(_ns); - } - }) - }); - return _nsls; -} - IriSP.Model.Source.prototype.get = function() { this.status = IriSP.Model._SOURCE_STATUS_WAITING; this.handleCallbacks(); @@ -1427,11 +1382,6 @@ IriSP.Model.Directory = function() { this.remoteSources = {}; this.elements = {}; - this.namespaces = {}; -} - -IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) { - this.namespaces[_namespace] = _url; } IriSP.Model.Directory.prototype.remoteSource = function(_properties) { @@ -2099,7 +2049,7 @@ }, serializer : function(_data, _source) { return { - id : _source.unNamespace(_data.id), + id : _data.id, url : _data.video, meta : { "dc:title" : _data.title, @@ -2119,7 +2069,7 @@ }, serializer : function(_data, _source) { return { - id : _source.unNamespace(_data.id), + id : _data.id, meta : { "dc:title" : _data.title } @@ -2136,7 +2086,7 @@ }, serializer : function(_data, _source) { return { - id : _source.unNamespace(_data.id), + id : _data.id, "dc:title" : _data.title, "dc:description" : _data.description } @@ -2176,7 +2126,7 @@ }, serializer : function(_data, _source) { return { - id : _source.unNamespace(_data.id), + id : _data.id, begin : _data.begin.milliseconds, end : _data.end.milliseconds, content : { @@ -2184,16 +2134,16 @@ description : _data.description, audio : _data.audio }, - media : _source.unNamespace(_data.media.id), + media : _data.media.id, meta : { - "id-ref" : _source.unNamespace(_data.annotationType.id), + "id-ref" : _data.annotationType.id, "dc:created" : IriSP.Model.dateToIso(_data.created), "dc:creator" : _data.creator, project : _source.projectId }, tags : IriSP._(_data.tag.id).map(function(_id) { return { - "id-ref" : _source.unNamespace(_id) + "id-ref" : _id } }) } @@ -2215,7 +2165,7 @@ "dc:title": _data.title, "dc:description": _data.description, segments: _data.segments.map(function(_annotation) { - return _source.unNamespace(_id); + return _id; }) } } @@ -2278,6 +2228,7 @@ annotation : { serialized_name : "annotations", serializer : function(_data, _source) { + var _annType = _data.getAnnotationType(); return { begin: _data.begin.milliseconds, end: _data.end.milliseconds, @@ -2286,10 +2237,10 @@ audio: _data.audio }, tags: _data.getTagTexts(), - media: _source.unNamespace(_data.getMedia().id), + media: _data.getMedia().id, title: _data.title, - type_title: _data.getAnnotationType().title, - type: ( typeof _data.getAnnotationType().dont_send_id !== "undefined" && _data.getAnnotationType().dont_send_id ? "" : _source.unNamespace(_data.getAnnotationType().id) ) + type_title: _annType.title, + type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ) } } } diff -r 8eea0d7de41c -r a8cca505882d web/tralalere/views.py --- a/web/tralalere/views.py Mon Jun 11 01:17:44 2012 +0200 +++ b/web/tralalere/views.py Mon Jun 11 12:23:53 2012 +0200 @@ -7,7 +7,6 @@ COLORS = ['red', 'yellow', 'green', 'blue'] EMOTICONS = ['happy','unhappy','laughing','surprised'] -SCALES = [0.2,0.5,0.8,1] def home(request): @@ -15,9 +14,11 @@ contents = Content.objects.filter(front_project__state = 2) tags_stats = {} - + nb_segments = 0 for segment in Segment.objects.filter(content__in = contents): + nb_segments += 1 c_tags = tags_stats.setdefault(segment.iri_id,{}) + for t in segment.tags.split(";"): t = t.strip().lower() if t: @@ -26,27 +27,58 @@ c_tags['colors'] = c_tags.setdefault('colors',0) + 1 if t in EMOTICONS: c_tags['emoticons'] = c_tags.setdefault('emoticons',0) + 1 - tags = {} + tags = {} + for contentid, c_tags in tags_stats.iteritems(): emoticons_stats = [] + tag_max = 0.0 + tag_sum = 0.0 + for t in EMOTICONS: if t in c_tags: - score = float(c_tags[t])/float(c_tags['emoticons']) - cat = int(len(EMOTICONS)*score) - scale = SCALES[cat] - width = int(50*scale) - emoticons_stats.append({'tag':t, 'score': score, 'cat':cat, 'scale': scale, 'width':width}) + tag_sqrt = math.sqrt(c_tags[t]) + tag_max = max(tag_max, tag_sqrt) + tag_sum += tag_sqrt + if tag_max: + tag_factor = 1.0 / tag_max + if tag_sum * tag_factor > 2.8: + tag_factor = tag_factor * 2.8 / ( tag_sum * tag_factor ) + + for t in EMOTICONS: + if t in c_tags: + score = c_tags[t] + tag_sqrt = math.sqrt(score) + scale = tag_sqrt * tag_factor + width = int(50*scale) + emoticons_stats.append({'tag':t, 'score': score, 'scale': scale, 'width':width}) + emoticons_stats.sort(key=operator.itemgetter('score','tag'), reverse=True) colors_stats = [] + tag_max = 0.0 + tag_sum = 0.0 + for t in COLORS: if t in c_tags: - score = float(c_tags[t])/float(c_tags['colors']) - cat = int(len(COLORS)*score) - scale = SCALES[cat] - width = int(50*scale) - colors_stats.append({'tag':t, 'score': score, 'cat':cat, 'scale': scale, 'width':width}) + tag_sqrt = math.sqrt(c_tags[t]) + tag_max = max(tag_max, tag_sqrt) + tag_sum += tag_sqrt + if tag_max: + tag_factor = 1.0 / tag_max + if tag_sum * tag_factor > 2.8: + tag_factor = tag_factor * 2.8 / ( tag_sum * tag_factor ) + + for t in COLORS: + if t in c_tags: + score = c_tags[t] + tag_sqrt = math.sqrt(score) + scale = tag_sqrt * tag_factor + width = int(50*scale) + colors_stats.append({'tag':t, 'score': score, 'scale': scale, 'width':width}) + colors_stats.sort(key=operator.itemgetter('score','tag'), reverse=True) + + tags[contentid] = {'emoticons': emoticons_stats, 'colors': colors_stats}