10 return u; |
10 return u; |
11 } |
11 } |
12 |
12 |
13 function showData() { |
13 function showData() { |
14 |
14 |
|
15 data.topiclabels.forEach(function(v) { |
|
16 var words = _(v.words).map(function(v, k) { |
|
17 return { |
|
18 word: k, |
|
19 weight: v |
|
20 } |
|
21 }); |
|
22 words.sort(function(a,b) { |
|
23 return b.weight - a.weight; |
|
24 }) |
|
25 data.topics[v.topic_id].words = words; |
|
26 }); |
|
27 |
15 var topicHash = document.location.hash || "#selectedtopics=5,15&visibletopics=5,10,15"; |
28 var topicHash = document.location.hash || "#selectedtopics=5,15&visibletopics=5,10,15"; |
16 |
29 |
17 var pageParams = {}; |
30 var pageParams = {}; |
18 |
31 |
19 var syncVideo = true, |
32 var syncVideo = true, |
117 } |
130 } |
118 } |
131 } |
119 |
132 |
120 function showTopics(topiclist) { |
133 function showTopics(topiclist) { |
121 var tbhtml = topiclist.reduce(function(mem, topic) { |
134 var tbhtml = topiclist.reduce(function(mem, topic) { |
122 var wordsToShow = topic.words.slice(0,3), |
135 var wordsToShow = topic.words.slice(0,4), |
123 max = wordsToShow[0].weight, |
136 max = wordsToShow[0].weight, |
124 min = Math.min(wordsToShow[wordsToShow.length - 1].weight, max - .01), |
137 min = Math.min(wordsToShow[wordsToShow.length - 1].weight, max - .01), |
125 scale = 8 / (max - min); |
138 scale = 8 / (max - min); |
126 var li = '<li class="shadow-block topic" data-topic-id="' |
139 var li = '<li class="shadow-block topic" data-topic-id="' |
127 + topic.index |
140 + topic.index |
482 }); |
495 }); |
483 |
496 |
484 |
497 |
485 var lastPos, lastDuration, lastTopics; |
498 var lastPos, lastDuration, lastTopics; |
486 |
499 |
487 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>'), |
500 var tweetTemplate = _.template( |
|
501 '<li class="tweet" data-timestamp="<%= timestamp %>" data-topic-id="<%= topic.topic %>">' |
|
502 + '<% if (show_link) { %><a href="#" data-user-id="<%- data.from_user_id %>"><% } %>' |
|
503 + '<img src="<%- data.profile_image_url %>" /><% if (show_link) { %></a><% } %>' |
|
504 + '<p><% if (show_link) { %><a href="#" data-user-id="<%- data.from_user_id %>"><% } %>' |
|
505 + '@<%- data.from_user_name %>:<% if (show_link) { %></a><% } %> <%= htext %></p></li>'), |
488 callnum = 0, |
506 callnum = 0, |
489 tweetstructure = {}, |
507 tweetstructure = {}, |
490 requestedtweets = {}, |
508 requestedtweets = {}, |
491 _NTWEETS = 50, |
509 _NTWEETS = 50, |
492 selectedWord = false; |
510 selectedWord = false; |
555 tweetstoshow = tweetstoshow.slice(0,10); |
573 tweetstoshow = tweetstoshow.slice(0,10); |
556 |
574 |
557 if (selectedWord) { |
575 if (selectedWord) { |
558 var rx = new RegExp( '(' + selectedWord.replace(/(\W)/gm,'\\$1') + ')', 'gim' ); |
576 var rx = new RegExp( '(' + selectedWord.replace(/(\W)/gm,'\\$1') + ')', 'gim' ); |
559 tweetstoshow.forEach(function(tw) { |
577 tweetstoshow.forEach(function(tw) { |
560 tw.data.htext = _(tw.data.text).escape().replace(rx,'<span class="highlight">$1</span>'); |
578 tw.htext = _(tw.data.text).escape().replace(rx,'<span class="highlight">$1</span>'); |
561 }); |
579 }); |
562 } else { |
580 } else { |
563 tweetstoshow.forEach(function(tw) { |
581 tweetstoshow.forEach(function(tw) { |
564 tw.data.htext = _(tw.data.text).escape(); |
582 tw.htext = _(tw.data.text).escape(); |
565 }) |
583 }); |
566 } |
584 } |
|
585 |
|
586 tweetstoshow.forEach(function(tw) { |
|
587 tw.show_link = true; |
|
588 }); |
567 |
589 |
568 tweetstoshow.sort(function(a, b) { |
590 tweetstoshow.sort(function(a, b) { |
569 return a.timestamp - b.timestamp; |
591 return a.timestamp - b.timestamp; |
570 }); |
592 }); |
571 |
593 |
664 $.getJSON( |
686 $.getJSON( |
665 solrUrl( |
687 solrUrl( |
666 "twitter", |
688 "twitter", |
667 { |
689 { |
668 q:"id:(" + toload.join(" OR ") + ")", |
690 q:"id:(" + toload.join(" OR ") + ")", |
669 fl: "id_str,created_at,from_user_name,text,profile_image_url", |
691 fl: "id_str,created_at,from_user_name,text,profile_image_url,from_user_id", |
670 rows: toload.length |
692 rows: toload.length |
671 } |
693 } |
672 ), |
694 ), |
673 function(t) { |
695 function(t) { |
674 var tweets = t.response.docs; |
696 var tweets = t.response.docs; |
817 Math.min( |
839 Math.min( |
818 zoomlevels.length - 1, |
840 zoomlevels.length - 1, |
819 startLevel + Math.round(Math.log(e.gesture.scale)*scaleStep) * (x > 140 ? 1 : -1) |
841 startLevel + Math.round(Math.log(e.gesture.scale)*scaleStep) * (x > 140 ? 1 : -1) |
820 ) |
842 ) |
821 ); |
843 ); |
822 //$("#konsole").text(e.gesture.scale + " => " + newlevel); |
|
823 if (newlevel !== currentlevel) { |
844 if (newlevel !== currentlevel) { |
824 currentlevel = newlevel; |
845 currentlevel = newlevel; |
825 localduration = zoomlevels[currentlevel]; |
846 localduration = zoomlevels[currentlevel]; |
826 localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, localpos)); |
847 localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, localpos)); |
827 throttledShowLocal(); |
848 throttledShowLocal(); |
855 |
876 |
856 if (pageParams.keywords && pageParams.keywords.length) { |
877 if (pageParams.keywords && pageParams.keywords.length) { |
857 $(".keyword-search a").removeClass("placeholder").text(pageParams.keywords.join(", ")); |
878 $(".keyword-search a").removeClass("placeholder").text(pageParams.keywords.join(", ")); |
858 } |
879 } |
859 |
880 |
|
881 var moveInterval; |
|
882 |
|
883 $(".left-arrow").data("direction", -3); |
|
884 $(".right-arrow").data("direction", 3); |
|
885 |
|
886 $(".left-arrow,.right-arrow") |
|
887 .on("mouseenter touchstart", function() { |
|
888 clearInterval(moveInterval); |
|
889 var moveDirection = $(this).data("direction"); |
|
890 moveInterval = setInterval(function() { |
|
891 var t = $(".topics-block"); |
|
892 t.css("left", + moveDirection + parseFloat(t.css("left"))); |
|
893 }, 20); |
|
894 }) |
|
895 .on("mouseleave touchend", function() { |
|
896 clearInterval(moveInterval); |
|
897 }); |
|
898 |
|
899 $(".play-localtweets").on("click", "li a", function() { |
|
900 var userid = $(this).attr("data-user-id"); |
|
901 $.getJSON( |
|
902 solrUrl( |
|
903 "twitter", |
|
904 { |
|
905 q: "from_user_id:" + userid, |
|
906 fl: "id_str,created_at,from_user_name,text,profile_image_url,from_user_id", |
|
907 rows: 500 |
|
908 } |
|
909 ), |
|
910 function(t) { |
|
911 var tweets = t.response.docs; |
|
912 tweets.forEach(function(tweet) { |
|
913 tweet.timestamp = new Date(tweet.created_at).valueOf() / 1000 - deltaT; |
|
914 }); |
|
915 tweets.sort(function(a,b) { |
|
916 return a.timestamp - b.timestamp; |
|
917 }) |
|
918 var html = tweets.reduce(function(mem, tweet) { |
|
919 return mem + tweetTemplate({ |
|
920 timestamp: tweet.timestamp, |
|
921 topic: {topic: -1}, |
|
922 weight: 0, |
|
923 data: tweet, |
|
924 htext: _(tweet.text).escape(), |
|
925 show_link: false |
|
926 }); |
|
927 },""); |
|
928 $(".user-tweets").show(); |
|
929 $(".user-tweets-list").html(html); |
|
930 $(".user-name").text(tweets[0].from_user_name); |
|
931 } |
|
932 ); |
|
933 return false; |
|
934 }); |
|
935 |
860 checkOrGoNext(); |
936 checkOrGoNext(); |
861 } |
937 } |
862 |
938 |
863 var data = { duration: 10200, topics: [] }, |
939 var data = { duration: 10200, topics: [] }, |
864 colorset = ["#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#A65628", "#F781BF"]; |
940 colorset = ["#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#A65628", "#F781BF"]; |
954 return a.timestamp - b.timestamp; |
1030 return a.timestamp - b.timestamp; |
955 }); |
1031 }); |
956 return randtweets; |
1032 return randtweets; |
957 } |
1033 } |
958 ) |
1034 ) |
|
1035 |
|
1036 loadJson("data/topiclabels.json", "topiclabels"); |
959 |
1037 |
960 loadJson( |
1038 loadJson( |
961 solrUrl("MMSO", {q: "*:*", fl: "topic*,MMSO_id,multimediaSegment,keywordsFromSocial", rows: 250 }), |
1039 solrUrl("MMSO", {q: "*:*", fl: "topic*,MMSO_id,multimediaSegment,keywordsFromSocial", rows: 250 }), |
962 "segments", |
1040 "segments", |
963 function(d) { |
1041 function(d) { |
1016 dwr.engine.setTimeout(60000); |
1094 dwr.engine.setTimeout(60000); |
1017 TopicsBean._path = "http://159.217.144.101:8050/sia-solr/dwr"; |
1095 TopicsBean._path = "http://159.217.144.101:8050/sia-solr/dwr"; |
1018 |
1096 |
1019 loadFromTopicsBean("getTopicsNumber",false,false,function(topic_count) { |
1097 loadFromTopicsBean("getTopicsNumber",false,false,function(topic_count) { |
1020 for (var i = 0; i < topic_count; i++) { |
1098 for (var i = 0; i < topic_count; i++) { |
1021 data.topics.push(null); |
1099 data.topics.push({ index: i, words: [ { word: "(no label)", weight: 1 }] }); |
1022 } |
1100 } |
1023 dwr.engine.beginBatch(); |
|
1024 data.topics.forEach(function(v, k) { |
|
1025 loadFromTopicsBean("getTopicDistribution",false,[k, 50, false],function(topic) { |
|
1026 var words = topic.match(/[^=,{]+=0.\d{0,8}/g); |
|
1027 data.topics[k] = { |
|
1028 index: k, |
|
1029 words: words.map(function(w) { |
|
1030 var parts = w.split("="); |
|
1031 return { |
|
1032 word: parts[0].trim(), |
|
1033 weight: parseFloat(parts[1]) |
|
1034 } |
|
1035 }) |
|
1036 } |
|
1037 }); |
|
1038 |
|
1039 }); |
|
1040 dwr.engine.endBatch(); |
|
1041 |
|
1042 }); |
1101 }); |
1043 |
1102 |
1044 |
1103 |
1045 }); |
1104 }); |