Ejemplo n.º 1
0
 public function testGetClientVisualizationData()
 {
     $client_data = array('Client 1' => 50, 'Client 2' => 10);
     $result = InsightsGenerator::getClientUsageVisualizationData($client_data);
     $this->assertEqual(gettype($result), 'string');
     $visualization_object = json_decode($result);
     $this->assertEqual(sizeof($visualization_object->rows), 2);
     $this->assertEqual(sizeof($visualization_object->cols), 2);
     $this->assertEqual($visualization_object->cols[0]->label, 'Client');
     $this->assertEqual($visualization_object->cols[1]->label, 'Posts');
     $this->assertEqual($visualization_object->rows[0]->c[0]->v, 'Client 1');
     $this->assertEqual($visualization_object->rows[0]->c[0]->f, 'Client 1');
     $this->assertEqual($visualization_object->rows[0]->c[1]->v, 50);
     $this->assertEqual($visualization_object->rows[1]->c[0]->v, 'Client 2');
     $this->assertEqual($visualization_object->rows[1]->c[1]->v, 10);
 }
Ejemplo n.º 2
0
 /**
  * Load instance dashboard
  * @param str $username
  * @param str $network
  */
 private function loadDefaultDashboard()
 {
     if (isset($this->instance)) {
         $this->setPageTitle($this->instance->network_username . "'s Dashboard");
         $insight_dao = DAOFactory::getDAO('InsightDAO');
         $hot_posts_data = $insight_dao->getPreCachedInsightData('PostMySQLDAO::getHotPosts', $this->instance->id, date('Y-m-d'));
         if (isset($hot_posts_data)) {
             $this->addToView('hot_posts_data', $hot_posts_data);
         }
         $click_stats_data = $insight_dao->getPreCachedInsightData('ShortLinkMySQLDAO::getRecentClickStats', $this->instance->id, date('Y-m-d'));
         if (isset($click_stats_data)) {
             $this->addToView('click_stats_data', $click_stats_data);
         }
         $post_dao = DAOFactory::getDAO('PostDAO');
         $most_replied_to_1wk = $insight_dao->getPreCachedInsightData('PostMySQLDAO::getMostRepliedToPostsInLastWeek', $this->instance->id, date('Y-m-d'));
         $this->addToView('most_replied_to_1wk', $most_replied_to_1wk);
         $most_retweeted_1wk = $insight_dao->getPreCachedInsightData('PostMySQLDAO::getMostRetweetedPostsInLastWeek', $this->instance->id, date('Y-m-d'));
         $this->addToView('most_retweeted_1wk', $most_retweeted_1wk);
         //for now, only show most liked/faved posts on Facebook dashboard
         //once we cache fave counts for Twitter, we can remove this conditional
         if ($this->instance->network == "facebook" || $this->instance->network == "facebook page" || $this->instance->network == "google+") {
             $most_faved_1wk = $post_dao->getMostFavedPostsInLastWeek($this->instance->network_username, $this->instance->network, 5);
             $this->addToView('most_faved_1wk', $most_faved_1wk);
         }
         //follows - these are pre-cached in insights
         $least_likely_followers = $insight_dao->getPreCachedInsightData('FollowMySQLDAO::getLeastLikelyFollowersThisWeek', $this->instance->id, date('Y-m-d'));
         $this->addToView('least_likely_followers', $least_likely_followers);
         //follower count history
         //by day
         $follower_count_dao = DAOFactory::getDAO('FollowerCountDAO');
         $follower_count_history_by_day = $follower_count_dao->getHistory($this->instance->network_user_id, $this->instance->network, 'DAY', 5);
         $this->addToView('follower_count_history_by_day', $follower_count_history_by_day);
         //by week
         $follower_count_history_by_week = $follower_count_dao->getHistory($this->instance->network_user_id, $this->instance->network, 'WEEK', 5);
         $this->addToView('follower_count_history_by_week', $follower_count_history_by_week);
         list($all_time_clients_usage, $latest_clients_usage) = $insight_dao->getPreCachedInsightData('PostMySQLDAO::getClientsUsedByUserOnNetwork', $this->instance->id, date('Y-m-d'));
         $this->addToView('most_replied_to_1wk', $most_replied_to_1wk);
         // The sliceVisibilityThreshold option in the chart will prevent small slices from being created
         $all_time_clients_usage = InsightsGenerator::getClientUsageVisualizationData($all_time_clients_usage);
         $this->addToView('all_time_clients_usage', $all_time_clients_usage);
         // Only show the two most used clients for the last 25 posts
         $latest_clients_usage = array_slice($latest_clients_usage, 0, 2);
         $this->addToView('latest_clients_usage', $latest_clients_usage);
     } else {
         $this->addErrorMessage($username . " on " . ucwords($this->instance->network) . " isn't set up on this ThinkUp installation.");
     }
 }