5
|
1 |
var topicPoubelle = 13; |
|
2 |
|
|
3 |
var adjust = 54; |
|
4 |
|
|
5 |
var deltaT = new Date("Wed, 02 May 2012 19:00:00 +0000") / 1000 + adjust; |
|
6 |
|
|
7 |
function solrUrl(table, params) { |
|
8 |
return "http://159.217.144.101:8050/sia-solr/" + table + "/select?" + $.param(params) + "&wt=json&json.wrf=?"; |
|
9 |
} |
|
10 |
|
|
11 |
function showData() { |
|
12 |
|
7
|
13 |
var topicHash = document.location.hash || "#selectedtopics=5,15&visibletopics=5,10,15"; |
|
14 |
|
|
15 |
var pageParams = {}; |
|
16 |
|
11
|
17 |
var syncVideo = true, |
|
18 |
syncTimer; |
|
19 |
|
|
20 |
function deSync() { |
|
21 |
syncVideo = false; |
|
22 |
clearTimeout(syncTimer); |
|
23 |
syncTimer = setTimeout(function() { |
|
24 |
syncVideo = true; |
|
25 |
},5000); |
|
26 |
} |
|
27 |
|
7
|
28 |
topicHash |
|
29 |
.replace(/^#/,'') |
|
30 |
.split('&') |
|
31 |
.forEach(function(p) { |
|
32 |
var s = p.split('='); |
|
33 |
pageParams[s[0]] = s[1].split(",").map(function(t) { return decodeURIComponent(t)}); |
|
34 |
}) |
5
|
35 |
|
|
36 |
var ordertag = 0; |
|
37 |
|
|
38 |
function secsToString(seconds) { |
|
39 |
var hours = Math.floor(seconds/3600), |
|
40 |
minutes = Math.floor(seconds/60) % 60, |
|
41 |
secs = Math.floor(seconds % 60); |
|
42 |
function pad(n) { |
|
43 |
var r = n.toString(); |
|
44 |
while (r.length < 2) { |
|
45 |
r = "0" + r; |
|
46 |
} |
|
47 |
return r; |
|
48 |
} |
|
49 |
return (hours ? (hours + ":") : "") + pad(minutes) + ":" + pad(secs); |
|
50 |
} |
|
51 |
|
|
52 |
$(".duration").text(secsToString(data.duration)); |
|
53 |
|
|
54 |
var nmmso = data.segments.length; |
|
55 |
|
|
56 |
data.topics.forEach(function(topic) { |
|
57 |
topic.score = 0; |
|
58 |
topic.weights = []; |
|
59 |
for (var i = 0; i < nmmso; i++) { |
|
60 |
topic.weights.push(0); |
|
61 |
} |
|
62 |
}); |
|
63 |
|
|
64 |
data.segments.forEach(function(mmso, i) { |
|
65 |
mmso.topics.forEach(function(t) { |
|
66 |
data.topics[t.topic].weights[i] = t.weight; |
|
67 |
data.topics[t.topic].score += t.weight; |
|
68 |
}); |
|
69 |
}); |
|
70 |
|
|
71 |
var sortedTopics = data.topics.filter(function(t) { |
7
|
72 |
return pageParams.visibletopics.indexOf(t.index.toString()) !==-1 && t.index !== topicPoubelle; |
5
|
73 |
}); |
|
74 |
|
11
|
75 |
function hasTopics(mmso, topics) { |
|
76 |
for (var j = 0; j < mmso.topics.length; j++) { |
|
77 |
if (topics.indexOf(mmso.topics[j].topic) !== -1) { |
|
78 |
return true; |
|
79 |
} |
|
80 |
} |
|
81 |
return false; |
|
82 |
} |
|
83 |
|
|
84 |
function checkOrGoNext() { |
|
85 |
var topics = Array.prototype.slice.call( |
|
86 |
$(".topic.selected").map(function() { |
|
87 |
return parseInt($(this).attr("data-topic-id")) |
|
88 |
}) |
|
89 |
); |
|
90 |
var currentMmso = _(data.segments).find(function(s) { |
|
91 |
return s.start <= player.currentTime && s.end > player.currentTime; |
|
92 |
}); |
|
93 |
|
|
94 |
if (hasTopics(currentMmso, topics)) { |
|
95 |
throttledShowLocal(); |
|
96 |
} else { |
|
97 |
goToNext(); |
|
98 |
} |
|
99 |
|
|
100 |
} |
5
|
101 |
|
9
|
102 |
function goToNext() { |
11
|
103 |
var topics = Array.prototype.slice.call( |
|
104 |
$(".topic.selected").map(function() { |
|
105 |
return parseInt($(this).attr("data-topic-id")); |
|
106 |
}) |
|
107 |
); |
9
|
108 |
for (var i = 0; i < data.segments.length; i++) { |
|
109 |
var mmso = data.segments[i]; |
11
|
110 |
if (mmso.start >= player.currentTime && hasTopics(mmso, topics)) { |
|
111 |
player.setCurrentTime(mmso.start); |
|
112 |
throttledShowLocal(); |
|
113 |
return; |
9
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
|
5
|
118 |
function showTopics(topiclist) { |
|
119 |
var tbhtml = topiclist.reduce(function(mem, topic) { |
|
120 |
var wordsToShow = topic.words.slice(0,3), |
|
121 |
max = wordsToShow[0].weight, |
|
122 |
min = Math.min(wordsToShow[wordsToShow.length - 1].weight, max - .01), |
|
123 |
scale = 8 / (max - min); |
|
124 |
var li = '<li class="shadow-block topic" data-topic-id="' |
|
125 |
+ topic.index |
|
126 |
+ '" data-timestamp="999999"><ul class="topic-words">' |
|
127 |
+ wordsToShow.reduce(function(memwords, word) { |
|
128 |
return memwords |
|
129 |
+ '<li style="font-size: ' |
|
130 |
+ ( 8 + scale * (word.weight - min) ) |
|
131 |
+ 'px;">' |
|
132 |
+ word.word |
|
133 |
+ '</li>'; |
|
134 |
},"") |
|
135 |
+ '</ul></li>'; |
|
136 |
return mem + li; |
|
137 |
},''); |
|
138 |
var tb = $(".topics-block"); |
|
139 |
tb.html(tbhtml); |
|
140 |
tb.css("top",0); |
|
141 |
|
|
142 |
showTopicViz(); |
|
143 |
} |
|
144 |
|
|
145 |
var tweetLines = []; |
|
146 |
|
|
147 |
function showTopicViz() { |
|
148 |
var selectedBlocks = $(".topic.selected, .topic.hover"), |
|
149 |
sbl = selectedBlocks.length, |
|
150 |
topicBlocks = $(".topic"); |
|
151 |
if (!sbl && topicBlocks.length < sortedTopics.length) { |
|
152 |
selectedBlocks = topicBlocks; |
|
153 |
sbl = selectedBlocks.length; |
|
154 |
} |
|
155 |
var topicsAndColors = [], |
|
156 |
colors = {}; |
|
157 |
selectedBlocks.each(function() { |
|
158 |
var el = $(this), |
|
159 |
topicid = parseInt(el.attr("data-topic-id")); |
|
160 |
topicsAndColors.push({ |
|
161 |
"$": el, |
|
162 |
timestamp: parseInt(el.attr("data-timestamp")), |
|
163 |
hovered: el.hasClass("hover"), |
|
164 |
id: topicid, |
|
165 |
topic: data.topics[topicid] |
|
166 |
}); |
|
167 |
}); |
|
168 |
topicsAndColors.sort(function(a,b) { |
|
169 |
return ( a.timestamp - b.timestamp ) || ( a.id - b.id ); |
|
170 |
}); |
|
171 |
topicBlocks.css("background",""); |
|
172 |
topicsAndColors.forEach(function(topic, i) { |
|
173 |
topic.color = topic.hovered ? "#ffff00" : colorset[i % colorset.length]; |
|
174 |
colors[topic.id] = topic.color; |
|
175 |
topic.$.css("background", topic.color); |
|
176 |
}); |
|
177 |
|
|
178 |
for (var i = 0; i < nmmso; i++) { |
|
179 |
var opacity = 0, |
|
180 |
rgb = [0,0,0]; |
|
181 |
topicsAndColors.forEach(function(topic) { |
|
182 |
var c = Raphael.getRGB(topic.color), |
|
183 |
o = topic.topic.weights[i]; |
|
184 |
rgb[0] += c.r * o; |
|
185 |
rgb[1] += c.g * o; |
|
186 |
rgb[2] += c.b * o; |
|
187 |
opacity += o; |
|
188 |
}); |
|
189 |
if (opacity) { |
|
190 |
color = Raphael.rgb.apply(Raphael, rgb.map(function(c) { |
|
191 |
return c/opacity; |
|
192 |
})); |
|
193 |
var attr = { |
|
194 |
fill: color, |
|
195 |
opacity: .5 + .5 * opacity |
|
196 |
}; |
|
197 |
segmentrects[i].show(); |
|
198 |
segmentrects[i].attr(attr); |
|
199 |
if (i >= localMmsoDelta && i < localMmsoDelta + localMmsos.length) { |
|
200 |
localMmsos[i - localMmsoDelta].show(); |
|
201 |
localMmsos[i - localMmsoDelta].attr(attr); |
|
202 |
} |
|
203 |
} else { |
|
204 |
segmentrects[i].hide(); |
|
205 |
if (i >= localMmsoDelta && i < localMmsoDelta + localMmsos.length) { |
|
206 |
localMmsos[i - localMmsoDelta].hide(); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
tweetLines.forEach(function(tl) { tl.remove(); }); |
|
212 |
tweetLines = []; |
|
213 |
|
11
|
214 |
var deltaY = $(".play-bottom").offset().top; |
5
|
215 |
|
6
|
216 |
$(".play-localtweets .tweet:visible").each(function() { |
5
|
217 |
var el = $(this), |
|
218 |
liY = + el.offset().top + el.outerHeight() / 2 - deltaY, |
|
219 |
tY = localyscale * (+el.attr("data-timestamp") - localpos + localduration / 2), |
6
|
220 |
p = "M" + localL + "," + tY + "L" + localR + "," + tY + "L400," + liY, |
5
|
221 |
path = paper.path(p); |
|
222 |
$(this).css("background",colors[el.attr("data-topic-id")] || ""); |
|
223 |
path.attr({ |
|
224 |
stroke: "#ccc" |
|
225 |
}); |
|
226 |
tweetLines.push(path); |
|
227 |
}); |
|
228 |
|
|
229 |
} |
|
230 |
|
|
231 |
var jqsvg = $(".play-svg"), |
|
232 |
paper = new Raphael(jqsvg[0]), |
|
233 |
totalR = jqsvg.width(), |
|
234 |
ph = jqsvg.height(), |
|
235 |
globW = 85, |
|
236 |
globL = 40, |
7
|
237 |
entonnoirR = 155, |
|
238 |
localL = 235, |
5
|
239 |
localW = 85, |
|
240 |
localR = (localL + localW), |
|
241 |
localTimeR = (localL + localW) + globL, |
|
242 |
globR = (globW + globL), |
|
243 |
yscale = ph / data.duration, |
|
244 |
mx = Math.max.apply(Math, data.minutes.map(function(s) { return s.count})), |
|
245 |
xscale = globW/mx; |
|
246 |
var segmentrects = data.segments.map(function(mmso) { |
|
247 |
var rect = paper.rect(globL, yscale * mmso.start, globW, yscale * mmso.duration); |
|
248 |
rect.attr({stroke: "none"}); |
|
249 |
return rect; |
|
250 |
}); |
|
251 |
|
|
252 |
var d = "M" + data.minutes.map(function(s) { |
|
253 |
var x = globL + xscale * s.count; |
|
254 |
return x |
|
255 |
+ "," |
|
256 |
+ yscale * (s.from + 20) |
|
257 |
+ "L" |
|
258 |
+ x |
|
259 |
+ "," |
|
260 |
+ yscale * (s.from + 40); |
|
261 |
}).join("L"); |
|
262 |
|
|
263 |
paper.path(d).attr({ |
|
264 |
"stroke-width": 4, |
|
265 |
"stroke": "#000000", |
|
266 |
opacity: .5 |
|
267 |
}); |
|
268 |
paper.path(d).attr({ |
|
269 |
"stroke-width": 1, |
|
270 |
"stroke": "#ffffff" |
|
271 |
}); |
|
272 |
|
|
273 |
for (var i=0; i < data.duration; i += 1800) { |
|
274 |
var y = yscale * i; |
|
275 |
paper.path("M0" + "," + y + "l" + globR + ",0").attr({stroke: "#666"}); |
|
276 |
paper.text(0, y + 6, secsToString(i)).attr({ |
|
277 |
"text-anchor": "start", |
|
278 |
"fill": "#ffffff" |
|
279 |
}); |
|
280 |
} |
|
281 |
paper.text(0, ph-8, secsToString(data.duration)).attr({ |
|
282 |
"text-anchor": "start", |
|
283 |
"fill": "#ffffff" |
|
284 |
}); |
|
285 |
paper.path("M0" + globR + ",0L" + localTimeR + ",0" ).attr({stroke: "#666"}); |
|
286 |
paper.path("M0," + (ph-1) + "l" + localTimeR + ",0" ).attr({stroke: "#666"}); |
|
287 |
|
|
288 |
paper.path("M" + globR + ",0l0," + ph).attr({stroke: "#666"}); |
|
289 |
paper.path("M" + localL + ",0l0," + ph).attr({stroke: "#666"}); |
|
290 |
|
|
291 |
var entonnoir = paper.path("").attr("fill","#333"), |
|
292 |
localStartText = paper.text(localTimeR,6,"").attr({ |
|
293 |
"text-anchor": "end", |
|
294 |
"fill": "#ffffff" |
|
295 |
}), |
|
296 |
localEndText = paper.text(localTimeR,ph - 8, "").attr({ |
|
297 |
"text-anchor": "end", |
|
298 |
"fill": "#ffffff" |
|
299 |
}), |
|
300 |
localTimes = [], |
|
301 |
localMmsos = [], |
|
302 |
localMmsoDelta, |
|
303 |
mmsoAlt = [], |
|
304 |
lowerFiveSecs, |
|
305 |
higherFiveSecs, |
|
306 |
localyscale; |
|
307 |
|
|
308 |
entonnoir.toBack(); |
|
309 |
|
9
|
310 |
var cloudTemplate = _.template('<li style="font-size: <%- size %>px;"<% if (selected) {%> class="selected"<% } %>><%- word %></li>'); |
7
|
311 |
|
11
|
312 |
var globalIndic = $(".global-position"), |
|
313 |
localIndic = $(".local-position"), |
|
314 |
playTime = $(".current-time"); |
|
315 |
|
5
|
316 |
function showLocal() { |
|
317 |
localyscale = ph / localduration; |
|
318 |
var localstart = localpos - localduration/2; |
|
319 |
localend = localpos + localduration/2; |
|
320 |
globtop = yscale * localstart, |
|
321 |
globbottom = yscale * localend, |
7
|
322 |
betweenx = (globR + entonnoirR) / 2, |
5
|
323 |
betweenyt = (globtop) / 2, |
|
324 |
betweenyb = (globbottom + ph) / 2, |
7
|
325 |
curve = (entonnoirR - globR) / 2, |
5
|
326 |
entonnoird = "M0," + globtop + "l" + globR + ",0Q" + betweenx + "," + globtop + "," + betweenx + "," |
|
327 |
+ Math.max(globtop - curve, betweenyt) + "L" + betweenx + "," + Math.min(curve, betweenyt) + "Q" |
7
|
328 |
+ betweenx + ",0," + entonnoirR + ",0" |
|
329 |
+ "L" + localR + ",0L" + localR + "," + ph + "L" + entonnoirR + "," + ph + "Q" + betweenx + "," + ph + "," |
5
|
330 |
+ betweenx + "," + Math.max(ph - curve, betweenyb) +"L" + betweenx + "," + Math.min(globbottom + curve, betweenyb) |
7
|
331 |
+ "Q" + betweenx + "," + globbottom + "," + globR + "," + globbottom + "L0," + globbottom, |
|
332 |
localkeywords = {}; |
5
|
333 |
|
|
334 |
entonnoir.attr("path",entonnoird); |
11
|
335 |
localIndic.css("top",(player.currentTime - localstart) * localyscale); |
5
|
336 |
localTimes.forEach(function(t) { |
|
337 |
t.text.remove(); |
|
338 |
t.line.remove(); |
|
339 |
}); |
|
340 |
localMmsos.forEach(function(t) { |
|
341 |
t.remove(); |
|
342 |
}); |
|
343 |
mmsoAlt.forEach(function(t) { |
|
344 |
t.remove(); |
|
345 |
}); |
|
346 |
var filteredSegments = data.segments.filter(function(s) { |
|
347 |
return s.start < localend && s.end > localstart; |
|
348 |
}); |
|
349 |
localMmsoDelta = parseInt(filteredSegments[0].id.split("_")[1]); |
|
350 |
localMmsos = filteredSegments.map(function(s) { |
|
351 |
var y = localyscale * (s.start - localstart), |
7
|
352 |
h = localyscale * s.duration, |
|
353 |
rect = paper.rect( localL, y, localW, h ), |
|
354 |
visibled = ( |
|
355 |
s.start < localstart |
|
356 |
? s.duration - localstart + s.start |
|
357 |
: ( |
|
358 |
s.end > localend |
|
359 |
? s.duration - s.end + localend |
|
360 |
: s.duration |
|
361 |
) |
|
362 |
); |
|
363 |
_(s.keywords).each(function(v,k) { |
|
364 |
localkeywords[k] = (v * visibled) + (localkeywords[k] || 0); |
|
365 |
}); |
5
|
366 |
rect.attr({stroke: "none", title: s.id}); |
|
367 |
if (parseInt(s.id.replace("MMSO_","")) % 2) { |
6
|
368 |
var altrect = paper.rect( localR, y, 60, h); |
5
|
369 |
altrect.attr({stroke: "none", fill: "#222"}); |
|
370 |
mmsoAlt.push(altrect); |
|
371 |
} |
|
372 |
return rect; |
|
373 |
}); |
|
374 |
localStartText.attr("text", secsToString(localstart)).toFront(); |
|
375 |
localEndText.attr("text", secsToString(localend)).toFront(); |
|
376 |
for ( var i = (1 + Math.floor(localstart / 120)) * 120; i < localend; i += 120 ) { |
|
377 |
var y = localyscale*(i - localstart) |
|
378 |
localTimes.push({ |
|
379 |
text: paper.text(localTimeR,6+y,secsToString(i)).attr({ |
|
380 |
"text-anchor": "end", |
|
381 |
"fill": "#ffffff" |
|
382 |
}), |
|
383 |
line: paper.path("M0" + localL + "," + y + "L" + localTimeR + "," + y).attr({stroke: "#666"}) |
|
384 |
}); |
|
385 |
} |
|
386 |
if (lowerFiveSecs) { |
|
387 |
lowerFiveSecs.remove(); |
|
388 |
} |
|
389 |
if (higherFiveSecs) { |
|
390 |
higherFiveSecs.remove(); |
|
391 |
} |
|
392 |
var filteredFiveSecs = data.fiveseconds.slice(Math.floor(localstart / 5), Math.ceil(localend / 5)); |
|
393 |
var counts = filteredFiveSecs.map(function(s) { return s.count}), |
|
394 |
lmx = Math.max.apply(Math, counts), |
|
395 |
lmi = Math.min.apply(Math, counts.concat([lmx - 1])) |
|
396 |
lxscale = localW/(lmx-lmi); |
|
397 |
|
|
398 |
var d = "M" + filteredFiveSecs.map(function(s) { |
|
399 |
var x = localL + lxscale * (s.count - lmi); |
|
400 |
return x |
|
401 |
+ "," |
|
402 |
+ localyscale * (s.from + 1 - localstart) |
|
403 |
+ "L" |
|
404 |
+ x |
|
405 |
+ "," |
|
406 |
+ localyscale * (s.from + 4 - localstart); |
|
407 |
}).join("L"); |
|
408 |
|
|
409 |
lowerFiveSecs = paper.path(d).attr({ |
|
410 |
"stroke-width": 4, |
|
411 |
"stroke": "#000000", |
|
412 |
opacity: .5 |
|
413 |
}); |
|
414 |
higherFiveSecs = paper.path(d).attr({ |
|
415 |
"stroke-width": 1, |
|
416 |
"stroke": "#ffffff" |
|
417 |
}); |
6
|
418 |
|
|
419 |
var imghtm = '', imgrate = localduration / 12, imgstart = imgrate * Math.floor(localstart / imgrate), imgend = imgrate * Math.ceil(localend / imgrate); |
|
420 |
for (var i = imgstart; i <= imgend; i+= imgrate) { |
|
421 |
var imgsrc = i + '.png'; |
|
422 |
while (imgsrc.length < 9) { |
|
423 |
imgsrc = '0' + imgsrc; |
|
424 |
} |
|
425 |
var imgy = Math.floor( localyscale * (i - localstart) - 22.5 ) |
|
426 |
imghtm += '<img src="thumbnails/' + imgsrc + '" style="top: ' + imgy +'px;" />'; |
|
427 |
} |
|
428 |
$(".play-images").html(imghtm); |
|
429 |
|
|
430 |
$(".play-localtweets .tweet").each(function() { |
|
431 |
var el = $(this), |
|
432 |
t = parseInt(el.attr("data-timestamp")); |
|
433 |
if (t > localstart && t < localend) { |
|
434 |
el.show(); |
|
435 |
} else { |
|
436 |
el.hide(); |
|
437 |
} |
|
438 |
}); |
|
439 |
|
7
|
440 |
localkeywords = _(localkeywords) |
|
441 |
.chain() |
|
442 |
.map(function(v,k) { |
|
443 |
return { word: k, score: v } |
|
444 |
}) |
|
445 |
.sortBy(function(w) { |
|
446 |
return -w.score; |
|
447 |
}) |
9
|
448 |
.first(40) |
7
|
449 |
.value(); |
|
450 |
|
|
451 |
var values = _(localkeywords).pluck('score'), |
|
452 |
max = Math.max.apply(Math, values), |
|
453 |
min = Math.min.apply(Math, values), |
9
|
454 |
scale = 10 / (max - Math.min(max - .1, min)), |
|
455 |
selectedVisible = false; |
7
|
456 |
|
|
457 |
localkeywords.forEach(function(w) { |
|
458 |
w.size = 10 + (w.score - min) * scale; |
9
|
459 |
w.selected = (w.word === selectedWord); |
|
460 |
selectedVisible = selectedVisible || w.selected; |
7
|
461 |
}); |
|
462 |
|
9
|
463 |
if (!selectedVisible) { |
|
464 |
selectedWord = false; |
|
465 |
} |
|
466 |
|
7
|
467 |
$(".play-tagcloud").html(localkeywords.map(cloudTemplate).join("")); |
|
468 |
|
6
|
469 |
throttledGetTweets(); |
|
470 |
|
5
|
471 |
showTopicViz(); |
|
472 |
} |
|
473 |
|
9
|
474 |
$(".play-tagcloud").on("click","li", function() { |
|
475 |
if ($(this).hasClass("selected")) { |
|
476 |
selectedWord = false; |
|
477 |
} else { |
|
478 |
selectedWord = $(this).text(); |
|
479 |
} |
|
480 |
throttledShowLocal(); |
|
481 |
}); |
|
482 |
|
5
|
483 |
|
|
484 |
var lastPos, lastDuration, lastTopics; |
|
485 |
|
9
|
486 |
var tweetTemplate = _.template('<li class="tweet" data-timestamp="<%= timestamp %>" data-topic-id="<%= topic.topic %>"><img src="<%- data.profile_image_url %>" /><p>@<%- data.from_user_name %>: <%= data.htext %></p></li>'), |
6
|
487 |
callnum = 0, |
|
488 |
tweetstructure = {}, |
|
489 |
requestedtweets = {}, |
11
|
490 |
_NTWEETS = 50, |
9
|
491 |
selectedWord = false; |
5
|
492 |
|
6
|
493 |
function showTweets() { |
|
494 |
|
|
495 |
var toshow = []; |
|
496 |
var topics = Array.prototype.join.call($(".topic.selected").map(function(){return $(this).attr("data-topic-id")})).split(","); |
|
497 |
|
|
498 |
for (var i = 0; i < localMmsos.length; i++) { |
|
499 |
var mmso = data.segments[localMmsoDelta + i]; |
|
500 |
var mmsostruct = tweetstructure[mmso.id]; |
|
501 |
if (mmsostruct) { |
|
502 |
for (var j = 0; j < topics.length; j++) { |
|
503 |
var topicid = topics[j]; |
7
|
504 |
if (mmsostruct.tweetids) { |
|
505 |
var tweetids = mmsostruct.tweetids[topicid]; |
6
|
506 |
for (var k = 0; k < tweetids.length; k++) { |
|
507 |
toshow.push(tweetids[k]); |
|
508 |
} |
|
509 |
} |
|
510 |
} |
|
511 |
} |
5
|
512 |
} |
6
|
513 |
toshow = _(toshow).uniq(); |
|
514 |
|
|
515 |
var tweetstoshow = toshow.map(function(tid) { |
|
516 |
return requestedtweets[tid]; |
|
517 |
}).filter(function(tw) { |
|
518 |
return ((tw.status == 2) && (tw.timestamp > (localpos - localduration / 2)) && (tw.timestamp < (localpos + localduration / 2))); |
|
519 |
}); |
9
|
520 |
|
|
521 |
if (selectedWord) { |
|
522 |
var rx = new RegExp(selectedWord.replace(/(\W)/gm,'\\$1'),'im'); |
|
523 |
tweetstoshow = tweetstoshow.filter(function(tw) { |
|
524 |
return rx.test(tw.data.text); |
|
525 |
}); |
|
526 |
} |
6
|
527 |
|
|
528 |
tweetstoshow.forEach(function(tw) { |
|
529 |
tw.topic = tw.topics.filter(function(t) { |
7
|
530 |
return topics.indexOf(t.topic.toString()) !== -1; |
6
|
531 |
}).sort(function(a,b) { |
|
532 |
return b.weight - a.weight |
|
533 |
})[0]; |
|
534 |
}); |
7
|
535 |
|
|
536 |
tweetstoshow = tweetstoshow.filter(function(t) { |
|
537 |
return !!t.topic; |
9
|
538 |
}); |
6
|
539 |
|
|
540 |
tweetstoshow.sort(function(a, b) { |
|
541 |
return b.topic.weight - a.topic.weight; |
|
542 |
}); |
|
543 |
|
|
544 |
tweetstoshow = tweetstoshow.slice(0,10); |
|
545 |
|
9
|
546 |
if (selectedWord) { |
|
547 |
var rx = new RegExp( '(' + selectedWord.replace(/(\W)/gm,'\\$1') + ')', 'gim' ); |
|
548 |
tweetstoshow.forEach(function(tw) { |
|
549 |
tw.data.htext = _(tw.data.text).escape().replace(rx,'<span class="highlight">$1</span>'); |
|
550 |
}); |
|
551 |
} else { |
|
552 |
tweetstoshow.forEach(function(tw) { |
|
553 |
tw.data.htext = _(tw.data.text).escape(); |
|
554 |
}) |
|
555 |
} |
|
556 |
|
6
|
557 |
tweetstoshow.sort(function(a, b) { |
|
558 |
return a.timestamp - b.timestamp; |
|
559 |
}); |
|
560 |
|
|
561 |
var html = tweetstoshow.map(tweetTemplate).join(""); |
|
562 |
|
|
563 |
$(".play-localtweets").html(html); |
|
564 |
var h = 0; |
|
565 |
$(".play-localtweets .tweet").each(function() { |
|
566 |
h += $(this).outerHeight(); |
|
567 |
}); |
|
568 |
$(".play-localtweets .tweet").css("margin-top",Math.max(0,($(".play-bottom").height() - h)/(tweetstoshow.length+1))); |
|
569 |
showTopicViz(); |
|
570 |
|
|
571 |
} |
|
572 |
|
|
573 |
function getMmsoTweetIds(mmstruct) { |
7
|
574 |
TopicsBean.bestSocialInteractionsIdsMatching(mmstruct.mmsoid, 0, _NTWEETS, { |
|
575 |
callback: function(res) { |
6
|
576 |
mmstruct.status = 2; |
7
|
577 |
mmstruct.tweetids = res; |
|
578 |
for (var j = 0; j < res.length; j++) { |
|
579 |
var tweetids = res[j], |
|
580 |
ntw = tweetids.length, |
|
581 |
topicweight = data.topics[j].weights[mmstruct.mmsoindex]; |
|
582 |
for (var k = 0; k < tweetids.length; k++) { |
|
583 |
var relevance = topicweight * (ntw - k) / ntw, |
|
584 |
tweetid = tweetids[k]; |
|
585 |
if (!requestedtweets[tweetid]) { |
|
586 |
requestedtweets[tweetid] = { |
|
587 |
id: tweetid, |
|
588 |
status: 0, |
|
589 |
topics: [] |
|
590 |
} |
6
|
591 |
} |
7
|
592 |
requestedtweets[tweetid].topics.push({ |
|
593 |
topic: j, |
|
594 |
weight: relevance |
|
595 |
}); |
6
|
596 |
} |
|
597 |
} |
|
598 |
debouncedGetTweetData(); |
|
599 |
}, |
7
|
600 |
errorHandler: function(err,info) { |
6
|
601 |
mmstruct.status = 0; |
7
|
602 |
console.error(err,info); |
9
|
603 |
debouncedGetTweetIds(); |
6
|
604 |
} |
|
605 |
}); |
|
606 |
} |
|
607 |
|
|
608 |
var _MAX_BATCH = 20; |
|
609 |
|
|
610 |
function getTweetIds() { |
|
611 |
|
|
612 |
console.log("getTweetIds"); |
|
613 |
|
|
614 |
var toload = []; |
5
|
615 |
|
7
|
616 |
_(tweetstructure).each(function(w) { |
|
617 |
if (!w.status) { |
|
618 |
w.status = 1; |
|
619 |
toload.push(w); |
|
620 |
} |
6
|
621 |
}); |
|
622 |
|
|
623 |
if (toload.length) { |
|
624 |
|
|
625 |
if (toload.length > _MAX_BATCH) { |
|
626 |
toload = _(toload).shuffle().slice(0,_MAX_BATCH); |
|
627 |
window.setInterval(throttledGetTweetIds,0); |
|
628 |
} |
|
629 |
|
|
630 |
dwr.engine.beginBatch(); |
|
631 |
toload.forEach(getMmsoTweetIds); |
|
632 |
dwr.engine.endBatch(); |
|
633 |
} |
|
634 |
} |
|
635 |
|
|
636 |
function getTweetData() { |
|
637 |
|
|
638 |
console.log("getTweetData"); |
|
639 |
|
|
640 |
var toload = []; |
|
641 |
|
|
642 |
_(requestedtweets).each(function(v) { |
|
643 |
if (!v.status) { |
|
644 |
toload.push(v.id); |
|
645 |
} |
|
646 |
}); |
|
647 |
|
9
|
648 |
if (toload.length) { |
|
649 |
toload = toload.slice(0,200); |
10
|
650 |
toload.forEach(function(twid) { |
|
651 |
requestedtweets[twid].status = 1; |
|
652 |
}) |
9
|
653 |
$.getJSON( |
6
|
654 |
solrUrl( |
|
655 |
"twitter", |
|
656 |
{ |
|
657 |
q:"id:(" + toload.join(" OR ") + ")", |
|
658 |
fl: "id_str,created_at,from_user_name,text,profile_image_url", |
|
659 |
rows: toload.length |
5
|
660 |
} |
6
|
661 |
), |
|
662 |
function(t) { |
|
663 |
var tweets = t.response.docs; |
|
664 |
tweets.forEach(function(tweet) { |
|
665 |
var timestamp = new Date(tweet.created_at).valueOf() / 1000 - deltaT; |
|
666 |
requestedtweets[tweet.id_str].data = tweet; |
|
667 |
requestedtweets[tweet.id_str].status = 2; |
|
668 |
requestedtweets[tweet.id_str].timestamp = timestamp; |
|
669 |
}); |
|
670 |
throttledShowTweets(); |
9
|
671 |
debouncedGetTweetData(); |
|
672 |
}); |
|
673 |
} |
|
674 |
|
|
675 |
|
6
|
676 |
|
|
677 |
} |
|
678 |
|
|
679 |
debouncedGetTweetData = _(getTweetData).debounce(125); |
|
680 |
|
|
681 |
throttledGetTweetIds = _(getTweetIds).throttle(10000); |
|
682 |
|
9
|
683 |
debouncedGetTweetIds = _(throttledGetTweetIds).debounce(125); |
|
684 |
|
6
|
685 |
throttledShowTweets = _(showTweets).throttle(200); |
|
686 |
|
|
687 |
function getLocalTweets() { |
|
688 |
|
|
689 |
console.log("getLocalTweets"); |
|
690 |
|
|
691 |
var topics = Array.prototype.join.call($(".topic.selected").map(function(){return $(this).attr("data-topic-id")})).split(","); |
|
692 |
|
|
693 |
for (var i = 0; i < localMmsos.length; i++) { |
|
694 |
var mmso = data.segments[localMmsoDelta + i]; |
|
695 |
if (!tweetstructure[mmso.id]) { |
7
|
696 |
tweetstructure[mmso.id] = { |
|
697 |
mmsoid: mmso.id, |
|
698 |
mmsoindex: localMmsoDelta + i, |
|
699 |
status: 0 |
|
700 |
} |
6
|
701 |
} |
5
|
702 |
} |
|
703 |
|
6
|
704 |
throttledGetTweetIds(); |
|
705 |
throttledShowTweets(); |
5
|
706 |
} |
|
707 |
|
6
|
708 |
var throttledGetTweets = _.throttle(getLocalTweets, 500), |
5
|
709 |
throttledShowLocal = _.throttle(showLocal, 100); |
|
710 |
|
|
711 |
showTopics(sortedTopics); |
7
|
712 |
|
|
713 |
pageParams.selectedtopics.forEach(function(id) { |
5
|
714 |
$(".topic[data-topic-id=" + id + "]").addClass("selected").attr("data-timestamp",++ordertag); |
|
715 |
}); |
|
716 |
|
7
|
717 |
var localpos = 300, |
5
|
718 |
localduration = 600; |
11
|
719 |
|
|
720 |
var player = new Player(); |
|
721 |
|
|
722 |
player.duration = data.duration; |
|
723 |
|
|
724 |
player.on("play", function() { |
|
725 |
$(".play-button").html("▐ ▌"); |
|
726 |
}); |
|
727 |
player.on("pause", function() { |
|
728 |
$(".play-button").text("▶"); |
|
729 |
}); |
|
730 |
player.on("timeupdate", function(t) { |
|
731 |
playTime.text(secsToString(t)); |
|
732 |
globalIndic.css("top", yscale * t); |
|
733 |
if (localyscale) { |
|
734 |
var localy = (+t - localpos + localduration / 2) * localyscale; |
|
735 |
localIndic.css("top", localy); |
|
736 |
} |
|
737 |
if (syncVideo) { |
|
738 |
localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, t)); |
|
739 |
throttledShowLocal(); |
|
740 |
} |
|
741 |
}); |
|
742 |
|
|
743 |
$(".play-button").click(function() { |
|
744 |
if (player.paused) { |
|
745 |
player.play(); |
|
746 |
} else { |
|
747 |
player.pause(); |
|
748 |
} |
|
749 |
}); |
|
750 |
|
|
751 |
$(".next-button").click(goToNext); |
5
|
752 |
|
|
753 |
$(".topics-block").on("mouseenter", ".topic", function() { |
|
754 |
var el = $(this); |
|
755 |
el.addClass("hover"); |
|
756 |
showTopicViz(); |
|
757 |
}).on("mouseleave", ".topic", function() { |
|
758 |
$(this).removeClass("hover"); |
|
759 |
showTopicViz(); |
|
760 |
}).on("click", ".topic", function() { |
|
761 |
var el = $(this); |
|
762 |
$(this).toggleClass("selected"); |
|
763 |
el.attr("data-timestamp", el.hasClass("selected") ? ++ordertag : 999999); |
|
764 |
showTopicViz(); |
|
765 |
}); |
11
|
766 |
|
|
767 |
var h = Hammer($(".play-bottom")[0]); |
|
768 |
|
|
769 |
var scrollGlobal, isDragging, startPos, startLevel, scaleStep = 1/Math.log(Math.sqrt(2)); |
|
770 |
|
|
771 |
h.on("tap", function(e) { |
|
772 |
var _o = $(this).offset(), |
|
773 |
posX = e.gesture.center.pageX - _o.left, |
|
774 |
posY = e.gesture.center.pageY - _o.top; |
|
775 |
if (posX < 140) { |
|
776 |
deSync(); |
|
777 |
localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, Math.floor(posY / yscale))); |
|
778 |
throttledShowLocal(); |
5
|
779 |
} |
11
|
780 |
}) |
|
781 |
.on("dragstart", function(e) { |
|
782 |
startPos = localpos; |
|
783 |
var x = e.gesture.center.pageX - $(this).offset().left; |
|
784 |
isDragging = (x < 380); |
|
785 |
scrollGlobal = (x < 140); |
|
786 |
}) |
|
787 |
.on("drag", function(e) { |
|
788 |
if (isDragging && e.gesture) { |
|
789 |
var delta = Math.floor(e.gesture.deltaY / (scrollGlobal ? yscale : - localyscale)); |
|
790 |
deSync(); |
|
791 |
localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, startPos + delta)); |
|
792 |
throttledShowLocal(); |
|
793 |
} |
|
794 |
}) |
|
795 |
.on("touch", function(e) { |
|
796 |
startLevel = currentlevel; |
|
797 |
}) |
|
798 |
.on("pinchin", function(e) { |
|
799 |
var newlevel = Math.max(0, Math.min(zoomlevels.length - 1, startLevel + Math.round(Math.log(e.gesture.scale)*scaleStep))); |
|
800 |
if (newlevel !== currentlevel) { |
|
801 |
currentlevel = newlevel; |
|
802 |
localduration = zoomlevels[currentlevel]; |
|
803 |
localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, localpos)); |
|
804 |
throttledShowLocal(); |
|
805 |
} |
|
806 |
}); |
|
807 |
|
5
|
808 |
var totalScroll = 0, zoomlevels = [ 1800, 900, 600, 300, 120, 60 ], currentlevel = 2; |
|
809 |
|
11
|
810 |
$(".play-bottom") |
|
811 |
.mousedown(function(_e) { |
|
812 |
_e.preventDefault(); |
|
813 |
}) |
|
814 |
.on("touchstart", function(_e) { |
|
815 |
_e.preventDefault(); |
|
816 |
}) |
|
817 |
.mousewheel(function(_event, _scrolldelta) { |
5
|
818 |
totalScroll += _scrolldelta; |
|
819 |
if (Math.abs(totalScroll) >= 1) { |
|
820 |
var d = (totalScroll > 0 ? 1 : -1), |
|
821 |
newlevel = Math.max(0, Math.min(zoomlevels.length - 1, currentlevel + d)); |
|
822 |
if (newlevel !== currentlevel) { |
|
823 |
currentlevel = newlevel; |
|
824 |
localduration = zoomlevels[currentlevel]; |
|
825 |
localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, localpos)); |
|
826 |
throttledShowLocal(); |
|
827 |
} |
|
828 |
totalScroll = 0; |
|
829 |
} |
11
|
830 |
_event.preventDefault(); |
7
|
831 |
}); |
|
832 |
|
|
833 |
if (pageParams.keywords && pageParams.keywords.length) { |
|
834 |
$(".keyword-search a").removeClass("placeholder").text(pageParams.keywords.join(", ")); |
|
835 |
} |
5
|
836 |
|
11
|
837 |
checkOrGoNext(); |
5
|
838 |
} |
|
839 |
|
|
840 |
var data = { duration: 10200, topics: [] }, |
|
841 |
colorset = ["#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#A65628", "#F781BF"]; |
|
842 |
|
|
843 |
$(function() { |
|
844 |
|
|
845 |
dwr.engine.setErrorHandler(function(a, b) { console.error("DWR", b); }); |
|
846 |
|
|
847 |
$(".topics-block").draggable({axis:"x"}); |
|
848 |
|
|
849 |
var loadedSteps = 0, |
|
850 |
stepsToFullyLoaded = 0; |
|
851 |
|
|
852 |
function checkIfLoaded() { |
|
853 |
loadedSteps++; |
|
854 |
if (loadedSteps >= stepsToFullyLoaded) { |
|
855 |
setTimeout(showData,0); |
|
856 |
} |
|
857 |
} |
|
858 |
|
|
859 |
function loadJson(url, propname, callback) { |
|
860 |
stepsToFullyLoaded++; |
|
861 |
$.getJSON(url, function(d) { |
|
862 |
if (callback) { |
|
863 |
var res = callback(d); |
|
864 |
} else { |
|
865 |
var res = d; |
|
866 |
} |
|
867 |
if (propname) { |
|
868 |
data[propname] = res; |
|
869 |
} |
|
870 |
checkIfLoaded(); |
|
871 |
}); |
|
872 |
} |
|
873 |
|
|
874 |
function loadFromTopicsBean(method, propname, args, callback) { |
|
875 |
stepsToFullyLoaded++; |
|
876 |
var arg = args || [], |
|
877 |
cb = function(d) { |
|
878 |
if (callback) { |
|
879 |
var res = callback(d); |
|
880 |
} else { |
|
881 |
var res = d; |
|
882 |
} |
|
883 |
if (propname) { |
|
884 |
data[propname] = res; |
|
885 |
} |
|
886 |
checkIfLoaded(); |
|
887 |
} |
|
888 |
arg.push({callback: cb}); |
|
889 |
TopicsBean[method].apply(TopicsBean,arg); |
|
890 |
} |
|
891 |
|
|
892 |
loadJson("data/minutes.json", "minutes"); |
|
893 |
loadJson("data/5secs.json", "fiveseconds"); |
|
894 |
|
|
895 |
loadJson( |
9
|
896 |
solrUrl("MMSO", {q: "*:*", fl: "topic*,MMSO_id,multimediaSegment,keywordsFromSocial", rows: 250 }), |
5
|
897 |
"segments", |
|
898 |
function(d) { |
|
899 |
return d.response.docs.map(function(mmso) { |
|
900 |
var tc = mmso.multimediaSegment.match(/\d+/g), |
|
901 |
start = parseInt(tc[0]), |
|
902 |
end = parseInt(tc[1]), |
7
|
903 |
topics = [], |
|
904 |
keywords = {}; |
|
905 |
|
|
906 |
function getKeywords(field) { |
|
907 |
var keywordtexts = mmso[field].replace(/[{}]/g,'').split(", "); |
|
908 |
keywordtexts.forEach(function(k) { |
|
909 |
var t = k.split('='), |
|
910 |
s = parseFloat(t[1]), |
|
911 |
w = t[0].split(" "); |
|
912 |
w.forEach(function(m) { |
|
913 |
if (m.length > 2) { |
|
914 |
keywords[m] = s + (keywords[m] || 0); |
|
915 |
} |
|
916 |
}); |
|
917 |
}); |
|
918 |
} |
|
919 |
|
9
|
920 |
//getKeywords("keywordsFromAudio"); |
7
|
921 |
getKeywords("keywordsFromSocial"); |
|
922 |
|
5
|
923 |
for (var k in mmso) { |
|
924 |
if (k.substr(0,5) === "topic" && mmso[k] > .01) { |
|
925 |
topics.push({ |
|
926 |
topic: parseInt(k.substr(5)), |
|
927 |
weight: mmso[k] |
|
928 |
}) |
|
929 |
} |
|
930 |
} |
|
931 |
topics.sort(function(a,b) { |
|
932 |
return b.weight - a.weight; |
|
933 |
}); |
|
934 |
/* topics = topics.filter(function(t) { |
|
935 |
return t.topic !== topicPoubelle |
|
936 |
}).slice(0,1); |
|
937 |
topics[0].weight = 1; */ |
|
938 |
return { |
|
939 |
id: mmso.MMSO_id, |
|
940 |
start: start, |
|
941 |
end: end, |
|
942 |
duration: end - start, |
7
|
943 |
topics: topics, |
|
944 |
keywords: keywords |
5
|
945 |
} |
|
946 |
}).sort(function(a,b) { |
|
947 |
return a.start - b.start; |
|
948 |
}); |
|
949 |
}) |
|
950 |
|
|
951 |
dwr.engine.setTimeout(60000); |
|
952 |
TopicsBean._path = "http://159.217.144.101:8050/sia-solr/dwr"; |
|
953 |
|
|
954 |
loadFromTopicsBean("getTopicsNumber",false,false,function(topic_count) { |
|
955 |
for (var i = 0; i < topic_count; i++) { |
|
956 |
data.topics.push(null); |
|
957 |
} |
|
958 |
dwr.engine.beginBatch(); |
|
959 |
data.topics.forEach(function(v, k) { |
|
960 |
loadFromTopicsBean("getTopicDistribution",false,[k, 50, false],function(topic) { |
|
961 |
var words = topic.match(/[^=,{]+=0.\d{0,8}/g); |
|
962 |
data.topics[k] = { |
|
963 |
index: k, |
|
964 |
words: words.map(function(w) { |
|
965 |
var parts = w.split("="); |
|
966 |
return { |
|
967 |
word: parts[0].trim(), |
|
968 |
weight: parseFloat(parts[1]) |
|
969 |
} |
|
970 |
}) |
|
971 |
} |
|
972 |
}); |
|
973 |
|
|
974 |
}); |
|
975 |
dwr.engine.endBatch(); |
|
976 |
|
|
977 |
}); |
|
978 |
|
|
979 |
|
|
980 |
}); |