changed the way columns were dumped
authorveltr
Tue, 21 Feb 2012 15:00:52 +0100
changeset 23 d473ebde73a3
parent 22 978c4a0e0095
child 24 5c1245fcc06f
changed the way columns were dumped
client/js/main.js
client/js/tweetanim.js
client/js/tweetvote-anim.js
client/main.html
--- a/client/js/main.js	Tue Feb 21 14:13:44 2012 +0100
+++ b/client/js/main.js	Tue Feb 21 15:00:52 2012 +0100
@@ -2,6 +2,13 @@
     myTweetSource,
     myQueueManager;
 
+var columnCounts,
+    onlineTweets = [],
+    dumpIsPaused = false;
+
+var MAX_TWEETS_BEFORE_DUMP = 10,
+    TWEETS_TO_DUMP_AT_ONCE = 5;
+
 function updateLastTweetList() {
     var _filtered = myTweetSource.afterDate(startHour),
         _txtFilter = $("#btv-cp-champ-filtre").val(),
@@ -61,6 +68,9 @@
 }
 
 $(function() {
+    columnCounts = columnKeywords.map(function() {
+        return 0;
+    })
     setInterval(function() {
         var _t = Math.floor((new Date() - startHour)/1000),
             _s = _t % 60,
@@ -103,14 +113,37 @@
             }
         }
         if (_cat != -1) {
-            if (_cat == 2) {
-                console.log(_t.text);
+            _t.cat = _cat;
+            columnCounts[_cat]++;
+            onlineTweets.push(_t);
+            createBallTweetForce(_t);
+            if (!dumpIsPaused) {
+                for (var _i = 0; _i < columnCounts.length; _i++) {
+                    if (columnCounts[_cat] > MAX_TWEETS_BEFORE_DUMP) {
+                        var toDel = onlineTweets.splice(0,TWEETS_TO_DUMP_AT_ONCE);
+                        
+                        for (var _j = 0; _j < toDel.length; _j++) {
+                            var _id = toDel[_j].id_str;
+                            world.DestroyBody(b2bod[_id]);
+                            
+                            $('#'+_id).delay(10).hide("slow").queue(function() {
+                                $(this).remove(); 
+                            });
+                        }
+                        
+                        // Regenerate column counts
+                        columnCounts = columnKeywords.map(function() {
+                            return 0;
+                        });
+                        for (var _k = 0; _k < onlineTweets.length; _k++) {
+                            columnCounts[onlineTweets[_k].cat]++;
+                        }
+                        break;
+                    }
+                }
             }
-            _t.cat = _cat;
-            createBallTweetForce(_t);
-            checkSilos();
         }
-});
+    });
     
     $("#btv-cp-champ-filtre").keyup(function() {
         updateLastTweetList();
@@ -132,4 +165,14 @@
            $(this).removeClass("btv-cp-status-play");
        }
     });
+    $("#btv-cp-cont-pause-aval").click(function() {
+        dumpIsPaused = !dumpIsPaused
+        if (dumpIsPaused) {
+            $(this).removeClass("btv-cp-status-pause");
+            $(this).addClass("btv-cp-status-play");
+        } else {
+            $(this).addClass("btv-cp-status-pause");
+            $(this).removeClass("btv-cp-status-play");
+        }
+    });
 });
