5
|
1 |
var topicPoubelle = 13; |
|
2 |
|
|
3 |
function showData() { |
1
|
4 |
|
5
|
5 |
var ordertag = 0; |
|
6 |
|
|
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 |
} |
1
|
20 |
|
5
|
21 |
$(".duration").text(secsToString(data.duration)); |
|
22 |
|
|
23 |
$(".topwords-list").on("click", "li", function() { |
|
24 |
var el = $(this).toggleClass("selected"); |
|
25 |
wordFilter(); |
|
26 |
}); |
|
27 |
|
|
28 |
var nmmso = data.segments.length; |
|
29 |
|
|
30 |
data.topics.forEach(function(topic) { |
|
31 |
topic.score = 0; |
|
32 |
topic.weights = []; |
|
33 |
for (var i = 0; i < nmmso; i++) { |
|
34 |
topic.weights.push(0); |
2
|
35 |
} |
5
|
36 |
}); |
|
37 |
|
|
38 |
data.segments.forEach(function(mmso, i) { |
|
39 |
mmso.topics.forEach(function(t) { |
|
40 |
data.topics[t.topic].weights[i] = t.weight; |
|
41 |
data.topics[t.topic].score += t.weight; |
2
|
42 |
}); |
5
|
43 |
mmso.tweet_rate = mmso.tweet_count / mmso.duration; |
|
44 |
}); |
|
45 |
|
|
46 |
var sortedTopics = data.topics.filter(function(t) { |
|
47 |
return t.index !== topicPoubelle; |
|
48 |
}).sort(function(a,b) { |
|
49 |
return b.score - a.score; |
|
50 |
}); |
|
51 |
|
|
52 |
var selectedWords = [], searchString = ""; |
|
53 |
|
|
54 |
function wordFilter() { |
|
55 |
var selectedLis = $(".topwords-list li.selected"); |
|
56 |
searchString = $(".keyword-search").val() || "", |
|
57 |
selectedWords = []; |
|
58 |
if (searchString.length) { |
|
59 |
selectedWords.push(searchString); |
|
60 |
} |
|
61 |
selectedLis.each(function() { |
|
62 |
selectedWords.push($(this).text().trim()); |
1
|
63 |
}); |
5
|
64 |
if (selectedWords.length) { |
|
65 |
/* |
|
66 |
var topiclist = data.topics.filter(function(topic) { |
|
67 |
if (topic.index === topicPoubelle) { |
|
68 |
return false; |
|
69 |
} |
|
70 |
var found = false, |
|
71 |
relevance = 0; |
|
72 |
var foundWords = selectedWords.map(function() { return false }); |
|
73 |
topic.words.forEach(function(topicword) { |
|
74 |
selectedWords.forEach(function(selectedword, k) { |
|
75 |
if (topicword.word.search(selectedword) !== -1) { |
4
|
76 |
found = true; |
|
77 |
relevance += (.5 + topicword.weight); |
|
78 |
} |
2
|
79 |
}); |
4
|
80 |
}); |
5
|
81 |
topic.relevance = relevance; |
|
82 |
return found; |
|
83 |
}).sort(function(a,b) { |
|
84 |
return b.relevance - a.relevance; |
|
85 |
}); |
|
86 |
*/ |
|
87 |
TopicsBean.topicsForKeywords(selectedWords.join(","),{ |
|
88 |
callback: function(topicweights) { |
|
89 |
var topiclist = data.topics.filter(function(topic) { |
|
90 |
return topicweights[topic.index] > .01 && topic.index !== topicPoubelle; |
|
91 |
}); |
|
92 |
topiclist.sort(function(a,b) { |
|
93 |
return topicweights[b.index] - topicweights[b.index] |
|
94 |
}); |
|
95 |
showTopics(topiclist); |
|
96 |
} |
|
97 |
}); |
|
98 |
} else { |
|
99 |
showTopics(sortedTopics); |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
function showTopics(topiclist) { |
|
104 |
var topicHtmls = ["", "", ""]; |
|
105 |
if (searchString.length) { |
|
106 |
var searchStringRx = new RegExp('(' + searchString.replace(/(\W)/g,'\\$1') + ')', "gim"); |
|
107 |
$(".topwords-list li").each(function() { |
|
108 |
var el = $(this); |
|
109 |
el.html(el.text().replace(searchStringRx,'<span class="highlight">$1</span>')); |
2
|
110 |
}); |
5
|
111 |
} else { |
|
112 |
$(".topwords-list li").each(function() { |
|
113 |
var el = $(this); |
|
114 |
el.text(el.text()); |
|
115 |
}); |
2
|
116 |
} |
5
|
117 |
var replaceRx = new RegExp('(' + selectedWords.map(function(w) { |
|
118 |
return w.replace(/(\W)/g,'\\$1') |
|
119 |
}).join("|") + ')', "gim"); |
|
120 |
topiclist.forEach(function(topic,i) { |
|
121 |
var wordsToShow = topic.words.slice(0,8), |
|
122 |
max = wordsToShow[0].weight, |
|
123 |
min = Math.min(wordsToShow[wordsToShow.length - 1].weight, max - .01), |
|
124 |
scale = 10 / (max - min); |
|
125 |
var li = '<li class="shadow-block topic" data-topic-id="' |
|
126 |
+ topic.index |
|
127 |
+ '" data-timestamp="999999"><ul class="topic-words">' |
|
128 |
+ wordsToShow.reduce(function(memwords, word) { |
|
129 |
return memwords |
|
130 |
+ '<li style="font-size: ' |
|
131 |
+ ( 10 + scale * (word.weight - min) ) |
|
132 |
+ 'px;">' |
|
133 |
+ ( selectedWords.length |
|
134 |
? word.word.replace(replaceRx,'<span class="highlight">$1</span>') |
|
135 |
: word.word ) |
|
136 |
+ '</li>'; |
|
137 |
},"") |
|
138 |
+ '</ul></li>'; |
|
139 |
topicHtmls[i % 3] += li; |
|
140 |
}); |
|
141 |
var tb = $(".topics-block"); |
|
142 |
tb.html(topicHtmls.reduce(function(mem,html) { |
|
143 |
return mem + '<ul class="topic-column">' + html + '</ul>' |
|
144 |
},"")); |
|
145 |
tb.css("top",0); |
1
|
146 |
|
5
|
147 |
showTopicViz(); |
|
148 |
} |
6
|
149 |
/* |
4
|
150 |
var topwords = [], globwords = {}; |
|
151 |
|
|
152 |
data.topics.forEach(function(topic) { |
|
153 |
topic.words.forEach(function(word) { |
|
154 |
globwords[word.word] = word.weight + (globwords[word.word] || 0) |
|
155 |
}); |
|
156 |
}) |
|
157 |
|
|
158 |
for (var w in globwords) { |
|
159 |
topwords.push({ |
|
160 |
word : w, |
|
161 |
weight : globwords[w] |
|
162 |
}); |
|
163 |
} |
|
164 |
topwords.sort(function(a, b) { |
|
165 |
return b.weight - a.weight; |
|
166 |
}); |
|
167 |
|
|
168 |
$(".keyword-search").autocomplete({ |
|
169 |
source: topwords.map(function(w) { return w.word }) |
|
170 |
}).on("keyup change paste", wordFilter); |
6
|
171 |
*/ |
|
172 |
// /* |
|
173 |
var globwords = {}; |
5
|
174 |
|
|
175 |
data.topics.forEach(function(topic) { |
6
|
176 |
topic.words.forEach(function(topicword) { |
|
177 |
topicword.word.split(" ").filter(function(w) { |
|
178 |
return w.length > 2; |
|
179 |
}).forEach(function(w) { |
|
180 |
globwords[w] = 2 * topicword.weight + (globwords[w] || 0) |
|
181 |
}); |
5
|
182 |
}); |
|
183 |
}); |
|
184 |
|
6
|
185 |
var ntw = data.topwords.length; |
|
186 |
|
|
187 |
data.topwords.forEach(function(v, k) { |
|
188 |
var weight = (ntw - k)/ntw; |
|
189 |
v.split(" ").filter(function(w) { |
|
190 |
return w.length > 2; |
|
191 |
}).forEach(function(w) { |
|
192 |
globwords[w] = weight + (globwords[w] || 0) |
|
193 |
}); |
5
|
194 |
}); |
|
195 |
|
6
|
196 |
delete globwords.des; |
|
197 |
|
|
198 |
var allwords = _(globwords).keys(), |
|
199 |
topwords = _(globwords).map(function(v, k) { |
|
200 |
return { |
|
201 |
word: k, |
|
202 |
weight: v |
|
203 |
} |
|
204 |
}); |
|
205 |
|
|
206 |
topwords.sort(function(a,b) { |
|
207 |
return b.weight - a.weight |
|
208 |
}); |
|
209 |
|
5
|
210 |
allwords.sort(); |
|
211 |
|
|
212 |
$(".keyword-search").autocomplete({ |
7
|
213 |
source: allwords, |
|
214 |
change: function() { |
|
215 |
window.setInterval(wordFilter,0); |
|
216 |
} |
5
|
217 |
}).on("keyup change paste", wordFilter); |
6
|
218 |
// */ |
5
|
219 |
|
|
220 |
var wordsToShow = topwords.slice(0,80), |
|
221 |
max = wordsToShow[0].weight, |
|
222 |
min = Math.min(wordsToShow[wordsToShow.length - 1].weight, max - .01), |
|
223 |
scale = 10 / (max - min); |
|
224 |
|
|
225 |
$(".topwords-list").html(wordsToShow.reduce(function(mem, d) { |
|
226 |
return mem |
|
227 |
+ '<li style="font-size: ' |
|
228 |
+ ( 10 + scale * (d.weight - min) ) |
|
229 |
+ 'px;">' |
|
230 |
+ d.word |
|
231 |
+ '</li>' |
|
232 |
},"")); |
|
233 |
|
|
234 |
function showTopicViz() { |
|
235 |
var selectedBlocks = $(".topic.selected, .topic.hover"), |
|
236 |
sbl = selectedBlocks.length, |
|
237 |
topicBlocks = $(".topic"); |
|
238 |
if (!sbl && topicBlocks.length < sortedTopics.length) { |
|
239 |
selectedBlocks = topicBlocks; |
|
240 |
sbl = selectedBlocks.length; |
|
241 |
} |
|
242 |
var topicsAndColors = []; |
7
|
243 |
selectedBlocks.each(function() { |
5
|
244 |
var el = $(this), |
|
245 |
topicid = parseInt(el.attr("data-topic-id")); |
|
246 |
topicsAndColors.push({ |
|
247 |
"$": el, |
|
248 |
timestamp: parseInt(el.attr("data-timestamp")), |
|
249 |
hovered: el.hasClass("hover"), |
|
250 |
id: topicid, |
|
251 |
topic: data.topics[topicid] |
4
|
252 |
}); |
5
|
253 |
}); |
|
254 |
topicsAndColors.sort(function(a,b) { |
|
255 |
return ( a.timestamp - b.timestamp ) || ( a.id - b.id ); |
|
256 |
}); |
|
257 |
topicBlocks.css("background",""); |
|
258 |
topicsAndColors.forEach(function(topic, i) { |
|
259 |
topic.color = topic.hovered ? "#ffff00" : colorset[i % colorset.length]; |
|
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; |
4
|
273 |
}); |
5
|
274 |
if (opacity) { |
|
275 |
color = Raphael.rgb.apply(Raphael, rgb.map(function(c) { |
|
276 |
return c/opacity; |
|
277 |
})); |
|
278 |
segmentrects[i].show(); |
|
279 |
segmentrects[i].attr({ |
|
280 |
fill: color, |
|
281 |
opacity: .5 + .5 * opacity |
4
|
282 |
}); |
5
|
283 |
} else { |
|
284 |
segmentrects[i].hide(); |
1
|
285 |
} |
2
|
286 |
} |
|
287 |
|
7
|
288 |
var url = "playscreen.html#visibletopics=" |
|
289 |
+ Array.prototype.join.call($(".topic:visible").map(function(){return $(this).attr("data-topic-id")})) |
|
290 |
+ "&selectedtopics=" |
|
291 |
+ Array.prototype.slice.call(topicsAndColors.map(function(t){return t.id})) |
|
292 |
+ "&keywords=" |
|
293 |
+ selectedWords.map(function(w) { |
|
294 |
return encodeURIComponent(w); |
|
295 |
}).join(","); |
|
296 |
|
|
297 |
$(".play-button").attr("href",url); |
|
298 |
|
5
|
299 |
} |
|
300 |
|
|
301 |
var jqsvg = $(".start-svg"); |
|
302 |
paper = new Raphael(jqsvg[0]), |
|
303 |
ph = jqsvg.height(), |
|
304 |
pw = jqsvg.width(), |
|
305 |
yscale = (ph - 20) / data.duration, |
|
306 |
mx = Math.max.apply(Math, data.minutes.map(function(s) { return s.count})), |
|
307 |
xscale = (pw - 50)/mx; |
|
308 |
|
|
309 |
var segmentrects = data.segments.map(function(mmso) { |
|
310 |
var rect = paper.rect(0, yscale * mmso.start, pw - 50, 1+yscale * mmso.duration); |
|
311 |
rect.attr({stroke: "none"}); |
|
312 |
return rect; |
|
313 |
}); |
|
314 |
|
|
315 |
var d = "M" + data.minutes.map(function(s) { |
|
316 |
var x = xscale * s.count; |
|
317 |
return x |
|
318 |
+ "," |
|
319 |
+ yscale * (s.from + 20) |
|
320 |
+ "L" |
|
321 |
+ x |
|
322 |
+ "," |
|
323 |
+ yscale * (s.from + 40); |
|
324 |
}).join("L"); |
2
|
325 |
|
5
|
326 |
paper.path(d).attr({ |
|
327 |
"stroke-width": 4, |
|
328 |
"stroke": "#000000", |
|
329 |
opacity: .5 |
|
330 |
}); |
|
331 |
paper.path(d).attr({ |
|
332 |
"stroke-width": 1, |
|
333 |
"stroke": "#ffffff" |
|
334 |
}); |
|
335 |
|
|
336 |
for (var i=0; i < data.duration; i += 1800) { |
|
337 |
var y = yscale * i; |
|
338 |
paper.path("M0," + y + "L" + pw + "," + y).attr({ |
|
339 |
stroke: "#666" |
4
|
340 |
}); |
5
|
341 |
paper.text(pw - 2, y + 6, secsToString(i)).attr({ |
4
|
342 |
"text-anchor": "end", |
|
343 |
"fill": "#ffffff" |
|
344 |
}); |
5
|
345 |
} |
|
346 |
paper.text(pw-2, ph-14, secsToString(data.duration)).attr({ |
|
347 |
"text-anchor": "end", |
|
348 |
"fill": "#ffffff" |
|
349 |
}); |
|
350 |
paper.path("M0," + (ph-20) + "L" + pw + "," + (ph-20)).attr({ |
|
351 |
stroke: "#666" |
|
352 |
}); |
|
353 |
paper.text(0, ph - 14,"tweets/min.").attr({ |
|
354 |
"text-anchor": "start", |
|
355 |
"fill": "#ffffff" |
|
356 |
}); |
|
357 |
|
|
358 |
for (var k = 2; k < 6; k++) { |
|
359 |
var x = xscale * k * 1000; |
4
|
360 |
paper.path("M" + x + ",0L" + x + "," + (ph - 10)).attr({ |
|
361 |
stroke: "#666" |
|
362 |
}); |
|
363 |
|
5
|
364 |
paper.text(x-2, ph - 14,k+"k").attr({ |
4
|
365 |
"fill": "#ffffff" |
2
|
366 |
}); |
5
|
367 |
} |
|
368 |
|
|
369 |
wordFilter(); |
|
370 |
|
|
371 |
$(".topics-block").on("mouseenter", ".topic", function() { |
|
372 |
var el = $(this); |
|
373 |
el.addClass("hover"); |
|
374 |
showTopicViz(); |
|
375 |
}).on("mouseleave", ".topic", function() { |
|
376 |
$(this).removeClass("hover"); |
|
377 |
showTopicViz(); |
|
378 |
}).on("click", ".topic", function() { |
|
379 |
var el = $(this); |
|
380 |
$(this).toggleClass("selected"); |
|
381 |
el.attr("data-timestamp", el.hasClass("selected") ? ++ordertag : 999999); |
|
382 |
showTopicViz(); |
|
383 |
}); |
|
384 |
} |
|
385 |
|
|
386 |
var data = { duration: 10200, topics: [] }, |
|
387 |
colorset = ["#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#A65628", "#F781BF"]; |
|
388 |
|
|
389 |
$(function() { |
|
390 |
|
|
391 |
$(".topics-block").draggable({axis:"y"}); |
|
392 |
|
|
393 |
var loadedSteps = 0, |
|
394 |
stepsToFullyLoaded = 0; |
|
395 |
|
|
396 |
function checkIfLoaded() { |
|
397 |
loadedSteps++; |
|
398 |
if (loadedSteps >= stepsToFullyLoaded) { |
|
399 |
setTimeout(showData,0); |
|
400 |
} |
|
401 |
} |
|
402 |
|
|
403 |
function loadJson(url, propname, callback) { |
|
404 |
stepsToFullyLoaded++; |
|
405 |
$.getJSON(url, function(d) { |
|
406 |
if (callback) { |
|
407 |
var res = callback(d); |
|
408 |
} else { |
|
409 |
var res = d; |
|
410 |
} |
|
411 |
if (propname) { |
|
412 |
data[propname] = res; |
|
413 |
} |
|
414 |
checkIfLoaded(); |
|
415 |
}); |
|
416 |
} |
|
417 |
|
|
418 |
function solrUrl(table, params) { |
|
419 |
return "http://159.217.144.101:8050/sia-solr/" + table + "/select?" + $.param(params) + "&wt=json&json.wrf=?"; |
|
420 |
} |
|
421 |
|
|
422 |
function loadFromTopicsBean(method, propname, args, callback) { |
|
423 |
stepsToFullyLoaded++; |
|
424 |
var arg = args || [], |
|
425 |
cb = function(d) { |
|
426 |
if (callback) { |
|
427 |
var res = callback(d); |
|
428 |
} else { |
|
429 |
var res = d; |
|
430 |
} |
|
431 |
if (propname) { |
|
432 |
data[propname] = res; |
|
433 |
} |
|
434 |
checkIfLoaded(); |
|
435 |
} |
|
436 |
arg.push({callback: cb}); |
|
437 |
TopicsBean[method].apply(TopicsBean,arg); |
|
438 |
} |
|
439 |
|
|
440 |
loadJson("data/minutes.json", "minutes"); |
|
441 |
|
|
442 |
loadJson( |
|
443 |
solrUrl("MMSO", {q: "*:*", fl: "topic*,MMSO_id,multimediaSegment", rows: 250 }), |
|
444 |
"segments", |
|
445 |
function(d) { |
|
446 |
return d.response.docs.map(function(mmso) { |
|
447 |
var tc = mmso.multimediaSegment.match(/\d+/g), |
|
448 |
start = parseInt(tc[0]), |
|
449 |
end = parseInt(tc[1]), |
|
450 |
topics = []; |
|
451 |
for (var k in mmso) { |
|
452 |
if (k.substr(0,5) === "topic" && mmso[k] > .01) { |
|
453 |
topics.push({ |
|
454 |
topic: parseInt(k.substr(5)), |
|
455 |
weight: mmso[k] |
|
456 |
}) |
|
457 |
} |
|
458 |
} |
|
459 |
topics.sort(function(a,b) { |
|
460 |
return b.weight - a.weight; |
|
461 |
}); |
|
462 |
/* topics = topics.filter(function(t) { |
|
463 |
return t.topic !== topicPoubelle |
|
464 |
}).slice(0,1); |
|
465 |
topics[0].weight = 1; */ |
|
466 |
return { |
|
467 |
id: mmso.MMSO_id, |
|
468 |
start: start, |
|
469 |
end: end, |
|
470 |
duration: end - start, |
6
|
471 |
topics: topics |
5
|
472 |
} |
|
473 |
}).sort(function(a,b) { |
|
474 |
return a.start - b.start; |
|
475 |
}); |
|
476 |
}) |
|
477 |
|
|
478 |
dwr.engine.setTimeout(60000); |
|
479 |
TopicsBean._path = "http://159.217.144.101:8050/sia-solr/dwr"; |
|
480 |
|
|
481 |
loadFromTopicsBean("getTopicsNumber",false,false,function(topic_count) { |
|
482 |
for (var i = 0; i < topic_count; i++) { |
|
483 |
data.topics.push(null); |
|
484 |
} |
|
485 |
data.topics.forEach(function(v, k) { |
|
486 |
loadFromTopicsBean("getTopicDistribution",false,[k, 50, false],function(topic) { |
|
487 |
var words = topic.match(/[^=,{]+=0.\d{0,8}/g); |
|
488 |
data.topics[k] = { |
|
489 |
index: k, |
|
490 |
words: words.map(function(w) { |
|
491 |
var parts = w.split("="); |
|
492 |
return { |
|
493 |
word: parts[0].trim(), |
|
494 |
weight: parseFloat(parts[1]) |
|
495 |
} |
|
496 |
}) |
|
497 |
} |
|
498 |
}); |
|
499 |
|
|
500 |
}); |
2
|
501 |
|
1
|
502 |
}); |
5
|
503 |
|
6
|
504 |
loadFromTopicsBean("getTopWords","topwords",[200]); |
5
|
505 |
|
1
|
506 |
}); |