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(); }
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"); $k = $_POST['k'];
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); } }