Commits

ajish  committed 9a68d5e

updates to hooks

  • Participants
  • Parent commits 77e81e3

Comments (0)

Files changed (3)

                             fetched = data; 
                             plotPoints( data ); 
                     });
-                                    				
-                    jQuery.getJSON("index.py?page=fetch_texts", function(textdata){
-                            $("#texts_table").dataTable({
-                                "bProcessing": true,
-                                "bDestroy": true,
-                                "aaData": textdata,
-                            });
-
-                    });  
-                    jQuery.getJSON("index.py?page=fetch_counts&mode=keyword", function(countdata){
-                    
-                        //load up the list-items
-                        var content = "<canvas id=tag_cloud name=tagcloud width=350 height=350 style=\"float: left; margin-bottom: 20px\"><ul>";
-                        for( var i=0; i < 20; i++){
-                            content = content + "<li><a href=# data-weight="+Math.round(Math.log(countdata[i][1]))+">"+countdata[i][0]+"</a></li>";
-                        }
-                        content = content + "</ul></canvas>";
-                        $('#text_cloud').html( content );
-
-                        $('#tag_cloud').tagcanvas({
-                             outlineThickness : 1,
-                             maxSpeed : 0.01,
-                             depth : 0.75,
-                             weightFrom: "data-weight",
-                             weightMode: "both",
-                             weightSize: 5,
-                             weight: true
-                           });                    
-                    });  
+                    updateTable();                                    			                    updateWordCloud(); 
 				
 			});
 		</script>
 		
 		<!-- 3. Add the container -->
 		<div id="container" style="width: 800px; height: 400px; margin: 20 auto"></div>
-        <div id="text_cloud" style="position: absolute; top:425px; left:10px; width: 350px; height: 400px; margin: 20 auto;">
-		</div>	
-        <div id="text_content" class="dynacloud" style="visibility:hidden;">
+        <div id="text_cloud_container"  style="position: absolute; top:425px; left:10px; width: 600px; height: 400px; margin: 20 auto;">
+        <div id="text_cloud_ctrl">  
+            <select id="text_cloud_mode" onChange="updateWordCloud();">
+                <option value="keyword">keyword</option>
+                <option value="entity">entity</option>
+            </select>
+        </div>
+        <div id="text_cloud" style:"width: 600px;">
+		</div>
         </div>
-        <div id="texts" style="position: absolute; top:425px; left:625px; width: 800px; height: 400px; margin: 20 auto;">
+        <div id="texts" style="position: absolute; top:425px; left:625px; width: 600px; height: 400px; margin: 20 auto;">
                 <table id="texts_table">
                     <thead>
                         <tr>
 #!/usr/bin/env python
 import json
 import random
+import re
 from mako.template import Template
 from mako.lookup import TemplateLookup
 from mako import exceptions
             normed[key]+=1
     out = []
     for k,v in normed.items():
-        out.append( [k[0], k[1], float(v)*1000/float(len(points))] )
+        out.append( [k[0], k[1], float(v)/float(len(points))] )
     return out
  
 def fetch_texts( minx=None, maxx=None, miny=None, maxy=None ):
         texts.append( [ "%s: %s (%s)" % (r[0], r[textcol], r[idcol]) ] )
     return texts
 
