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