--- 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<n; i++) {
+ _res += Math.floor(16*Math.random()).toString(16);
+ }
+ return _res;
+ }
+ return _d.getUTCFullYear() + '-'
+ + pad(_d.getUTCMonth()+1) + '-'
+ + pad(_d.getUTCDate()) + '-'
+ + fillrand(16);
+ })(new Date()),
getUID : function() {
- return "autoid-" + (++this._ID_AUTO_INCREMENT);
+ var _n = (++this._ID_AUTO_INCREMENT).toString();
+ while (_n.length < 4) {
+ _n = '0' + _n
+ }
+ return "autoid-" + this._ID_BASE + '-' + _n;
},
regexpFromTextOrArray : function(_textOrArray) {
function escapeText(_text) {
@@ -653,7 +671,7 @@
_res.setTime(Number(time));
return _res;
},
- dateToIso : function(d) {
+ dateToIso : function(d) {
function pad(n){return n<10 ? '0'+n : n}
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
@@ -924,14 +942,11 @@
IriSP.Model.Reference = function(_source, _idRef) {
this.source = _source;
+ this.id = _idRef;
if (typeof _idRef === "object") {
this.isList = true;
- this.id = IriSP._(_idRef).map(function(_id) {
- return _source.getNamespaced(_id).fullname;
- });
} else {
this.isList = false;
- this.id = _source.getNamespaced(_idRef).fullname;
}
this.refresh();
}
@@ -972,8 +987,7 @@
_id = IriSP.Model.getUID();
}
this.source = _source;
- this.namespacedId = _source.getNamespaced(_id)
- this.id = this.namespacedId.fullname;
+ this.id = _id;
this.title = "";
this.description = "";
this.source.directory.addElement(this);
@@ -1113,7 +1127,7 @@
/* */
IriSP.Model.MashedAnnotation = function(_mashup, _annotation) {
- IriSP.Model.Element.call(this, _mashup.namespacedId.name + "_" + _annotation.namespacedId.name, _annotation.source);
+ IriSP.Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source);
this.elementType = 'mashedAnnotation';
this.annotation = _annotation;
this.begin = new IriSP.Model.Time(_mashup.duration);
@@ -1217,54 +1231,10 @@
})
this.callbackQueue = [];
this.contents = {};
- if (typeof this.namespace === "undefined") {
- this.namespace = "metadataplayer";
- } else {
- if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") {
- var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g),
- _url = _matches[0];
- if (_matches.length > 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 )
}
}
}
--- 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}