+def fetch_entity_counts( minx=None, maxx=None, miny=None, maxy=None ):
+    ''' get the counts within the specified range
+        for each entity (twitter-id/hash-tag) found
+    '''
+    rows = get_rows( "dat.txt"  )
+    ycol = -1
+    xcol = -2
+    textcol = -3
+    idcol = -4
+    counts = {}
+    for r in rows:
+        x= float(r[xcol])
+        y= float(r[ycol])
+        y= round(y,3)
+        key = r[0].replace("\"","")
+        if minx and x < minx:
+            continue
+        if maxx and x > maxx:
+            continue
+        if miny and y < miny:
+            continue
+        if maxy and y > maxy:
+            continue
+        txt = r[textcol].lower()
+        txt = re.sub(r'[\"|:|,|.|!]',"",txt)
+        for key in txt.split():
+            if key.startswith("@") or key.startswith("#"):
+                if counts.has_key(key):
+                    counts[key] += 1
+                else:
+                    counts[key] = 1
+    pairs = []
+    for key, value in sorted(counts.iteritems(), key=lambda (k,v): (v,k), reverse=True):
+        pairs.append( [key, value] )
+    return pairs
 def fetch_keyword_counts( minx=None, maxx=None, miny=None, maxy=None ):
     ''' get the counts within the specified range
         for each keyword tracked
         pairs.append( [key, value] )
     return pairs
 
-allowed_modes = ["keyword"]
+allowed_modes = ["keyword","entity"]
 
 if page == "fetch_points":
     minx = get_optional_var("minx", form)
         raise Exception("Mode must be one of: %s" % (",".join(allowed_modes)))
     if mode == "keyword":
         counts = fetch_keyword_counts( float(minx), float(maxx), float(miny), float(maxy) )
+    elif mode == "entity":
+        counts = fetch_entity_counts( float(minx), float(maxx), float(miny), float(maxy) )
+        
     out = json.dumps(counts, encoding='latin1')
     print "Content-type: application/json\n\n"
     print out    

File js/scatter.js

+var rangeArgs="";
 var options = {
       chart: {
          renderTo: 'container', 
 
 
 function updateClouds( evt ){
-    xst = evt.xAxis[0].min;
-    xen = evt.xAxis[0].max;
-    yst = evt.yAxis[0].min;
-    yen = evt.yAxis[0].max;
+    if (evt.resetSelection == true){
+        rangeArgs = "";
+    }else{
+        xst = evt.xAxis[0].min;
+        xen = evt.xAxis[0].max;
+        yst = evt.yAxis[0].min;
+        yen = evt.yAxis[0].max;
+        rangeArgs = "&minx="+xst +"&maxx="+xen +"&miny="+yst +"&maxy="+yen; 
+    }
     $.ajax({    type: "GET",
-                url: "index.py?page=fetch_points&minx="+xst+"&maxx="+xen+"&miny="+yst+"&maxy="+yen,
+                url: "index.py?page=fetch_points"+rangeArgs,
                 success: function(data) {
                      var pts = renderClouds( data );
                      chart.xAxis[0].setExtremes();
                     $("#err").html("Reload error!");
                 }
             });
-    updateProxies( xst, xen, yst, yen );
+    updateTable();
+    updateWordCloud();
 
 }
 
 function renderClouds(points){
 
     var markers = new Array();
+    var min_pt = 2;
+    for (var i=0; i < points.length; i++){
+        if (points[i][2] < min_pt){
+            min_pt = points[i][2];
+        }
+    }
     for (var i=0; i < points.length; i++){
         markers[i] = {  "x": points[i][0],
                         "y": points[i][1],
-                        "marker": { "radius": points[i][2]*10 }
+                        "marker": { "radius": Math.log(points[i][2]/min_pt+1) * 10 }
                      };
     }
     return( markers );
 }
 
 
-function updateProxies( xmin, xmax, ymin, ymax ){
 
-    var rangeArgs = "&minx="+xmin +"&maxx="+xmax +"&miny="+ymin +"&maxy="+ymax; 
-    alert(rangeArgs);
+function updateTable( ){
     jQuery.getJSON("index.py?page=fetch_texts"+rangeArgs, function(textdata){
             $("#texts_table").dataTable({
                 "bProcessing": true,
             });
 
     });  
-    jQuery.getJSON("index.py?page=fetch_counts&mode=keyword"+rangeArgs, function(countdata){
+
+}
+
+function updateWordCloud(){
+    var mode = $("#text_cloud_mode").val();
+    jQuery.getJSON("index.py?page=fetch_counts&mode="+mode+rangeArgs, function(countdata){
     
         //load up the list-items
         var max_idx = 20;
         if (countdata.length < max_idx){
             max_idx = countdata.length;
         }
-        var content = "<canvas id=tag_cloud name=tagcloud width=350 height=350 style=\"float: left; margin-bottom: 20px\"><ul>";
+        var max_wgt = 0;
+        for( var i=0; i < max_idx; i++){
+                max_wgt += countdata[i][1];
+        }
+        var content = "<canvas id=tag_cloud name=tagcloud width=600 height=400 style=\"float: left; margin-bottom: 20px\"><ul>";
         for( var i=0; i < max_idx; i++){
-            content = content + "<li><a href=# data-weight="+(Math.round(Math.log(countdata[i][1]))+1)+">"+countdata[i][0]+"</a></li>";
+            wgt = (countdata[i][1] / max_wgt) * 36 + 4;
+            content = content + "<li><a href=# data-weight="+wgt+">"+countdata[i][0]+"</a></li>";
         }
         content = content + "</ul></canvas>";
         $('#text_cloud').html( content );