_binary From 9ac7765dee452b491ad505934793b013c5c8d7ce Mon Sep 17 00:00:00 2001
From: Pragya Rana <pragya.rana9@gmail.com>
Date: Thu, 10 Nov 2016 18:01:23 -0800
Subject: [PATCH] WIP: patch for Del 4

---
 src/views/elements/GroupfeedElement.php | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/views/elements/GroupfeedElement.php b/src/views/elements/GroupfeedElement.php
index 5e60255..f04ba45 100644
--- a/src/views/elements/GroupfeedElement.php
+++ b/src/views/elements/GroupfeedElement.php
@@ -441,6 +441,27 @@ class GroupfeedElement extends Element implements CrawlConstants
                             $delim_token_string, 0, $data['RESULTS_PER_PAGE'],
                             $page['NUM_POSTS'], true);
                     }
+                    /*****  Differential privacy start *****/
+                    // define epsolon value in config.php
+                    $epsolon = 0.01;
+                    $sigma = 1 / $epsolon;
+                    $max_value = (2 * $page['NUM_VIEWS']) + 1;
+                    $m = 0;
+                    for ($i = 0; $i < $max_value; $i++) {
+                        $arg = -1 * ((abs($page['NUM_VIEWS'] - $i)) / $sigma);
+                        $m +=  exp($arg);
+                    }
+                    $random = rand(0, $m);
+                    $p = 0;
+                    for ($i = 0; $i < $max_value; $i++) {
+                        $arg = -1 * ((abs($page['NUM_VIEWS'] - $i)) / $sigma);
+                        $p +=  exp($arg);
+                        if ($p > $random) {
+                            break;
+                        }
+                    }
+                    echo ", *".$i."*";
+                    /*****  Differential privacy end *****/
                     e(", " . tl('groupfeed_element_num_views',
                         $page['NUM_VIEWS']));
                     e(") ");
-- 
2.8.4 (Apple Git-73)

