Commits

Gregory Petukhov committed eac6f64

Add missed rank counter

Comments (0)

Files changed (2)

 <script src="static/bootstrap/js/bootstrap.min.js"></script>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
 <script type="text/javascript" src="static/jsplumb-1.3.16/js/jquery.jsPlumb-1.3.16-all.js"></script>
-<script type="text/javascript" src="static/js/util.js?2"></script>
+<script type="text/javascript" src="static/js/util.js?4"></script>
 <!--<script type="text/javascript" src="static/js/jquery.the-modal.js"></script>-->
 </head>
 <body>
 <div class="navbar navbar-inverse navbar-fixed-top">
     <div class="navbar-inner">
         <div class="container">
-            <a class="brand" href="#">Javascript Page Rank</a>
+            <a class="brand" href="">Javascript Page Rank</a>
             <div class="nav-collapse collapse">
                 <ul class="nav">
                     <li class="divider-vertical"></li>
             <hr>
             <form>
                 <label class="checkbox">
-                    <input checked="checked" name="auto-calc" type="checkbox" /> Auto Calculation
+                    <input checked2="checked" name="auto-calc" type="checkbox" /> Auto Calculation
                 </label>
-                <input class="input-mini" value="5" name="iteration-count" type="text" />
+                <input class="input-mini" value="50" name="iteration-count" type="text" />
                 <span class="help-inline">Iterations</span>
             </form>
             <button class="btn btn-small btn-success" onclick="calculatePageRank()">Calculate PR</button>
 
         </div>
         <div class="span2">
+            <h3>Statistics</h3>
+            <div id="missed-rank">Missed rank: <span class="label label-success value">0</span></div>
             <h3>Credits</h3>
             <ul class="unstyled">
                 <li><a href="http://twitter.github.com/bootstrap/index.html">Twitter Bootstrap</a></li>

static/js/util.js

 var pageCounter = 0;
 var connections = {};
 var initialOffset = [0, 0];
+var missedRank = 0;
 
-//function getRandomInt(min, max) {
-  //return Math.floor(Math.random() * (max - min + 1)) + min;
-//}
-//
+function getRandomInt(min, max) {
+  return Math.floor(Math.random() * (max - min + 1)) + min;
+}
+
 function filter_array(array, value) {
     new_values = []
     $.each(array, function(idx, new_value) {
 }
 
 function calculatePageRank() {
-    var D = 0.85
 
+    var N = 0
     $.each(pageRegistry, function(pid, page) {
-        page.rank = 1;
+        N += 1;
+    });
+
+    //ranks = {
+        //'page1': getRandomInt(1, 100),
+        //'page2': getRandomInt(1, 100),
+        //'page3': getRandomInt(1, 100),
+        //'page4': getRandomInt(1, 100),
+        //'page5': getRandomInt(1, 100),
+    //}
+    $.each(pageRegistry, function(pid, page) {
+        //page.rank = ranks[pid];
+        page.rank = 1/N;
         page.rank_new = 0;
     });
 
+    var stopRegistry = [];
+
+    // Mark stop-pages
+    $.each(pageRegistry, function(pid, page) {
+        if (page.links.length == 0) {
+            page.stop = true;
+        } else {
+            page.stop = false;
+        }
+
+        // Remember stop links
+        if (page.stop) {
+            $.each(pageRegistry, function(x, test_page) {
+                if ($.inArray(pid, test_page.links) > -1) {
+                    //stopRegistry[stopRegistry.length] = [test_page.id, pid];
+                    //test_page.links = filter_array(test_page.links, pid);
+                    //console.log('Removing', test_page.id, 'link to', pid);
+                }
+            });
+        }
+    });
+
     var iterationCount = parseInt($('input[name="iteration-count"]').val());
     if (isNaN(iterationCount)) {
         iterationCount = 5;
     }
+
+    var D = 0.15;
+    missedRank = 0;
+
     for(var x=0; x<iterationCount; x++) {
         $.each(pageRegistry, function(pid, page) {
             if (page.links.length) {
                     var dst = pageRegistry[link_id];
                     dst.rank_new += rank_share;
                 });
-            }/* else {
-                page.rank_new += page.rank;
-            }*/
+            } else {
+                missedRank += (1 - D) * page.rank;
+            }
         });
         $.each(pageRegistry, function(pid, page) {
-            page.rank = (1- D) + D * page.rank_new;
+            page.rank = D/N + (1 - D) * page.rank_new;
+            //page.rank = page.rank_new;
             page.rank_new = 0;
         });
     }
+
+    missedRank = Math.round(missedRank * 1000) / 1000;
     $.each(pageRegistry, function(pid, page) {
-        page.rank = Math.round(page.rank * 1000)/1000;
+        page.rank = Math.round(page.rank * 1000) / 1000;
     });
     refreshPageInfo();
 }
         var node = $('#' + pid);
         node.find('.pr').text(page.rank);
     });
+    $('#missed-rank .value').text(missedRank);
 }
 
 function resetAll() {
             breakConnection(res);
         }
     });
-    p1 = createNewPage();
-    p2 = createNewPage();
+    p1 = createNewPage(1, [0, 0]);
+    p2 = createNewPage(2, [300, 0]);
+    p3 = createNewPage(3, [0, 100]);
+    p4 = createNewPage(4, [300, 100]);
+    p5 = createNewPage(5, [0, 200]);
     makeConnection({'sourceId': p1.id, 'targetId': p2.id})
+    makeConnection({'sourceId': p1.id, 'targetId': p3.id})
+    makeConnection({'sourceId': p3.id, 'targetId': p5.id})
+    makeConnection({'sourceId': p3.id, 'targetId': p4.id})
+    makeConnection({'sourceId': p2.id, 'targetId': p4.id})
+
+    makeConnection({'sourceId': p2.id, 'targetId': p1.id})
+    makeConnection({'sourceId': p3.id, 'targetId': p1.id})
+    makeConnection({'sourceId': p4.id, 'targetId': p1.id})
     calculatePageRank();
 });