# HG changeset patch # User veltr # Date 1363109384 -3600 # Node ID ba3652cdd44b8b74d56122b84746b55191fee49b # Parent a2d5b669f6639dcf073e3cb016c944e1d8567791 Branch to keep old tweet fetch method diff -r a2d5b669f663 -r ba3652cdd44b js/playscreen.js --- a/js/playscreen.js Tue Mar 12 17:44:31 2013 +0100 +++ b/js/playscreen.js Tue Mar 12 18:29:44 2013 +0100 @@ -427,8 +427,8 @@ if (mmsostruct) { for (var j = 0; j < topics.length; j++) { var topicid = topics[j]; - if (mmsostruct.tweetids) { - var tweetids = mmsostruct.tweetids[topicid]; + if (mmsostruct[topicid]) { + var tweetids = mmsostruct[topicid].tweetids; for (var k = 0; k < tweetids.length; k++) { toshow.push(tweetids[k]); } @@ -446,7 +446,7 @@ tweetstoshow.forEach(function(tw) { tw.topic = tw.topics.filter(function(t) { - return topics.indexOf(t.topic.toString()) !== -1; + return topics.indexOf(t.topic) !== -1; }).sort(function(a,b) { return b.weight - a.weight })[0]; @@ -479,36 +479,36 @@ } function getMmsoTweetIds(mmstruct) { - TopicsBean.bestSocialInteractionsIdsMatching(mmstruct.mmsoid, 0, _NTWEETS, { - callback: function(res) { + console.log("TopicsBean.bestSocialInteractionsIdsMatching('" + mmstruct.mmso + "', " + mmstruct.topic + ", 0, " + _NTWEETS + ")"); + TopicsBean.bestSocialInteractionsIdsMatching(mmstruct.mmso, mmstruct.topic, 0, _NTWEETS, { + callback: function(tw) { mmstruct.status = 2; - mmstruct.tweetids = res; - for (var j = 0; j < res.length; j++) { - var tweetids = res[j], - ntw = tweetids.length, - topicweight = data.topics[j].weights[mmstruct.mmsoindex]; - for (var k = 0; k < tweetids.length; k++) { - var relevance = topicweight * (ntw - k) / ntw, - tweetid = tweetids[k]; - if (!requestedtweets[tweetid]) { - requestedtweets[tweetid] = { - id: tweetid, - status: 0, - topics: [] - } + mmstruct.tweetids = tw; + for (var k = 0; k < tw.length; k++) { + var tweetid = tw[k], + relevance = mmstruct.weight * (_NTWEETS - k) / _NTWEETS; + if (!requestedtweets[tweetid]) { + requestedtweets[tweetid] = { + id: tweetid, + status: 0, + topics: [] } requestedtweets[tweetid].topics.push({ topic: j, weight: relevance }); } + requestedtweets[tweetid].topics.push({ + topic: mmstruct.topic, + weight: relevance + }); } debouncedGetTweetData(); }, errorHandler: function(err,info) { mmstruct.status = 0; console.error(err,info); - throttledGetTweetIds(); + debouncedGetTweetIds(); } }); } @@ -521,11 +521,13 @@ var toload = []; - _(tweetstructure).each(function(w) { - if (!w.status) { - w.status = 1; - toload.push(w); - } + _(tweetstructure).each(function(v) { + _(v).each(function(w) { + if (!w.status) { + w.status = 1; + toload.push(w); + } + }); }); if (toload.length) { @@ -534,10 +536,11 @@ toload = _(toload).shuffle().slice(0,_MAX_BATCH); window.setInterval(throttledGetTweetIds,0); } - + console.log("Begin Batch"); dwr.engine.beginBatch(); toload.forEach(getMmsoTweetIds); dwr.engine.endBatch(); + console.log("End Batch"); } } @@ -582,6 +585,8 @@ throttledGetTweetIds = _(getTweetIds).throttle(10000); + debouncedGetTweetIds = _(throttledGetTweetIds).debounce(125); + throttledShowTweets = _(showTweets).throttle(200); function getLocalTweets() { @@ -593,11 +598,21 @@ for (var i = 0; i < localMmsos.length; i++) { var mmso = data.segments[localMmsoDelta + i]; if (!tweetstructure[mmso.id]) { - tweetstructure[mmso.id] = { - mmsoid: mmso.id, - mmsoindex: localMmsoDelta + i, - status: 0 - } + tweetstructure[mmso.id] = {} + } + var mmsostruct = tweetstructure[mmso.id]; + for (var j = 0; j < topics.length; j++) { + var topicid = topics[j], + weight = data.topics[topics[j]].weights[localMmsoDelta + i]; + if (weight > .1 && !mmsostruct[topicid]) { + mmsostruct[topicid] = { + topic: topicid, + mmso: mmso.id, + status: 0, + weight: weight, + tweetids: [] + }; + } } } @@ -696,7 +711,6 @@ colorset = ["#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#A65628", "#F781BF"]; $(function() { - dwr.engine.setErrorHandler(function(a, b) { console.error("DWR", b); }); $(".topics-block").draggable({axis:"x"});