\ No newline at end of file
--- a/client/js/tweetanim.js	Tue Feb 21 14:13:44 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,221 +0,0 @@
-var tweetQueue = [];
-var isAnimating = false;
-var countTweets = 0;
-var isPlayingTweets = false; // auto start
-var SPEED_TWEETS = 10;
-var MAX_VOTES = 10;
-var DUMP_TWEETS = 10;
-var toDel = [];
-
-var current_tweet = null;
-var current_past_tweet = 0;
-
-var ts = [];
-
-var candidats = Array(4);
-
-for(var h= 0; h < 4; h++) {
-  toDel[h] = [];
-}
-
-var b = 0;
-
-var defaultTweet = {
-  created_at: "Sun, 19 Feb 2012 19:12:15 +0000",
-  date_value: 1329678735000,
-  from_user: "chateaudeau",
-  from_user_id: 164810536,
-  from_user_id_str: "164810536",
-  from_user_name: "Olivia Duchâteau",
-  geo: null,
-  id: 171311150900854800,
-  id_str: "171311150900854784",
-  iso_language_code: "fr",
-  profile_image_url: "http://a2.twimg.com/profile_images/1481618117/clip_image00212_normal.jpg",
-  profile_image_url_https: "https://si0.twimg.com/profile_images/1481618117/clip_image00212_normal.jpg",
-  source: "&lt;a href=&quot;http://phnxapp.com&quot; rel=&quot;nofollow&quot;&gt;phnx&lt;/a&gt;",
-  text: "RT @LeProf_Higgins: Le carton rouge à Sarkozy, on a eu l'idée avant MLP mais le mien sera rouge, puis rose, mais pas brun !",
-  to_user: null,
-  to_user_id: null,
-  to_user_id_str: null,
-  to_user_name: null,
-};
-
-var TweetAnim = {
-
-  init: function() {
-  
-    var html = getDefaultTweet();
-    $('#tweet-container').fadeOut(0).html(html).fadeIn(2000, function() {
-      $(this).fadeOut(500,  function() {
-      isPlayingTweets=true;
-      $(this).html("").fadeIn();
-      });
-    });
-
-
-    
-   },
-  queueTweet: function(t) {
-
-    tweetQueue.push({t: t, anim: true}); 
-    $('#nbr-mesure-new').html(tweetQueue.length);
-    /*
-    if(tweetQueue.length>0)
-      document.getElementById('btn-tweet-next').style.visibility="visible";
-      */
-  },
-  
-  shiftQueue: function() {
-    if(tweetQueue.length==0) {
-        $('#tweet-container').html(getDefaultTweet());
-    }  
-    if((tweetQueue.length>0) && (!isAnimating)) {
-      countTweets++;
-      isAnimating = true;
-      var q = tweetQueue.shift();
-      this.showTweet(q.t, q.anim);
-
-    }
-
-  },
-  
-  skipQueue: function() {
-
-    if((tweetQueue.length>0) && (current_tweet!=null)) {
-      countTweets++;
-      isAnimating = true;
-      $('#tweet_anim_'+ current_tweet.id_str).dequeue();
-      TweetAnim.animate(current_tweet, true);
-      var q = tweetQueue.shift();
-      this.showTweet(q.t, true);
-    }
-  },
-  
-	showTweet: function(t, anim) {
-
-    var tweetId = "tweet_anim_" + t.id_str;
-    var imgId = "img_" + t.id_str;
-    
-    if(anim)
-      current_tweet = t;
-    
-    var htmlStr = "<div id='"+tweetId+"'><div class='tweet-bulle-avatar'>";
-    htmlStr += "  <img class='tweet-img-avatar' src='"+t.profile_image_url+"' id='"+imgId+"'/>";
-    htmlStr += "</div>";    
-    htmlStr += "<div class='tweet-preview-container'>";
-    htmlStr += "  <span class='tweet-screen-name'><a target='_blank' href='http://twitter.com/intent/user?screen_name="+t.from_user+"'>"+t.from_user+"</a></span>";    
-    htmlStr += "  <span class='tweet-full-name'>"+t.from_user_name+"</span>";
-    htmlStr += "  <div class='tweet-text'>"+t.text+"</div>";
-    htmlStr += "  <div class='tweet-time'><a target='_blank' href='http://twitter.com/#!/" + t.from_user + "/status/" +t.id_str+"'>"+t.created_at+"</div>";
-    htmlStr += "</div>";
-
-    $('#tweet-container').html(htmlStr);
-    $('#nbr-mesure-show').html(countTweets);
-    $('#nbr-mesure-new').html(tweetQueue.length);
-    /*
-    if(tweetQueue.length>0)
-      document.getElementById('btn-tweet-next').style.visibility="visible";
-    else 
-       document.getElementById('btn-tweet-next').style.visibility="hidden";
-*/
-        
-    if(anim) {
-      TweetAnim.animate(t, true);
-      
-      $('#'+tweetId).hover(function() {
-          $(this).stop(true, true).fadeIn();
-        }, function() {
-          TweetAnim.animate(t, true);
-      });
-    }
-	},
-	
-	animate: function(t, doSshift) {
-      var tweetId = "tweet_anim_" + t.id_str;
-
-    t.cat = t.from_user_id%4;
-    createBallTweetForce(t);
-
-    
-    // Pour expérimenter le balayage de tout le podium
-    //setInterval(function() {defaultTweet.cat = b%4; createBallTweetForce(defaultTweet); b++;}, 500);
-
-
-
- isAnimating = false;
-  if(doSshift)
-  TweetAnim.shiftQueue();
-          
-
-  toDel[t.cat].push(t);
-  checkSilos();
-        
-     
-	}
-}
-
-
-function getDefaultTweet() {
-
-  var htmlStr = "<div class='tweet-bulle-avatar'>";
-  htmlStr += "  <img class='tweet-img-avatar' src='img/avatar-icon.png' />";
-  htmlStr += "  </div>";
-  htmlStr += "  <div class='tweet-preview-container'>";
-  htmlStr += "  <span class='tweet-screen-name'><a target='_blank' href='http://twitter.com/intent/user?screen_name=bubbleT2012'>Bubble T</a></span>";
-  htmlStr += "  <span class='tweet-full-name'>tea or tweet ?</span>";
-  htmlStr += "  <div class='tweet-text'>";
-  htmlStr += "  <a href='http://www.twitter.com' target='blank'>";
-  htmlStr += "  Pendant que les prochains tweets se chargent.</br>";
-  htmlStr += "  Exprimez, vous aussi, vos opinions sur vos candidats favoris !</a>";
-  htmlStr += "  </div>";
-  htmlStr += "  <div class='tweet-time'>maintenant</div>";
-  
-  return htmlStr;
-      
-}
-
-function checkSilos() {
-
-  for(var j=0; j<4; j++) {
-    if(toDel[j].length>MAX_VOTES) {
-      
-      var ids = toDel[j].shift();
-      world.DestroyBody(b2bod[ids.id_str]);
-       
-
-      $('#'+ids.id_str).delay(10).hide("slow").queue(function() {
-        $(this).remove(); 
-      });
-    }
-  }
-}
-/*
-
-function emptySilos() {
-  console.log("emptySilos");
-
-    var toDel2 = [];
-    var m =0;
-
-    for(var k=0; k<DUMP_TWEETS; k++) {
-      world.DestroyBody(b2bod[toDel[k].id_str]);
-      $('#'+toDel[k].id_str).delay(10).hide("slow").queue(function() {
-        $(this).remove(); 
-      });
-    }
-    
-    for(var h= 0; h < candidats.length; h++) {
-     ts[h] = 0;
-    }
-
-    for(var l=DUMP_TWEETS; l<toDel.length; l++) {
-      toDel2[l-DUMP_TWEETS] = toDel[l];
-      ts[toDel2[l-DUMP_TWEETS].candidats[0]]++;  
-    }
-
-    toDel = toDel2;
-    current_past_tweet=toDel.length;
-}
-*/
-TweetAnim.init();
--- a/client/js/tweetvote-anim.js	Tue Feb 21 14:13:44 2012 +0100
+++ b/client/js/tweetvote-anim.js	Tue Feb 21 15:00:52 2012 +0100
@@ -293,7 +293,7 @@
     setInterval(function() {
     
       // Check if div podiums are already loaded
-      if($('#podium div').size() > 0) {h
+      if($('#podium div').size() > 0) {
         
         $('#podium div').each( function(idx, panel) {
        
@@ -429,7 +429,7 @@
   console.log("created " + t.id_str)
 	bodies.push(b2bod[t.id_str]);	
   
-  toDel[t.cat].push(t);
+//  toDel[t.cat].push(t);
   
 
 	$("#"+t.id_str).mouseover(function() {
--- a/client/main.html	Tue Feb 21 14:13:44 2012 +0100
+++ b/client/main.html	Tue Feb 21 15:00:52 2012 +0100
@@ -13,7 +13,6 @@
         
         <script type="text/javascript" src="lib/protoclass.js"></script>              
         <script type="text/javascript" src="lib/box2d.js"></script>
-        <script type="text/javascript" src="js/tweetanim.js"></script>
         <script type="text/javascript" src="js/tweetvote-anim.js"></script>     
         <script type="text/javascript" src="js/podium.js"></script>
         <script type="text/javascript" src="js/tweetsource.js"></script>