public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $year = date('Y'); $regenerate = false; //testing //$regenerate = true; $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $top_three_replied_to = $this->topThreeThisYear($instance); foreach ($top_three_replied_to as $key => $post) { $post->author_avatar = $user->avatar; } //Populate Instagram photos if ($instance->network == 'instagram') { $photo_dao = DAOFactory::getDAO('PhotoDAO'); $popular_photos = array(); foreach ($top_three_replied_to as $key => $post) { $post = $photo_dao->getPhoto($post->post_id, 'instagram'); $popular_photos[] = $post; } $top_three_replied_to = $popular_photos; } $post_dao = DAOFactory::getDAO('PostDAO'); $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = ""; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = " (at least since " . $since . ")"; } } $copy = array('twitter' => array('normal' => array('headline' => "%username's most replied-to tweets of %year", 'body' => "Come for the faves, stay for the mentions. " . "In %year, %username inspired the most conversation in " . "these tweets%qualified_year."), 'one' => array('headline' => "%username's most replied-to tweet of %year", 'body' => "Come for the faves, stay for the mentions. " . "In %year, %username inspired the most conversation in " . "this tweet%qualified_year."), 'none' => array('headline' => "Let's talk", 'body' => "%username didn't get any replies in %year" . $qualified_year . ", but that's " . "about to change. Give @thinkup a mention — we love to talk!")), 'facebook' => array('normal' => array('headline' => "%username's most commented-on status updates of %year", 'body' => "Some status updates are meant to " . "be trivial. Others sow the seeds of meaningful " . "conversation. In %year, %username received the most comments " . "on these status updates%qualified_year."), 'one' => array('headline' => "%username's most commented-on status update of %year", 'body' => "Some status updates are meant to " . "be trivial. Others sow the seeds of meaningful " . "conversation. In %year, %username received the most comments " . "on this status update%qualified_year."), 'none' => array('headline' => "No comment", 'body' => "Is this thing on? No one commented on %username's " . "status updates on Facebook in %year" . $qualified_year . ".")), 'instagram' => array('normal' => array('headline' => "%username's most commented-on Instagram posts of %year", 'body' => "There's lots of eye candy on Instagram, and not much conversation. " . "But some photos and videos are so good people can't help but respond. " . "In %year, %username received the most comments " . "on these Instagram posts%qualified_year."), 'one' => array('headline' => "%username's most commented-on Instagram of %year", 'body' => "There's lots of eye candy on Instagram, and not much conversation. " . "But some photos and videos are so good people can't help but respond. " . "In %year, %username received the most comments " . "on these Instagram posts%qualified_year."), 'none' => array('headline' => "No comment", 'body' => "Is this thing on? No one commented on %username's " . "Instagram photos and videos in %year" . $qualified_year . "."))); $network = $instance->network; if (sizeof($top_three_replied_to) > 1) { $type = 'normal'; } else { if (sizeof($top_three_replied_to) == 1) { $type = 'one'; } else { $type = 'none'; } } $insight->headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year)); $insight->text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'qualified_year' => $qualified_year)); $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->filename = basename(__FILE__, ".php"); $insight->setPosts($top_three_replied_to); $this->insight_dao->insertInsight($insight); $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); } }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $video_dao = DAOFactory::getDAO('VideoDAO'); $filename = basename(__FILE__, ".php"); foreach ($last_week_of_posts as $post) { if ($post->network == 'youtube') { $video = $video_dao->getVideoByID($post->post_id, 'youtube'); $simplified_post_date = date('Y-m-d', strtotime($video->pub_date)); } else { break; } // Get the average baselines $total_likes_and_dislikes = $video->likes + $video->dislikes; $percent_likes = round($video->likes / $total_likes_and_dislikes * 100, 2); $percent_dislikes = round($video->dislikes / $total_likes_and_dislikes * 100, 2); // If the video splits opinion in the range of 60/40 likes / dislikes or 40/60 likes / dislikes if ($percent_likes >= 40 && $percent_likes <= 60) { $headline = $video->post_text . " really touched a nerve!"; $insight_text = "{$percent_likes}" . "% of people liked "; $insight_text .= "<a href=\"http://plus.google.com/{$instance->network_user_id}/about\">" . $instance->network_username; $insight_text .= '</a>\'s video '; $insight_text .= "<a href=\"http://www.youtube.com/watch?v={$post->post_id}\">" . $video->post_text . "</a> "; $insight_text .= "and " . $percent_dislikes . "% disliked it."; $this->insight_dao->insertInsightDeprecated("split_opinions" . $video->id, $instance->id, $simplified_post_date, $headline, $insight_text, $filename, 1, serialize($video)); } } }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $baseline_dao = DAOFactory::getDAO('InsightBaselineDAO'); foreach ($this->getSchedule() as $baseline_slug => $data) { $now = TimeHelper::getTime(); if ($now >= strtotime($data['start']) && $now <= strtotime($data['end'])) { $this->logger->logInfo("{$now} is in-schedule", __METHOD__ . ',' . __LINE__); $baseline = $baseline_dao->getMostRecentInsightBaseline($baseline_slug, $instance->id); if (!$baseline) { if ($instance->network == 'facebook' && date('w') == 4 || $instance->network == 'twitter' && date('w') == 1 || Utils::isTest()) { $found = $this->runInsightForConfig($data, $instance); $baseline_dao->insertInsightBaseline($baseline_slug, $instance->id, $found); } else { $this->logger->logInfo("Not today", __METHOD__ . ',' . __LINE__); } } else { $this->logger->logInfo("Already exists", __METHOD__ . ',' . __LINE__); } } else { $this->logger->logInfo("Not in-schedule", __METHOD__ . ',' . __LINE__); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); if (self::shouldGenerateInsight('favorited_links', $instance, $insight_date = 'today', $regenerate_existing_insight = true)) { $fpost_dao = DAOFactory::getDAO('FavoritePostDAO'); $favorited_posts = $fpost_dao->getAllFavoritePosts($instance->network_user_id, $instance->network, 40); $todays_favorited_posts_with_links = array(); foreach ($favorited_posts as $post) { if (date('Y-m-d', strtotime($post->pub_date)) == date('Y-m-d')) { $post_text = $post->post_text; $text_parser = new Twitter_Extractor($post_text); $elements = $text_parser->extract(); if (count($elements['urls'])) { $todays_favorited_posts_with_links[] = $post; } } } $favorited_links_count = count($todays_favorited_posts_with_links); if ($favorited_links_count) { $verb = ''; $post_type = ''; if ($favorited_links_count == 1) { $insight_text = $this->username . " " . $this->terms->getVerb('liked') . " <strong>1 " . $this->terms->getNoun('post') . "</strong> with a link in it."; } else { $insight_text = $this->username . " " . $this->terms->getVerb('liked') . " <strong>" . $favorited_links_count . " " . $this->terms->getNoun('post', InsightTerms::PLURAL) . "</strong> with links in them:"; } $this->insight_dao->insertInsightDeprecated("favorited_links", $instance->id, $this->insight_date, "Links you liked:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW, serialize($todays_favorited_posts_with_links)); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); //Set up DAOs $instance_hashtag_dao = DAOFactory::getDAO('InstanceHashtagDAO'); $hashtag_post_dao = DAOFactory::getDAO('HashtagPostDAO'); $hashtag_dao = DAOFactory::getDAO('HashtagDAO'); // Get all the hashtags for the instance $instance_hashtags = $instance_hashtag_dao->getByInstance($instance->id); // foreach hashtag, get the count of new posts foreach ($instance_hashtags as $instance_hashtag) { $total_new_posts = $hashtag_post_dao->getTotalPostsByHashtagAndDate($instance_hashtag->hashtag_id); //Only insert insight if there are new results if ($total_new_posts > 0) { //Assemble insight text $post_term = $instance->network == 'twitter' ? 'tweets' : 'posts'; $hashtag = $hashtag_dao->getHashtagByID($instance_hashtag->hashtag_id); $link = 'search.php?u=' . $instance->network_username . '&n=' . $instance->network . '&c=searches&k=' . urlencode($hashtag->hashtag) . '&q=' . urlencode($hashtag->hashtag); $text = number_format($total_new_posts) . " new " . $post_term . " contain <b><a href=\"" . $link . "\">" . $hashtag->hashtag . "</a></b>."; // Insert insight $this->insight_dao->insertInsightDeprecated("saved_search_results_" . $instance_hashtag->hashtag_id, $instance->id, $this->insight_date, "New search results:", $text, basename(__FILE__, ".php"), Insight::EMPHASIS_MED); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); if ($this->shouldGenerateInsight($this->slug, $instance, $insight_date = 'today', $regenerate = false)) { $baseline_dao = DAOFactory::getDAO('InsightBaselineDAO'); $met_milestone = 0; foreach ($this->milestones as $count => $text) { if ($user->follower_count > $count && $user->follower_count < $count * 2) { $met_milestone = $count; } else { if ($user->follower_count < $count) { break; } } } if ($met_milestone) { $baseline = $baseline_dao->getMostRecentInsightBaseline('follower_vis_last_run', $instance->id); if (!isset($baseline->value) || isset($baseline->value) && $met_milestone > $baseline->value) { $baseline_dao->insertInsightBaseline('follower_vis_last_run', $instance->id, $met_milestone); $insight = new Insight(); $insight->slug = $this->slug; $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->headline = $this->getVariableCopy(array($this->milestones[$met_milestone]['headline']), array('total' => number_format($user->follower_count))); $insight->text = $this->getVariableCopy(array($this->milestones[$met_milestone]['text']), array('total' => number_format($user->follower_count), 'thres' => number_format($met_milestone))); $insight->setHeroImage($this->milestones[$met_milestone]["hero_image"]); $this->insight_dao->insertInsight($insight); } } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $network = $instance->network; $user_id = $instance->network_user_id; if ($network == 'twitter' && $this->shouldGenerateMonthlyInsight($this->slug, $instance, 'today', false, 8)) { $my_count = $user->follower_count; $follow_dao = DAOFactory::getDAO('FollowDAO'); $follow_count = $follow_dao->countTotalFriends($user_id, $network); $median = $follow_dao->getMedianFollowerCountOfFriends($user_id, $network); $number_under = $follow_dao->getCountOfFriendsWithFewerFollowers($user_id, $network, $my_count); $rank = $follow_count - $number_under + 1; $percentile = (int) sprintf('%d', 100 * ($number_under / $follow_count)); if ($percentile >= 50 && $my_count > $median) { $insight = new Insight(); $insight->slug = $this->slug; $insight->date = $this->insight_date; $insight->instance_id = $instance->id; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_MED; $insight->headline = $this->getVariableCopy(array('%username has it good', 'A closer look at %username\'s follower count', '%username could lend a hand')); $insight->text = $this->getVariableCopy(array("%username has more followers than %percentile% of the %total people %username follows. That means " . "<strong>%percentoftotal</strong> of %username's friends would reach a bigger audience " . "if %username retweeted them.", "%username has more followers than %percentile% of the people %username follows. That means " . "<strong>%percentoftotal</strong> of %username's friends would reach a bigger audience " . "if %username retweeted them."), array('total' => number_format($follow_count), 'percentoftotal' => number_format($number_under), 'percentile' => $percentile)); $this->insight_dao->insertInsight($insight); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $since_date = date("Y-m-d"); $insight_date = new DateTime(); $insight_day_of_week = (int) $insight_date->format('w'); $insight_day_of_month = (int) $insight_date->format('j'); $filename = basename(__FILE__, ".php"); if ($insight_day_of_month == 1) { //it's the first day of the month // Past 30 days if (self::shouldGenerateInsight('biggest_fans_last_30_days', $instance, $insight_date = $since_date)) { $fav_dao = DAOFactory::getDAO('FavoritePostDAO'); $fans = $fav_dao->getUsersWhoFavoritedMostOfYourPosts($instance->network_user_id, $instance->network, 30); if (isset($fans) && sizeof($fans) > 0) { $this->insight_dao->insertInsightDeprecated("biggest_fans_last_30_days", $instance->id, $since_date, "Biggest fans:", "People who " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " the most over the last 30 days: ", $filename, Insight::EMPHASIS_LOW, serialize($fans)); } } } else { if ($insight_day_of_week == 0) { //it's Sunday // Past 7 days if (self::shouldGenerateInsight('biggest_fans_last_7_days', $instance, $insight_date = $since_date)) { $fav_dao = DAOFactory::getDAO('FavoritePostDAO'); $fans = $fav_dao->getUsersWhoFavoritedMostOfYourPosts($instance->network_user_id, $instance->network, 7); if (isset($fans) && sizeof($fans) > 0) { $this->insight_dao->insertInsightDeprecated("biggest_fans_last_7_days", $instance->id, $since_date, "Biggest fans:", "People who " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " the most over the last 7 days: ", $filename, Insight::EMPHASIS_LOW, serialize($fans)); } } } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $filename = basename(__FILE__, ".php"); foreach ($last_week_of_posts as $post) { $simplified_post_date = date('Y-m-d', strtotime($post->pub_date)); // Map insight: If not a reply or retweet and geoencoded, show the map in the stream if (!isset($post->in_reply_to_user_id) && !isset($post->in_reply_to_post_id) && !isset($post->in_retweet_of_post_id) && $post->reply_count_cache > 5) { $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO'); $options = $plugin_option_dao->getOptionsHash('geoencoder', true); if (isset($options['gmaps_api_key']->option_value) && $post->is_geo_encoded == 1) { //Get post's replies and loop through them to make sure at least 5 are indeed geoencoded $post_dao = DAOFactory::getDAO('PostDAO'); $post_replies = $post_dao->getRepliesToPost($post->post_id, $post->network); $total_geoencoded_replies = 0; foreach ($post_replies as $reply) { if ($reply->is_geo_encoded == 1) { $total_geoencoded_replies++; } } if ($total_geoencoded_replies > 4) { $this->insight_dao->insertInsight('geoencoded_replies', $instance->id, $simplified_post_date, "Going global!", "{$this->username}'s post got responses from locations all over the map.", $filename, Insight::EMPHASIS_LOW, serialize($post)); } } } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $filename = basename(__FILE__, ".php"); foreach ($last_week_of_posts as $post) { //if post was a retweet, check if insight exists if ($post->in_retweet_of_post_id != null && $post->in_rt_of_user_id != null) { $simplified_post_date = date('Y-m-d', strtotime($post->pub_date)); //if insight doesn't exist fetch user details of original author and instance if (self::shouldGenerateInsight('amplifier_' . $post->id, $instance, $insight_date = $simplified_post_date)) { if (!isset($user_dao)) { $user_dao = DAOFactory::getDAO('UserDAO'); } if (!isset($instance_user)) { $instance_user = $user_dao->getDetails($post->author_user_id, $post->network); } $retweeted_user = $user_dao->getDetails($post->in_rt_of_user_id, $post->network); //if user exists and has fewer followers than instance user, build and insert insight if (isset($retweeted_user) && $retweeted_user->follower_count < $instance_user->follower_count) { $add_audience = number_format($instance_user->follower_count - $retweeted_user->follower_count); $insight_text = "{$this->username} broadcast this post to <strong>{$add_audience}</strong> " . "more people than its author originally reached."; $this->insight_dao->insertInsightDeprecated('amplifier_' . $post->id, $instance->id, $simplified_post_date, "Amplifier:", $insight_text, $filename, Insight::EMPHASIS_LOW, serialize($post)); } } } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $possible_messaging = array(array('headline' => 'Ohai', 'text' => 'Greetings, humans', 'header_image' => 'http://farm3.staticflickr.com/2713/4098259769_725b5fb65b_o.jpg'), array('headline' => 'Hello', 'text' => 'Greetings, earthlings', 'header_image' => 'http://farm9.staticflickr.com/8078/8276342554_5a51725f5f_n.jpg'), array('headline' => 'Yo', 'text' => 'Greetings, peeps', 'header_image' => 'http://farm6.staticflickr.com/5006/5367216303_83c5f2dc39_n.jpg')); //Instantiate the Insight object $my_insight = new Insight(); //REQUIRED: Set the insight's required attributes //We pull some from the options above. But the could just be strings like 'Ohai' $which_messaging = TimeHelper::getTime() % count($possible_messaging); foreach ($possible_messaging[$which_messaging] as $field => $value) { $my_insight->{$field} = $value; } $my_insight->slug = 'my_test_insight_hello_thinkup'; //slug to label this insight's content $my_insight->instance_id = $instance->id; $my_insight->date = $this->insight_date; //date is often this or $simplified_post_date $my_insight->filename = basename(__FILE__, ".php"); //Same for every insight, must be set exactly this way $my_insight->emphasis = Insight::EMPHASIS_MED; //Set emphasis optionally, default is Insight::EMPHASIS_LOW //OPTIONAL: Attach related data of various types using Insight setter functions //$my_insight->setPosts($my_insight_posts); //$my_insight->setLinks($my_insight_links); //$my_insight->setPeople($my_insight_people); //$my_insight->setMilestones($my_insight_milestones); //etc $this->insight_dao->insertInsight($my_insight); $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $filename = basename(__FILE__, ".php"); $follow_dao = DAOFactory::getDAO('FollowDAO'); // Least likely followers based on follower-to-followee ratio $least_likely_followers = $follow_dao->getLeastLikelyFollowersByDay($instance->network_user_id, $instance->network, 0, 3); if (sizeof($least_likely_followers) > 0) { //if not null, store insight if (sizeof($least_likely_followers) > 1) { $this->insight_dao->insertInsightDeprecated('least_likely_followers', $instance->id, $this->insight_date, "Standouts:", '<strong>' . sizeof($least_likely_followers) . " interesting users</strong> " . "followed {$this->username}.", $filename, Insight::EMPHASIS_LOW, serialize($least_likely_followers)); } else { $this->insight_dao->insertInsightDeprecated('least_likely_followers', $instance->id, $this->insight_date, "Standout:", "An interesting user followed {$this->username}.", $filename, Insight::EMPHASIS_LOW, serialize($least_likely_followers)); } } // Verified followers $verified_followers = $follow_dao->getVerifiedFollowersByDay($instance->network_user_id, $instance->network, 0, 3); if (sizeof($verified_followers) > 0) { //if not null, store insight if (sizeof($verified_followers) > 1) { $this->insight_dao->insertInsightDeprecated('verified_followers', $instance->id, $this->insight_date, "Verified followers!", '<strong>' . sizeof($verified_followers) . " verified users</strong> " . "followed {$this->username}.", $filename, Insight::EMPHASIS_LOW, serialize($verified_followers)); } else { $this->insight_dao->insertInsightDeprecated('verified_followers', $instance->id, $this->insight_date, "Verified follower!", "A verified user followed {$this->username}.", $filename, Insight::EMPHASIS_LOW, serialize($verified_followers)); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $archived_posts_in_hundreds = intval($instance->total_posts_in_system / 100); if ($archived_posts_in_hundreds > 0) { $insight_baseline_slug = "archived_posts_" . $archived_posts_in_hundreds; $insight_baseline_dao = DAOFactory::getDAO('InsightBaselineDAO'); if (!$insight_baseline_dao->doesInsightBaselineExist($insight_baseline_slug, $instance->id)) { $insight_baseline_dao->insertInsightBaseline($insight_baseline_slug, $instance->id, $archived_posts_in_hundreds); $config = Config::getInstance(); switch ($instance->network) { case "twitter": $posts_term = "tweets"; break; case "foursquare": $posts_term = "checkins"; break; default: $posts_term = "posts"; } $text = "ThinkUp has captured over <strong>" . number_format($archived_posts_in_hundreds * 100) . ' ' . $posts_term . '</strong> by ' . $this->username . '.'; $this->insight_dao->insertInsight("archived_posts", $instance->id, $this->insight_date, "Archived:", $text, basename(__FILE__, ".php"), Insight::EMPHASIS_MED); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $existing_insight = $this->insight_dao->getInsight("posts_on_this_day_popular_flashback", $instance->id, $this->insight_date); if (!isset($existing_insight)) { //Generate flashback post list $post_dao = DAOFactory::getDAO('PostDAO'); $flashback_posts = $post_dao->getOnThisDayFlashbackPosts($instance->network_user_id, $instance->network, $this->insight_date); $most_popular_post = null; $most_responses = 0; if (isset($flashback_posts) && sizeof($flashback_posts) > 0) { foreach ($flashback_posts as $post) { $total_responses = $post->reply_count_cache + $post->all_retweets + $post->favlike_count_cache; if ($total_responses > 0 && $total_responses > $most_responses) { $most_popular_post = $post; $most_responses = $total_responses; } } if (isset($most_popular_post)) { $post_year = date(date('Y', strtotime($most_popular_post->pub_date))); $current_year = date('Y'); $number_of_years_ago = $current_year - $post_year; $plural = $number_of_years_ago > 1 ? 's' : ''; $insight_text = "{$this->username}'s most popular post <strong>{$number_of_years_ago} year{$plural} ago" . "</strong> today was:"; $this->insight_dao->insertInsight("posts_on_this_day_popular_flashback", $instance->id, $this->insight_date, "Time machine:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW, serialize($most_popular_post)); } } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { if ($instance->network == 'twitter' || $instance->network == 'test_no_monthly') { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $monthly = 0; $weekly = 0; if ($instance->network == 'twitter') { $weekly = 6; $monthly = 28; } else { if ($instance->network == 'test_no_monthly') { $monthly = 0; $weekly = 2; } } $did_monthly = false; if ($monthly && self::shouldGenerateMonthlyInsight($this->slug, $instance, 'today', false, $monthly)) { $post_dao = DAOFactory::getDAO('PostDAO'); $posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = date('t'), $iterator = false, $is_public = false); $this->generateMonthlyInsight($instance, $posts); $did_monthly = true; } $do_weekly = $weekly && !$did_monthly; if ($do_weekly && self::shouldGenerateWeeklyInsight($this->slug, $instance, 'today', false, $weekly)) { $this->generateWeeklyInsight($instance, $last_week_of_posts); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); } }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); //Instantiate the Insight object $my_insight = new Insight(); //REQUIRED: Set the insight's required attributes $my_insight->instance_id = 1; $my_insight->slug = 'my_test_insight_hello_thinkup'; //slug to label this insight's content $my_insight->date = '2013-12-21'; //date of the data this insight applies to $my_insight->headline = 'Ohai'; $my_insight->text = "Greetings humans"; $my_insight->emphasis = Insight::EMPHASIS_MED; //Set emphasis optionally, default is Insight::EMPHASIS_LOW $my_insight->filename = basename(__FILE__, ".php"); //Same for every insight, must be set exactly this way //OPTIONAL: Attach related data of various types using Insight setter functions //$my_insight->setPosts($my_insight_posts); //$my_insight->setLinks($my_insight_links); //$my_insight->setPeople($my_insight_people); //etc $this->insight_dao->insertInsight($my_insight); $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $year = date('Y'); $regenerate = false; //testing //$regenerate = true; $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $network = $instance->network; $count = 0; $post_dao = DAOFactory::getDAO('PostDAO'); $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network); $total_posts = 0; foreach ($last_year_of_posts as $post) { $count += AllAboutYouInsight::hasFirstPersonReferences($post->post_text) ? 1 : 0; $total_posts++; } $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = ""; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = " (at least since " . $since . ")"; } } if ($instance->network == 'twitter') { $headline = $this->getVariableCopy(array("A year's worth of %username")); } elseif ($instance->network == 'instagram') { $headline = $this->getVariableCopy(array("A year of %username photos")); } else { $headline = $this->getVariableCopy(array("A year about %username")); } $percent = round($count / $total_posts * 100); if ($count > 0) { if ($instance->network == 'twitter' || $instance->network == 'facebook') { $insight_text = $this->getVariableCopy(array("In %year, <strong>{$percent}%</strong> of %username's %posts " . "— a grand total of %total — contained " . "the words “I”, “me”, “my”, " . "“mine”, or “myself”%qualified_year. " . ($instance->network == 'facebook' ? "Go ahead: tell your story" : "Sometimes, you've just got to get personal") . "."), array('total' => number_format($count), 'year' => $year, 'qualified_year' => $qualified_year)); } else { $insight_text = $this->getVariableCopy(array("In %year, <strong>{$percent}%</strong> of %username's Instagram captions " . "— a grand total of %total — contained " . "the words “I”, “me”, “my”, " . "“mine”, or “myself”%qualified_year. " . "What a life in pictures!"), array('total' => number_format($count), 'year' => $year, 'qualified_year' => $qualified_year)); } } else { $insight_text = $this->getVariableCopy(array("In %year, none of %username's %posts contained " . "the words “I”, “me”, “my”, " . "“mine”, or “myself”%qualified_year. Sometimes, " . "you've just got to get personal — unless you're " . "%username, apparently!"), array('total' => number_format($count), 'year' => $year, 'qualified_year' => $qualified_year)); } $insight->headline = $headline; $insight->text = $insight_text; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->header_image = $user->avatar; $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); if ($instance->network == 'twitter' || $instance->network == 'facebook') { if ($instance->network == 'facebook' && self::shouldGenerateWeeklyInsight($this->slug, $instance, 'today', false, 1)) { $run = true; } else { if ($instance->network == 'twitter' && self::shouldGenerateWeeklyInsight($this->slug, $instance, 'today', false, 5)) { $run = true; } } if ($run) { $photo_this_week = $this->findPostWithPhoto($last_week_of_posts); if (!$photo_this_week) { $post_dao = DAOFactory::getDAO('PostDAO'); $posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = 14, $iterator = false, $is_public = false); $photo_at_all = $this->findPostWithPhoto($posts); if ($photo_at_all) { $insight = new Insight(); $insight->slug = $this->slug; $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $days = floor((time() - strtotime($photo_at_all->pub_date)) / (60 * 60 * 24)); $insight->headline = $this->getVariableCopy(array("A great time for a pic", "%total days without a pic", "A thousand words unsaid"), array('total' => $days)); $insight->text = $this->username . " hasn't posted a photo in {$days} day" . ($days == 1 ? "" : "s") . ". " . "It might be worth finding something to share."; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_LOW; $this->insight_dao->insertInsight($insight); } } } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $post_dao = DAOFactory::getDAO('PostDAO'); $user_dao = DAOFactory::getDAO('UserDAO'); $service_user = $user_dao->getDetails($instance->network_user_id, $instance->network); $share_verb = $instance->network == 'twitter' ? 'retweeted' : 'reshared'; foreach ($last_week_of_posts as $post) { $big_reshares = $post_dao->getRetweetsByAuthorsOverFollowerCount($post->post_id, $instance->network, $service_user->follower_count); if (isset($big_reshares) && sizeof($big_reshares) > 0) { if (!isset($config)) { $config = Config::getInstance(); } $post_link = '<a href="' . $config->getValue('site_root_path') . 'post/?t=' . $post->post_id . '&n=' . $post->network . '&v=fwds">'; if (sizeof($big_reshares) > 1) { $notification_text = "People with lots of followers {$share_verb} " . $post_link . "{$this->username}'s post</a>."; } else { $follower_count_multiple = intval($big_reshares[0]->follower_count / $service_user->follower_count); if ($follower_count_multiple > 1) { $notification_text = "Someone with <strong>" . $follower_count_multiple . "x</strong> more followers than {$this->username} {$share_verb} " . $post_link . "this post</a>."; } else { $notification_text = "Someone with lots of followers {$share_verb} " . $post_link . "{$this->username}'s post</a>."; } } //Replace each big resharer's bio line with the text of the post foreach ($big_reshares as $sharer) { $sharer->description = '"' . $post->post_text . '"'; } $simplified_post_date = date('Y-m-d', strtotime($post->pub_date)); $this->insight_dao->insertInsight("big_reshare_" . $post->id, $instance->id, $simplified_post_date, "Big reshare!", $notification_text, basename(__FILE__, ".php"), Insight::EMPHASIS_HIGH, serialize($big_reshares)); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $filename = basename(__FILE__, ".php"); //get new group memberships per day $group_membership_dao = DAOFactory::getDAO('GroupMemberDAO'); $new_groups = $group_membership_dao->getNewMembershipsByDate($instance->network, $instance->network_user_id, $this->insight_date); if (sizeof($new_groups) > 0) { //if not null, store insight $group_membership_count_dao = DAOFactory::getDAO('GroupMembershipCountDAO'); $list_membership_count_history_by_day = $group_membership_count_dao->getHistory($instance->network_user_id, $instance->network, 'DAY', 15); if (sizeof($new_groups) > 1) { $group_name_list = ''; $group_number = 0; foreach ($new_groups as $group) { if (sizeof($new_groups) > 10) { //If more than 10 lists, just display first 10 if ($group_number >= 10) { if ($group_number == 10) { $group_name_list .= ", and " . (sizeof($new_groups) - 10) . " more"; } } else { if ($group_name_list != '') { $group_name_list .= ", "; } } if ($group_number < 10) { $group->setMetadata(); $group_name_list .= '<a href="' . $group->url . '">' . $group->keyword . '</a>'; } $group_number++; } else { //Display all lists if ($group == end($new_groups)) { $group_name_list .= " and "; } else { if ($group_name_list != '') { $group_name_list .= ", "; } } $group->setMetadata(); $group_name_list .= '<a href="' . $group->url . '">' . $group->keyword . '</a>'; } } $insight_text = "{$this->username} is on " . sizeof($new_groups) . " new lists: " . $group_name_list; if (end($list_membership_count_history_by_day['history']) > sizeof($new_groups)) { $insight_text .= ", bringing the total to <strong>" . number_format(end($list_membership_count_history_by_day['history'])) . " lists</strong>."; } else { $insight_text .= "."; } $this->insight_dao->insertInsight('new_group_memberships', $instance->id, $this->insight_date, "Made the list:", $insight_text, $filename, Insight::EMPHASIS_LOW, serialize($list_membership_count_history_by_day)); } else { $new_groups[0]->setMetadata(); $this->insight_dao->insertInsight('new_group_memberships', $instance->id, $this->insight_date, "Made the list:", "{$this->username} is on a new list, " . '<a href="' . $new_groups[0]->url . '">' . $new_groups[0]->keyword . "</a>, bringing the total to <strong>" . number_format(end($list_membership_count_history_by_day['history'])) . " lists</strong>.", $filename, Insight::EMPHASIS_LOW, serialize($list_membership_count_history_by_day)); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $regenerate = false; //testing // $regenerate = true; $year = date('Y'); $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $filename = basename(__FILE__, ".php"); $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $top_three_favliked = $this->topThreeThisYear($instance); foreach ($top_three_favliked as $key => $post) { if ($post->favlike_count_cache == 0) { unset($top_three_favliked[$key]); } else { //Avoid broken avatars $post->author_avatar = $user->avatar; } } $post_dao = DAOFactory::getDAO('PostDAO'); $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = $year; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = $year . " (at least since " . $since . ")"; } } $copy = array('twitter' => array('normal' => array('headline' => "%username's most-faved tweets of %year", 'body' => "In the Walk of Fame that is %username's Twitter " . "stream, these fan favorites earned the most stars in %qualified_year."), 'one' => array('headline' => "%username's most-faved tweet of %year", 'body' => "In the Walk of Fame that is %username's Twitter " . "stream, this fan favorite earned the most stars in %qualified_year."), 'none' => array('headline' => "What's in a fave?", 'body' => "%username didn't get any faves in %year, which is " . "crazy! Give @thinkup a mention and we'd be happy to " . "change that.")), 'facebook' => array('normal' => array('headline' => "%username's most-liked status updates of %year", 'body' => "Liked it? Nah. They LOVED it. These status updates " . "had %username's friends mashing the thumbs-up button the " . "most in %qualified_year."), 'one' => array('headline' => "%username's most-liked status update of %year", 'body' => "Liked it? Nah. They LOVED it. This status update " . "had %username's friends mashing the thumbs-up button the " . "most in %qualified_year."), 'none' => array('headline' => "Like, what's the deal?", 'body' => "No one liked %username's status updates on Facebook " . "in %year, but no biggie: We like %username plenty."))); $network = $instance->network; if (sizeof($top_three_favliked) > 1) { $type = 'normal'; } else { if (sizeof($top_three_favliked) == 1) { $type = 'one'; } else { $type = 'none'; } } $insight->headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year, 'qualified_year' => $qualified_year)); $insight->text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'qualified_year' => $qualified_year)); $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->filename = $filename; $insight->setPosts($top_three_favliked); $this->insight_dao->insertInsight($insight); $insight = null; } else { $this->logger->logInfo("Skipped generating insight", __METHOD__ . ',' . __LINE__); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
/** * Determine whether an insight should be generated or not. * @param str $slug slug of the insight to be generated * @param Instance $instance user and network details for which the insight has to be generated * @param date $insight_date date for which the insight has to be generated * @param bool $regenerate_existing_insight whether the insight should be regenerated over a day * @param int $day_of_week the day of week (0 for Sunday through 6 for Saturday) on which the insight should run * @param int $count_last_week_of_posts if set, wouldn't run insight if there are no posts from last week * @param arr $excluded_networks array of networks for which the insight shouldn't be run * @param bool $alternate_day whether today is an alternate day or not * @return bool $run whether the insight should be generated or not */ public function shouldGenerateInsight($slug, Instance $instance, $insight_date = null, $regenerate_existing_insight = false, $day_of_week = null, $count_last_week_of_posts = null, $excluded_networks = null, $alternate_day = true) { if (Utils::isTest()) { return true; } else { return $alternate_day && parent::shouldGenerateInsight($slug, $instance, $insight_date, $regenerate_existing_insight, $day_of_week, $count_last_week_of_posts, $excluded_networks); } }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); // $insight_dao = DAOFactory::getDAO('InsightDAO'); // // $insight_dao->insertInsight('hello_thinkup_insight', $instance->id, $this->insight_date, // "Hello ThinkUp:", "Hello insight world ".$instance->network_username, Insight::EMPHASIS_LOW); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $year = date('Y'); $regenerate = false; //testing //$regenerate = true; $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $count = 0; $post_dao = DAOFactory::getDAO('PostDAO'); $network = $instance->network; $last_year_of_posts = $post_dao->getThisYearOfPostsWithLinksIterator($author_id = $instance->network_user_id, $network = $network); $scored_pics = $this->getScoredPics($last_year_of_posts); $posts = $this->getMostPopularPics($instance, $scored_pics); $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = "."; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = " (at least since " . $since . ")."; } } $copy = array('twitter' => array('normal' => array('headline' => "%username's most popular picture on Twitter, %year", 'body' => "With tweets limited to 140 characters, a picture " . "is worth at least 1,000 characters. In %year, these were the " . "most popular pics %username shared on Twitter%qualified_year"), 'one' => array('headline' => "%username's most popular picture on Twitter, %year", 'body' => "With tweets limited to 140 characters, a picture " . "is worth at least 1,000 characters. In %year, this was the " . "most popular pic %username shared on Twitter%qualified_year"), 'none' => array('headline' => "%username must yearn for the text-only days of Twitter", 'body' => "%username didn't share any pics on Twitter this year%qualified_year " . "Bummer! On the plus side: %username probably doesn't need to worry about " . "leaked nudes!")), 'facebook' => array('normal' => array('headline' => "%username's most popular picture on Facebook, %year", 'body' => "What's a newsfeed without the photos? In %year, " . "these were the most popular pics %username shared on Facebook%qualified_year"), 'one' => array('headline' => "%username's most popular picture on Facebook, %year", 'body' => "What's a newsfeed without the photos? In %year, " . "this was the most popular pic %username shared on Facebook%qualified_year"), 'none' => array('headline' => "No photos on Facebook?", 'body' => "%username didn't share any pics on Facebook this year%qualified_year " . "Bummer! On the plus side: %username probably doesn't need to worry about " . "leaked nudes!"))); if (sizeof($posts) > 1) { $type = 'normal'; } else { if (sizeof($posts) == 1) { $type = 'one'; } else { $type = 'none'; } } $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year)); $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'qualified_year' => $qualified_year)); $insight->headline = $headline; $insight->text = $insight_text; //Avoid InsightFieldExceedsMaxLengthException $posts = array_slice($posts, 0, 12); //Avoid broken avatars foreach ($posts as $post) { $post->author_avatar = $user->avatar; } $insight->setPosts($posts); $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
/** * Determine whether an insight should be generated or not. * @param str $slug slug of the insight to be generated * @param Instance $instance user and network details for which the insight has to be generated * @param date $insight_date date for which the insight has to be generated * @param bool $regenerate_existing_insight whether the insight should be regenerated over a day * @param int $day_of_week the day of week (0 for Sunday through 6 for Saturday) on which the insight should run * @param int $count_last_week_of_posts if set, wouldn't run insight if there are no posts from last week * @param arr $excluded_networks array of networks for which the insight shouldn't be run * @param bool $alternate_day whether today is an alternate day or not * @return bool $run whether the insight should be generated or not */ public function shouldGenerateInsight($slug, Instance $instance, $insight_date = null, $regenerate_existing_insight = false, $day_of_week = null, $count_last_week_of_posts = null, $excluded_networks = null, $alternate_day = true) { $in_test_mode = isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS" || getenv("MODE") == "TESTS"; if ($in_test_mode) { return true; } else { return $alternate_day && parent::shouldGenerateInsight($slug, $instance, $insight_date, $regenerate_existing_insight, $day_of_week, $count_last_week_of_posts, $excluded_networks); } }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { if (Utils::isTest() || date("Y-m-d") == '2015-02-23') { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-02/oscars2015.jpg', 'alt_text' => 'Oprah got a Lego Oscar!', 'credit' => 'Photo: Disney | ABC Television Group', 'img_link' => 'https://www.flickr.com/photos/disneyabc/16620198142'); $post_dao = DAOFactory::getDAO('PostDAO'); $last_month_of_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = 30, $iterator = false, $is_public = false); if (self::shouldGenerateWeeklyInsight('oscars_2015', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = 1, count($last_month_of_posts))) { foreach ($last_month_of_posts as $post) { $this->logger->logInfo("Post text is: " . $post->post_text, __METHOD__ . ',' . __LINE__); // see if $post date is before the awards aired if ($post->pub_date < "2015-02-22 18:00:00") { $mentioned_oscar_winner = self::detectOscarWinnerReferences($post->post_text); $mentioned_oscar_loser = self::detectOscarLoserReferences($post->post_text); $oscar_mention_count = self::countOscarMentions($post->post_text); if ($mentioned_oscar_winner) { $this->logger->logInfo("Winner mention: {$mentioned_oscar_winner}", __METHOD__ . ',' . __LINE__); $insight_body = "{$this->username} was talking about {$mentioned_oscar_winner} before the " . "Academy Award winners were even announced!"; } else { $this->logger->logInfo("No winners mentioned, skipping insight. ", __METHOD__ . ',' . __LINE__); } if ($mentioned_oscar_loser) { $this->logger->logInfo("Loser mention: {$mentioned_oscar_loser}", __METHOD__ . ',' . __LINE__); $insight_body_suffix = " Looks like the Academy voters might have missed " . "{$this->username}'s " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " about " . $mentioned_oscar_loser . ", though."; } } } if ($insight_body_suffix) { $insight_text = $insight_body . $insight_body_suffix; } else { $insight_text = $insight_body; } if ($insight_body) { $headline = "Somebody was ready for the Oscars party!"; $my_insight = new Insight(); $my_insight->slug = 'oscars_2015'; //slug to label this insight's content $my_insight->instance_id = $instance->id; $my_insight->date = $this->insight_date; //date is often this or $simplified_post_date $my_insight->headline = $headline; // or just set a string like 'Ohai'; $my_insight->text = $insight_text; // or just set a strong like "Greetings humans"; $my_insight->filename = basename(__FILE__, ".php"); //Same for every insight, must be set this way $my_insight->emphasis = Insight::EMPHASIS_HIGH; //Optional emphasis, default Insight::EMPHASIS_LOW $my_insight->setHeroImage($hero_image); $this->insight_dao->insertInsight($my_insight); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); } }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $year = date('Y'); $regenerate = false; //testing //$regenerate = true; $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $count = 0; $post_dao = DAOFactory::getDAO('PostDAO'); $network = $instance->network; $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network); $scored_posts = $this->getScoredPosts($last_year_of_posts); $top_post = $this->getMostPopularPost($instance, $scored_posts); $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = $year . "."; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = $year . " (at least since " . $since . ")."; } } $copy = array('twitter' => array('normal' => array('headline' => "%username's most popular tweet of %year", 'body' => "We don't tweet for the glory, but a little " . "attention doesn't hurt. With <strong>%list_of_stats</strong>, " . "this is %username's most popular tweet of %qualified_year")), 'facebook' => array('normal' => array('headline' => "%username's most popular status update of %year", 'body' => "Sometimes you just say the right thing. With <strong>" . "%list_of_stats</strong>, this is %username's most " . "popular status update of %qualified_year"))); $stats = array(); if ($top_post->favlike_count_cache > 0) { $stats[] = $top_post->favlike_count_cache . " " . $this->terms->getNoun('like', $top_post->favlike_count_cache); } if ($top_post->retweet_count_cache > 0) { $stats[] = $top_post->retweet_count_cache . " " . $this->terms->getNoun('retweet', $top_post->retweet_count_cache); } if ($top_post->reply_count_cache > 0) { $stats[] = $top_post->reply_count_cache . " " . $this->terms->getNoun('reply', $top_post->reply_count_cache); } $list_of_stats = $this->makeList($stats); $type = 'normal'; $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year)); $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('qualified_year' => $qualified_year, 'list_of_stats' => $list_of_stats)); $insight->headline = $headline; $insight->text = $insight_text; $insight->setPosts(array($top_post)); $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $year = date('Y'); $regenerate = false; //testing //$regenerate = true; $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $i = 1; while ($i < 13) { $this->posts_per_month[$i] = array('post_id' => null, 'popularity_index' => 0); $i++; } $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $count = 0; $post_dao = DAOFactory::getDAO('PostDAO'); $network = $instance->network; $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network); $this->setScoredPosts($last_year_of_posts); $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = $year . "."; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = $year . " (at least since " . $since . ")."; $cut_off_posts = date('n', strtotime($earliest_pub_date)) - 1; $this->posts_per_month = array_slice($this->posts_per_month, $cut_off_posts); } } $top_posts = $this->getMostPopularPosts($instance); if (count($top_posts) < 3) { $this->logger->logInfo("Not enough top posts per month to generate", __METHOD__ . ',' . __LINE__); return; } $copy = array('twitter' => array('normal' => array('headline' => "%username's biggest tweets of each month in %year", 'body' => "Twelve months make a year, and this year's almost behind us. Take one last look " . "back at %username's biggest tweets of each month in %qualified_year")), 'facebook' => array('normal' => array('headline' => "%username's biggest posts of each month in %year", 'body' => "This year's about to enter the history books. For better or for worse, these were " . "%username's most popular status updates of each month of %qualified_year"))); $type = 'normal'; $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year)); $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('qualified_year' => $qualified_year)); $insight->headline = $headline; $insight->text = $insight_text; $insight->setPosts($top_posts); $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); if (self::shouldGenerateInsight('interactions', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = 3, count($last_week_of_posts), $excluded_networks = array('facebook', 'google+', 'foursquare', 'youtube'))) { $user_dao = DAOFactory::getDAO('UserDAO'); $mentions_count = array(); $mentions_info = array(); $insight_data = array(); foreach ($last_week_of_posts as $post) { $post_text = $post->post_text; // Extract mentions from post text $text_parser = new Twitter_Extractor($post_text); $elements = $text_parser->extract(); $mentions_in_post = $elements['mentions']; foreach ($mentions_in_post as $mention_in_post) { if ($mention_in_post == $instance->network_username) { // Don't count metweets continue; } else { $mentioned_user = $user_dao->getUserByName($mention_in_post, $instance->network); if (isset($mentioned_user)) { $mention_in_post = '@' . $mentioned_user->username; $mentions_info[$mention_in_post] = $mentioned_user; } else { $mention_in_post = '@' . $mention_in_post; } // Update mention count if (array_key_exists($mention_in_post, $mentions_count)) { $mentions_count[$mention_in_post]++; } else { $mentions_count[$mention_in_post] = 1; } } } } if (count($mentions_count)) { // Get most mentioned user arsort($mentions_count); $most_mentioned_user = each($mentions_count); // Add mentions to dataset foreach ($mentions_count as $mention => $count) { $mention_info['mention'] = $mention; $mention_info['count'] = $count; $mention_info['user'] = $mentions_info[$mention]; $insight_data[] = $mention_info; } } if (isset($most_mentioned_user)) { $insight_text = $this->username . " mentioned " . $most_mentioned_user['key'] . " <strong>" . $this->terms->getOccurrencesAdverb($most_mentioned_user['value']) . "</strong> last week."; $this->insight_dao->insertInsightDeprecated('interactions', $instance->id, $this->insight_date, "BFFs:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW, serialize($insight_data)); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $is_first_run = !$this->insight_dao->doesInsightExist($this->slug, $instance->id); $should_generate_insight = $this->shouldGenerateMonthlyInsight($this->slug, $instance, 'today', $regenerate = false, 3, $excluded_networks = array('instagram')); if ($instance->network == 'facebook' && ($is_first_run || $should_generate_insight)) { if ($is_first_run) { $number_of_posts = count($last_week_of_posts); $period = 'week'; } else { $post_dao = DAOFactory::getDAO('PostDAO'); $number_of_posts = $post_dao->countAllPostsByUserSinceDaysAgo($instance->network_user_id, $instance->network, date('t')); $period = 'month'; } if ($number_of_posts >= 4) { // at least a minute $insight = new Insight(); $insight->slug = $this->slug; $insight->emphasis = Insight::EMPHASIS_MED; $insight->filename = basename(__FILE__, ".php"); $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $insight->text = $this->postsToInsightText($number_of_posts); $insight->headline = $this->username . " " . $this->terms->getVerb('posted') . " " . number_format($number_of_posts) . " time" . ($number_of_posts == 1 ? '' : 's') . " in the past {$period}"; $this->insight_dao->insertInsight($insight); } } if ($instance->network == 'twitter') { $number_of_posts = $user->post_count; $hundreds_of_posts = intval($number_of_posts / 100); // At least a minute of posts and either 100 or the first run. if ($number_of_posts > 4 && ($archived_posts_in_hundreds > 0 || $is_first_run)) { $baseline_slug = "time_spent_" . $hundreds_of_posts; $baseline_dao = DAOFactory::getDAO('InsightBaselineDAO'); if (!$baseline_dao->doesInsightBaselineExist($baseline_slug, $instance->id)) { if ($hundreds_of_posts) { $baseline_dao->insertInsightBaseline($baseline_slug, $instance->id, $hundreds_of_posts); } $insight = new Insight(); $insight->slug = $this->slug; $insight->emphasis = Insight::EMPHASIS_MED; $insight->filename = basename(__FILE__, ".php"); $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $insight->text = $this->postsToInsightText($number_of_posts); $insight->headline = $this->username . " has tweeted " . number_format($number_of_posts) . " time" . ($number_of_posts == 1 ? '' : 's'); $this->insight_dao->insertInsight($insight); } } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }