예제 #1
0
require_once 'config/config.php';
require_once 'config/db.php';
require_once 'lib/user.php';
require_once 'lib/follower.php';
require_once 'lib/following.php';
require_once 'lib/follower2.php';
require_once 'lib/following2.php';
require_once 'lib/kmeans.php';
require_once 'lib/centroid.php';
$db = new db();
/* $following_dao = new Following_dao;
$following_dao->countCommonFollowing(); //menghitung masing-masing common_friends dari following dan menyimpannya ke tabel following
$following_dao->countCommonFollower();  //menghitung masing-masing common_follower dari following dan menyimpannya ke tabel following
$following_dao->countSimilarity(); 
 */
$user_dao = new User_dao();
$user = $user_dao->getAll();
//mendapatkan data user
$following_dao = new Following_dao();
$datanya = $following_dao->getId();
//mendapatkan data id following
//var_dump($datanya);
// $column1 = "common_followers_count";
// $column2 = "common_friends_count";
$column1 = "similarity_followers";
$column2 = "similarity_friends";
$data = loadData($column1, $column2);
//mendapatkan data similarity dari tabel following
//var_dump($data);
//$data = array(array(0,0),array(0,2), array(2,0), array(2,2), array(5,0), array(5,2), array(7,0), array(7,2));
//$datanya = array("a","b","c","d","e","f","g","h");
예제 #2
0
 function countSimilarity()
 {
     $user_dao = new User_dao();
     $user = $user_dao->getAll();
     //var_dump($user);
     $followers_user = $user->followers_count - 1;
     $friends_user = $user->friends_count - 1;
     //echo $followers_user;
     $following_dao = new Following_dao();
     $following = $following_dao->getAll();
     foreach ($following as $fol) {
         $similarity_follower = $fol->common_followers_count / $followers_user;
         //echo $similarity_follower;
         $following_dao->addSimilarityFollower($fol->id, $similarity_follower);
         $similarity_friends = $fol->common_friends_count / $friends_user;
         //echo $similarity_friends;
         $following_dao->addSimilarityFollowing($fol->id, $similarity_friends);
     }
 }
예제 #3
0
 function cluster($k)
 {
     $db = new db();
     $user_dao = new User_dao();
     $user = $user_dao->getAll();
     //get data user
     //create graph
     $graph = new Graph(700, 600);
     //set graph
     $graph->SetScale("linlin");
     $graph->img->SetMargin(70, 50, 50, 50);
     //$graph->SetShadow();
     $graph->title->Set("Friends Twitter Clustering");
     $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 14);
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->title->SetMargin(10);
     $userx = $user->name;
     $graph->subtitle->Set("User: "******" (" . $k . " Kluster)");
     $graph->subtitle->SetFont(FF_FONT1, FS_BOLD);
     //$graph->yaxis->scale->SetAutoMax(1);  //untuk seting max nilai y
     //$graph->xaxis->scale->SetAutoMax(1);  //untuk seting max nilai x
     //
     $following_dao = new Following_dao();
     /* 
     	$data = $following_dao->get();
     	$x = array();
     	$y = array();
     	for($i=0; $i<count($data); $i++){
     		$x[]=$data[$i][0];
     		$y[]=$data[$i][1];	
     	}
     	
     	//format scatterplots data
     	$scatterplots = new ScatterPlot($y, $x); // (Data)
     	$scatterplots->mark->SetType(MARK_FILLEDCIRCLE);
     	$scatterplots->mark->SetFillColor("blue");
     	$scatterplots->mark->SetWidth(4);
     */
     $warna = array("blue", "orange", "green", "purple", "maroon", "pink", "cyan", "violet", "lime", "fuchsia", "maroon", "olive", "navy", "purple", "chocolate", "coral", "lightblue", "orchid", "skyblue", "yellow", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
     //warna untuk cluster
     //data cluster
     for ($i = 0; $i < $k; $i++) {
         $x = array();
         $y = array();
         $data = $following_dao->getByCluster($i + 1);
         //var_dump($data);
         for ($j = 0; $j < count($data); $j++) {
             $x[] = $data[$j][0];
             $y[] = $data[$j][1];
         }
         //var_dump($x);
         $scatterplots[$i] = new ScatterPlot($y, $x);
         $scatterplots[$i]->mark->SetType(MARK_FILLEDCIRCLE);
         if ($warna[$i] == "") {
             $warna[$i] = "gold";
         }
         $scatterplots[$i]->mark->SetFillColor($warna[$i]);
         $scatterplots[$i]->mark->SetWidth(3);
         $graph->Add($scatterplots[$i]);
     }
     // data centroid
     $centroid_dao = new Centroid_dao();
     $data2 = $centroid_dao->get();
     $x2 = array();
     $y2 = array();
     for ($i = 0; $i < count($data2); $i++) {
         $x2[] = $data2[$i][0];
         $y2[] = $data2[$i][1];
     }
     $centroids = new ScatterPlot($y2, $x2);
     // (Centroids)
     $centroids->mark->SetType(MARK_CROSS);
     $centroids->mark->SetFillColor("red");
     $centroids->mark->SetColor("red");
     $centroids->mark->SetWeight(10);
     $centroids->mark->SetWidth(50);
     $centroids->value->SetColor("black");
     // Add plots to graph.
     $graph->Add($centroids);
     //$graph->Add($scatterplots);
     $graph->xaxis->title->Set('Followers Similarity');
     $graph->yaxis->title->Set('Followings Similarity');
     $graph->yaxis->title->SetMargin(10);
     // Display graph
     $graph->Stroke();
 }
예제 #4
0
     header("Location:index.php");
     exit;
 }
 //echo count($response);
 if (count($response) > 2) {
     //menyimpan data profil user ke tabel user
     $user = new User();
     $user->id = $response['id'];
     $user->name = $response['name'];
     $user->screen_name = $response['screen_name'];
     $user->followers_count = $response['followers_count'];
     $user->friends_count = $response['friends_count'];
     $user->statuses_count = $response['statuses_count'];
     $user->location = $response['location'];
     $user->profile_image_url = $response['profile_image_url'];
     $user_dao = new User_dao();
     $user_dao->deleteAll();
     //menghapus data user yang telah ada di tabel user
     $user_dao->add($user);
     //menyimpan data user ke tabel user berdasarkan hasil input
     //mengambil data follower dari user dan menyimpannya ke tabel follower
     $followers_url = "http://api.twitter.com/1/statuses/followers/{$user->id}.json";
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $followers_url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $curlout = curl_exec($ch);
     curl_close($ch);
     $followers = json_decode($curlout, true);
     $follower_dao = new Follower_dao();
     $follower_dao->deleteAll();
     foreach ($followers as $myfollowers) {