public function testGetClientVisualizationData() { $client_data = array('Client 1' => 50, 'Client 2' => 10); $result = DashboardModuleCacher::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); }
/** * 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')); if (is_array($all_time_clients_usage)) { // The sliceVisibilityThreshold option in the chart will prevent small slices from being created $all_time_clients_usage = DashboardModuleCacher::getClientUsageVisualizationData($all_time_clients_usage); $this->addToView('all_time_clients_usage', $all_time_clients_usage); } if (is_array($latest_clients_usage) && sizeof($latest_clients_usage > 1)) { // 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."); } }
/** * 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); } $yearly_popular = $insight_dao->getPreCachedInsightData('PostMySQLDAO::getMostPopularPostsOfTheYear', $this->instance->id, date('Y-m-d')); if (isset($yearly_popular)) { if (date('n') == 12) { $yearly_popular_year = date('Y'); } else { $yearly_popular_year = intval(date('Y')) - 1; } $this->addToView('yearly_popular', $yearly_popular); $this->addToView('yearly_popular_year', $yearly_popular_year); } $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')); if (is_array($all_time_clients_usage)) { // The sliceVisibilityThreshold option in the chart will prevent small slices from being created $all_time_clients_usage = DashboardModuleCacher::getClientUsageVisualizationData($all_time_clients_usage); $this->addToView('all_time_clients_usage', $all_time_clients_usage); } if (is_array($latest_clients_usage) && sizeof($latest_clients_usage > 1)) { // 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); } $posts_flashback = $insight_dao->getPreCachedInsightData('PostMySQLDAO::getOnThisDayFlashbackPosts', $this->instance->id, date('Y-m-d')); $this->addToView('posts_flashback', $posts_flashback); // Foursquare items if ($this->instance->network == "foursquare") { // Checkins per hour $checkins_per_hour = $insight_dao->getPreCachedInsightData('PostMySQLDAO::getPostsPerHourDataVis', $this->instance->id, date('Y-m-d')); $this->addToView('checkins_per_hour', $checkins_per_hour); // Checkins by type of place - all time $place_types = $insight_dao->getPreCachedInsightData('PostMySQLDAO::countCheckinsToPlaceTypes', $this->instance->id, date('Y-m-d')); $this->addToView('checkins_by_type', $place_types); // Checkins by type of place - last week $place_types_last_week = $insight_dao->getPreCachedInsightData('PostMySQLDAO::countCheckinsToPlaceTypesLastWeek', $this->instance->id, date('Y-m-d')); $this->addToView('checkins_by_type_last_week', $place_types_last_week); // Map of checkins in the last week $checkins_map = $insight_dao->getPreCachedInsightData('PostMySQLDAO::getAllCheckinsInLastWeekAsGoogleMap', $this->instance->id, date('Y-m-d')); $this->addToView('checkins_map', $checkins_map); } } else { $this->addErrorMessage($username . " on " . ucwords($this->instance->network) . " isn't set up on this ThinkUp installation."); } }