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) { 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__); $has_never_run = !$this->insight_dao->doesInsightExist($this->slug, $instance->id); if (Utils::isTest() || $has_never_run && (date("Y-m-d") == '2015-06-27' || date("Y-m-d") == '2015-06-28')) { $this->logger->logInfo("Should generate insight", __METHOD__ . ',' . __LINE__); $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-06/white-house-rainbow.jpg', 'alt_text' => '1600 Pennsylvania Avenue', 'credit' => 'Photo: Jason Goldman', 'img_link' => 'https://twitter.com/Goldman44/status/614599247959322624'); $topics = array('lovewins' => array("LoveWins", "marriage equality", "scotus", "gay marriage", "pride")); $matches = array(); $matched_posts = array(); $matched = false; foreach ($last_week_of_posts as $post) { foreach ($topics as $key => $strings) { foreach ($strings as $string) { if (preg_match_all('/\\b' . strtolower($string) . '\\b/i', strtolower($post->post_text), $matches)) { $matched = true; $this->logger->logInfo("FOUND " . $string . " in " . $post->post_text, __METHOD__ . ',' . __LINE__); } else { $this->logger->logInfo("Didn't find " . $string . " in " . $post->post_text, __METHOD__ . ',' . __LINE__); } } } if ($matched) { $this->logger->logInfo("Matched post " . $post->post_text, __METHOD__ . ',' . __LINE__); $matched_posts[] = $post; } $matched = false; } if (count($matched_posts) > 0) { if ($instance->network == 'facebook') { $headline = $this->username . " had enough pride for all 50 states"; $insight_text = $this->username . ' joined the <a href="https://facebook.com/celebratepride">marriage equality celebration</a> ' . 'this week!'; } else { $headline = $this->username . " joined the #LoveWins celebration"; $insight_text = $this->username . ' was all about <a href="https://twitter.com/hashtag/LoveWins">marriage equality</a> ' . 'this week.'; } $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = date("Y-m-d"); $insight->headline = $headline; $insight->text = $insight_text; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->setHeroImage($hero_image); $matched_posts_sliced = array_slice($matched_posts, 0, 5); $insight->setPosts($matched_posts_sliced); $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 == 'facebook' && $this->shouldGenerateMonthlyInsight($slug, $instance, 'today', false, 15)) { $ok_to_generate = false; // Find the last time we prompted (or "beginning of time" if we have never prompted) $baseline_slug = 'facebook_profile_prompted'; $insight_baseline_dao = DAOFactory::getDAO('InsightBaselineDAO'); $last_baseline = $insight_baseline_dao->getMostRecentInsightBaseline($baseline_slug, $instance->id); $last_prompted = 0; if ($last_baseline) { $last_prompted = strtotime($last_baseline->date); } // Only prompt at most every other month. At least 57 days are between two 15ths of the month. $time_diff = time() - $last_prompted; if ($time_diff > 60 * 60 * 24 * 57) { // Swap for the FacebookInstance so we have profile_updated $facebook_instance_dao = DAOFactory::getDAO('FacebookInstanceDAO'); $instance = $facebook_instance_dao->get($instance->id); $profile_updated_ts = time(); if ($instance->profile_updated) { $profile_updated_ts = strtotime($instance->profile_updated); } $time_since_update = time() - $profile_updated_ts; if ($time_since_update > 60 * 60 * 24 * 60) { $ok_to_generate = true; } } if ($ok_to_generate) { $insight = new Insight(); $insight->slug = 'facebook_profile_prompt'; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_LOW; $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $months = floor($time_since_update / (60 * 60 * 24 * 30)); $insight->headline = $this->getVariableCopy(array("%username's %months-month-old profile", "%username's Facebook profile is a little stale"), array('months' => $months)); if (date('Y') == date('Y', $profile_updated_ts)) { $nice_date = date('F jS', $profile_updated_ts); } else { $nice_date = date('F jS, Y', $profile_updated_ts); } $insight->text = $this->getVariableCopy(array("%username's Facebook profile hasn't been updated since {$nice_date}. " . "Might be worth checking if it's still up to date. ", "%username's Facebook profile hasn't been updated since {$nice_date}. " . "Can't hurt to see if that profile info is still accurate. ")); $insight->setButton(array('label' => 'Edit Facebook Profile', 'url' => 'https://www.facebook.com/me?sk=info&edit=eduwork&ref=update_info_button')); $this->insight_dao->insertInsight($insight); $insight_baseline_dao->insertInsightBaseline($baseline_slug, $instance->id, $months); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { if (Utils::isTest() || date("Y-m-d") == '2014-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/2014-02/olympics2014.jpg', 'alt_text' => 'The Olympic rings in Sochi', 'credit' => 'Photo: Atos International', 'img_link' => 'http://www.flickr.com/photos/atosorigin/12568057033/'); $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('olympics_2014', $instance, $insight_date = 'today', $regenerate_existing_insight = true, $day_of_week = 0, count($last_month_of_posts))) { $event_count = 0; foreach ($last_month_of_posts as $post) { $event_count += self::countOlympicReferences($post->post_text); } $this->logger->logInfo("There are {$event_count} Olympic-related mentions", __METHOD__ . ',' . __LINE__); if ($event_count > 0) { $headline = "Do they give out medals for " . $this->terms->getNoun('post', InsightTerms::PLURAL) . "?"; $insight_text = "{$this->username} mentioned "; if ($event_count > 0) { $this->logger->logInfo("There are event mentions", __METHOD__ . ',' . __LINE__); $insight_text .= "the Olympics "; if ($event_count > 1) { $this->logger->logInfo("there is more than one event mention", __METHOD__ . ',' . __LINE__); $insight_text .= "{$event_count} times since they started."; $insight_text .= " That's kind of like winning {$event_count} gold medals in " . ucfirst($instance->network) . ", right?"; } else { $insight_text .= "just as the whole world's attention was focused on the Games."; $insight_text .= " That's a pretty great way to join a global conversation."; } } $my_insight = new Insight(); $my_insight->slug = 'olympics_2014'; //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 is 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__); $fav_dao = DAOFactory::getDAO('FavoritePostDAO'); $days_ago = 0; while ($days_ago < $number_days) { $since_date = date("Y-m-d", strtotime("-" . $days_ago . " day")); if (self::shouldGenerateInsight('favorites_year_ago_flashback', $instance, $insight_date = $since_date, $regenerate_existing_insight = false)) { //Generate flashback post list $flashback_favs = $fav_dao->getFavoritesFromOneYearAgo($instance->network_user_id, $instance->network, $since_date); if (isset($flashback_favs) && sizeof($flashback_favs) > 0) { //Load photos for Instagram if ($instance->network == 'instagram') { $photo_dao = DAOFactory::getDAO('PhotoDAO'); $flashback_fav_photos = array(); foreach ($flashback_favs as $post) { $photo = $photo_dao->getPhoto($post->post_id, 'instagram'); $flashback_fav_photos[] = $photo; $photo = null; } $flashback_favs = $flashback_fav_photos; } $post_year = date(date('Y', strtotime($flashback_favs[0]->pub_date))); $current_year = date('Y'); $number_of_years_ago = $current_year - $post_year; $plural = $number_of_years_ago > 1 ? 's' : ''; if ($instance->network == 'twitter') { $headline = $this->username . " liked @" . $flashback_favs[0]->author_username . "'s tweet from " . $number_of_years_ago . " year" . $plural . " ago"; } else { $post_term = $flashback_favs[0]->is_short_video ? 'video' : '%post'; $headline = $this->username . " " . $this->terms->getVerb('liked') . " " . $flashback_favs[0]->author_username . $this->terms->getProcessedText("'s " . $post_term . " from " . $number_of_years_ago . " year" . $plural . " ago"); } $my_insight = new Insight(); $my_insight->instance_id = $instance->id; $my_insight->slug = 'favorites_year_ago_flashback'; $my_insight->date = $since_date; $my_insight->headline = $headline; $my_insight->text = "Can you believe how fast time flies?"; $my_insight->emphasis = Insight::EMPHASIS_MED; $my_insight->filename = basename(__FILE__, ".php"); $my_insight->setPosts($flashback_favs); $this->insight_dao->insertInsight($my_insight); } } $days_ago++; } $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}"; $post_dao = DAOFactory::getDAO('PostDAO'); $network = $instance->network; $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network); $streaks = $this->getStreaks($last_year_of_posts); $longest_streak = $this->getLongestStreak($streaks); $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 longest tweet-streak of %year", 'body' => "Sometimes the tweets flow like water and you just " . "don't need a day off. In %qualified_year, %username's longest " . "tweeting streak lasted for <strong>%total days</strong>, from %date1 to %date2."), 'everyday' => array('headline' => "%username has tweeted every single day in %year!", 'body' => "Sometimes the tweets flow like water and you just " . "don't need a day off. So far in %qualified_year, %username hasn't taken off " . "a single day, with a streak that has so far lasted for <strong>%total " . "days</strong>, from %date1 to %date2.")), 'facebook' => array('normal' => array('headline' => "%username's longest update streak of %year", 'body' => "Facebook is great for sharing what we're up to, " . "and sometimes we're up to a lot. In %qualified_year, %username " . "posted at least one status update or comment to Facebook " . "for <strong>%total days</strong> in a row, from %date1 to %date2."), 'everyday' => array('headline' => "%username has posted to Facebook every single day in %year!", 'body' => "Facebook is great for sharing what we're up to, and in %year, " . "%username was up to a lot — posting at least one time every day " . "so far in %qualified_year for a streak of <strong>%total days</strong>, " . "from %date1 through %date2.")), 'instagram' => array('normal' => array('headline' => "%username's longest Instagram streak of %year", 'body' => "Instagram is the place to share scenes from your life, " . "and sometimes there's a lot of life to share. In %qualified_year, %username " . "posted at least one photo or video on Instagram " . "for <strong>%total days</strong> in a row, from %date1 to %date2."), 'everyday' => array('headline' => "%username has posted to Instagram every single day in %year!", 'body' => "Instagram is the place to share scenes from your life, and in %year, " . "%username had lots of life to share — posting at least one time every day " . "so far in %qualified_year for a streak of <strong>%total days</strong>, " . "from %date1 through %date2."))); if ($longest_streak['length'] - 2 == date('z') - 1) { $type = 'everyday'; } else { $type = 'normal'; } $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year)); $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'total' => $longest_streak['length'], 'date1' => $this->getDateFromDay($longest_streak['start_day'], 'F jS'), 'date2' => $this->getDateFromDay($longest_streak['end_day'], 'F jS'), 'qualified_year' => $qualified_year)); $milestones = array("per_row" => 1, "label_type" => "text", "items" => array(0 => array("number" => $longest_streak['length'], "label" => "days"))); $insight->setMilestones($milestones); $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') { $day_of_week = 4; } else { $day_of_week = 1; } $should_generate_insight = self::shouldGenerateWeeklyInsight('long_lost_contacts', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = $day_of_week); if ($should_generate_insight) { $follow_dao = DAOFactory::getDAO('FollowDAO'); $contacts = $follow_dao->getFolloweesRepliedToThisWeekLastYear($instance->network_user_id, $instance->network); $long_lost_contacts = array(); $insight_text = ''; if (count($contacts)) { $post_dao = DAOFactory::getDAO('PostDAO'); foreach ($contacts as $contact) { if ($post_dao->getDaysAgoSinceUserRepliedToRecipient($instance->network_user_id, $contact->user_id, $instance->network) >= 365) { $long_lost_contacts[] = $contact; } } } if (count($long_lost_contacts)) { $headline = $this->username . " hasn't replied to " . (count($long_lost_contacts) > 1 ? "<strong>" . count($long_lost_contacts) . " people</strong> " : $long_lost_contacts[0]->full_name . " ") . "in over a year"; $insight_text = "It's good to reflect after some time has passed."; //Instantiate the Insight object $my_insight = new Insight(); //REQUIRED: Set the insight's required attributes $my_insight->slug = 'long_lost_contacts'; //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"; if (count($long_lost_contacts) == 1) { $my_insight->header_image = $long_lost_contacts[0]->avatar; } $my_insight->filename = basename(__FILE__, ".php"); $my_insight->emphasis = Insight::EMPHASIS_MED; $my_insight->setPeople($long_lost_contacts); $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__); $post_dao = DAOFactory::getDAO('PostDAO'); $insight_text = ''; foreach ($last_week_of_posts as $post) { $big_reshares = $post_dao->getRetweetsByAuthorsOverFollowerCount($post->post_id, $instance->network, $user->follower_count); if (isset($big_reshares) && sizeof($big_reshares) > 0) { if (!isset($config)) { $config = Config::getInstance(); } if (sizeof($big_reshares) > 1) { $headline = "People with lots of followers " . $this->terms->getVerb('shared') . " " . "{$this->username}"; } else { $follower_count_multiple = intval($big_reshares[0]->follower_count / $user->follower_count); if ($follower_count_multiple > 1) { $headline = "Someone with <strong>" . $follower_count_multiple . "x</strong> more followers " . $this->terms->getVerb('shared') . " " . $this->username; } else { $headline = $big_reshares[0]->full_name . " " . $this->terms->getVerb('shared') . " " . $this->username; } } $added_people = 0; foreach ($big_reshares as $big_resharer) { $added_people += $big_resharer->follower_count - $user->follower_count; } $insight_text = number_format($added_people) . " more people saw " . $this->username . "'s " . $this->terms->getNoun('post') . "."; $simplified_post_date = date('Y-m-d', strtotime($post->pub_date)); //Instantiate the Insight object $my_insight = new Insight(); $my_insight->slug = "big_reshare_" . $post->id; //slug to label this insight's content $my_insight->instance_id = $instance->id; $my_insight->date = $simplified_post_date; //date of the data this insight applies to $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->header_image = $header_image; $my_insight->filename = basename(__FILE__, ".php"); $my_insight->emphasis = Insight::EMPHASIS_MED; $my_insight->setPeople($big_reshares); $my_insight->setPosts(array($post)); $this->insight_dao->insertInsight($my_insight); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function getInsightForCounts($this_period_count, $last_period_count, $instance, $matching_posts) { $insight = null; if ($this_period_count > 0) { $insight = new Insight(); $insight->slug = $this->getSlug(); $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $network = ucfirst($instance->network); $potential_headlines = array("The LOLs of %month", 'LOL activity detected'); $last_month = Date('F', strtotime(date('F') . " last month")); $insight->text = 'Looks like ' . $this->username . ' found ' . number_format($this_period_count) . ' thing' . ($this_period_count == 1 ? '' : 's') . ' LOL-worthy in the last month.'; if ($this_period_count > $last_period_count && $last_period_count > 0) { $potential_headlines[] = $network . ' must be getting even funnier!'; $lol_diff = $this_period_count - $last_period_count; $insight->text .= ' That\'s ' . number_format($lol_diff) . ' more laugh' . ($lol_diff == 1 ? '' : 's') . ' than the ' . 'prior month.'; } $insight->headline = $this->getVariableCopy($potential_headlines, array('other_user' => $matching_posts[0]->author_username, 'month' => $last_month)); $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_MED; if (count($this->posts_to_include) > 0) { // Only include up to 10 posts to avoid InsightFieldExceedsMaxLengthException $insight->setPosts(array_slice($this->posts_to_include, 0, 10)); } } return $insight; }
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 getInsightForCounts($this_period_count, $last_period_count, $instance, $matching_posts) { $insight = null; if ($this_period_count > 0) { $insight = new Insight(); $insight->slug = $this->getSlug(); $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_MED; $insight->headline = $this->getVariableCopy(array('30 days of !!!', 'OMG %username is serious!')); $showchart = count($this->point_chart) > 2; $insight->text = $this->getVariableCopy(array("%username used exclamation points in %total %post" . ($this_period_count == 1 ? '' : 's') . " this past month! " . ($showchart ? "" : "That's %percent% of %username's %posts!")), array('total' => $this_period_count, 'percent' => floor($this_period_count / $this->total_posts * 100))); if ($showchart) { $insight->text .= " Some things are just one-exclamation-point exciting! " . "Others are really exciting!!!! Here's " . $this->username . "'s breakdown."; asort($this->point_chart); $rows = array(); foreach ($this->point_chart as $label => $number) { $rows[] = array('c' => array(array('v' => str_repeat('!', $label)), array('v' => $number))); } $insight->setBarChart(array('cols' => array(array('label' => 'Exclamation Points', 'type' => 'string'), array('label' => 'Occurences', 'type' => 'number')), 'rows' => $rows)); } } return $insight; }
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__); }
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__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { if (Utils::isTest() || date("Y-m-d") == $this->run_date) { 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/llama.jpg', 'alt_text' => 'Llama', 'credit' => 'Photo: Eric Kilby', 'img_link' => 'https://www.flickr.com/photos/ekilby/8564867495/'); $should_generate_insight = self::shouldGenerateWeeklyInsight($this->slug, $instance, $insight_date = $this->run_date, $regenerate_existing_insight = false, $day_of_week = 5, count($last_week_of_posts)); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $post_dao = DAOFactory::getDAO('PostDAO'); $topics = array('llama' => array("llama", "llamas")); $matches = array(); foreach ($last_week_of_posts as $post) { foreach ($topics as $key => $strings) { foreach ($strings as $string) { if (preg_match_all('/\\b' . $string . '\\b/i', $post->post_text) > 0) { $matches[$key] = array('term' => $string, 'post' => $post); unset($topics[$key]); break; } } } } if (count($matches) == 0) { $headline = $this->username . ' managed to avoid llamageddon!'; $insight_text = "It seems like half the internet was " . "<a href='http://www.theverge.com/2015/2/26/8116693/live-the-internet-is-going-bananas-" . "for-this-llama-chase'>talking about runaway llamas</a> " . 'yesterday. Kudos to ' . $this->username . ' for showing a llama restraint.'; } else { $headline = $this->username . " showed a whole llama love"; $insight_text = "Two runaway llamas <a href='http://www.theverge.com/2015/2/26/8116693/live-" . "the-internet-is-going-bananas-for-this-llama-chase'>took over Twitter yesterday</a>" . ", and like a llama people, " . $this->username . " couldn't resist."; } $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = $this->run_date; $insight->headline = $headline; $insight->text = $insight_text; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->setHeroImage($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__); $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, 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__); if (Utils::isTest() || date("Y-m-d") == $this->run_date) { $this->logger->logInfo("Should generate insight", __METHOD__ . ',' . __LINE__); $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-05/starwars.jpg', 'alt_text' => 'RockTrooper', 'credit' => 'Photo: JD Hancock', 'img_link' => 'https://www.flickr.com/photos/jdhancock/4932301604'); $post_dao = DAOFactory::getDAO('PostDAO'); $last_year_of_posts = $post_dao->getPostsByUserInRange($author_id = $instance->network_user_id, $network = $instance->network, $from = date('Y-m-d', strtotime('-1 year')), $until = date('Y-m-d'), $order_by = 'pub_date', $direction = 'DESC', $iterator = true, $is_public = false); $topics = array('force' => array("star wars", "force awakens", "bb-8", "darth vader", "bb8", "StarWars", "StarWarsDay")); $matches = array(); $matched_posts = array(); $matched = false; //print_r($last_year_of_posts); foreach ($last_year_of_posts as $post) { foreach ($topics as $key => $strings) { foreach ($strings as $string) { if (preg_match_all('/\\b' . strtolower($string) . '\\b/i', strtolower($post->post_text), $matches)) { $matched = true; } //DEBUG // else { // $this->logger->logInfo("Didn't find ".$string." in ".$post->post_text, // __METHOD__.','.__LINE__); // } } } if ($matched) { $this->logger->logInfo("Matched post " . $post->post_text, __METHOD__ . ',' . __LINE__); $matched_posts[] = $post; } $matched = false; } if (count($matched_posts) > 0) { $headline = "The Force is strong with " . $this->username . " on #StarWarsDay"; $insight_text = $this->username . " was ready for Star Wars Day. May the fourth be with you... always."; $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = $this->run_date; $insight->headline = $headline; $insight->text = $insight_text; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->setHeroImage($hero_image); $matched_posts_sliced = array_slice($matched_posts, 0, 20); $insight->setPosts($matched_posts_sliced); $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__); $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, null, $excluded_networks = array('facebook', 'instagram')); 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_shared = $this->topThreeThisYear($instance); $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-retweeted tweets of %year", 'body' => "Tweet, retweet, repeat. In %year, " . "%username earned the most retweets for these gems%qualified_year."), 'one' => array('headline' => "%username's most-retweeted tweet of %year", 'body' => "Tweet, retweet, repeat. In %year, " . "%username earned the most retweets for this gem%qualified_year."), 'none' => array('headline' => "Retweets aren't everything", 'body' => "%username didn't get any retweets in %year" . $qualified_year . ", which is a-okay. We're not all here to broadcast.")), 'facebook' => array('normal' => array('headline' => "%username's most-shared status updates of %year", 'body' => "With shares on the rise, %year was a bull " . "market for %username's most-shared status updates."), 'one' => array('headline' => "%username's most-shared status update of %year", 'body' => "With shares on the rise, %year was a " . "bull market for %username's most-shared status update."), 'none' => array('headline' => "Shares aren't everything", 'body' => "No one shared %username's status updates on " . "Facebook in %year — not that there's anything wrong " . "with that. Sometimes it's best to keep things close-knit."))); $network = $instance->network; if (sizeof($top_three_shared) > 1) { $type = 'normal'; } else { if (sizeof($top_three_shared) == 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"); //Avoid broken avatars foreach ($top_three_shared as $post) { $post->author_avatar = $user->avatar; } $insight->setPosts($top_three_shared); $this->insight_dao->insertInsight($insight); $insight = null; $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->getThisYearOfPostsWithLinksIterator($author_id = $instance->network_user_id, $network = $network); $scored_pics = $this->getScoredLinks($last_year_of_posts); $posts = $this->getMostPopularPics($instance, $scored_pics, $user); $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 links on Twitter, %year", 'body' => "The wealth of the web, shared in a constant 23 characters: " . "These are the most popular links %username shared on " . "Twitter in %qualified_year."), 'one' => array('headline' => "%username's most popular link on Twitter, %year", 'body' => "The wealth of the web, shared in a constant 23 characters: " . "This is the most popular link %username shared on " . "Twitter in %qualified_year."), 'none' => array('headline' => "%username's words are good enough", 'body' => "%username didn't share any links on Twitter in %qualified_year. " . "Crazy, %username!")), 'facebook' => array('normal' => array('headline' => "%username's most popular links on Facebook, %year", 'body' => "We laughed, we cried, we linked. These are the most " . "popular links %username shared on Facebook in %qualified_year."), 'one' => array('headline' => "%username's most popular link on Facebook, %year", 'body' => "We laughed, we cried, we linked. This is the most " . "popular link %username shared on Facebook in %qualified_year."), 'none' => array('headline' => "No links on Facebook?", 'body' => "%username didn't link to anything on Facebook in %qualified_year. " . "The internet promises to try harder, next year."))); 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; $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__); }
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, null, $excluded_networks = array('twitter')); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $fav_dao = DAOFactory::getDAO('FavoritePostDAO'); $fans = $fav_dao->getUsersWhoFavoritedMostOfYourPosts($instance->network_user_id, $instance->network, TimeHelper::getDaysSinceJanFirst()); if (!isset($fans) || sizeof($fans) == 0) { $this->logger->logInfo("No fans captured", __METHOD__ . ',' . __LINE__); return; } $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 . ")."; } } $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $network = $instance->network; $copy = array('facebook' => array('normal' => array('headline' => "%username's biggest Facebook fans of %year", 'body' => "It feels great to have friends who support you. " . "%user_list liked %username's status updates the most this year%qualified_year")), 'instagram' => array('normal' => array('headline' => "%username's biggest Instagram fans of %year", 'body' => "It means a lot to have friends who love your stuff. " . "%user_list liked %username's Instagram photos and videos the most this year%qualified_year"))); $type = 'normal'; $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year)); $fan_list = array(); foreach ($fans as $fan) { $fan_list[] = $fan->full_name; } $fan_list = $this->makeList($fan_list); $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('user_list' => $fan_list, 'qualified_year' => $qualified_year)); $insight->headline = $headline; $insight->text = $insight_text; $insight->setPeople($fans); $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 testInsightRelatedDataSetters() { $i = new Insight(); // @TODO Assign and assert that the data is in the array structure it should be $i->setPhotos("this is my list of photos"); $this->assertEqual($i->related_data["photos"], "this is my list of photos"); $i->setPosts("my posts"); $this->assertEqual($i->related_data["posts"], "my posts"); $i->setLineChart("line chart data goes here"); $this->assertEqual($i->related_data["line_chart"], "line chart data goes here"); $i->setBarChart("bar chart data goes here"); $this->assertEqual($i->related_data["bar_chart"], "bar chart data goes here"); $i->setPeople("list 'o users"); $this->assertEqual($i->related_data["people"], "list 'o users"); $i->setLinks("listoflinks"); $this->assertEqual($i->related_data["links"], "listoflinks"); $i->setMilestones("milestones"); $this->assertEqual($i->related_data["milestones"], "milestones"); $i->setButton("button"); $this->assertEqual($i->related_data["button"], "button"); $i->setHeroImage("Hero Image"); $this->assertEqual($i->related_data["hero_image"], "Hero Image"); }
public function testInsightRelatedDataSetters() { $i = new Insight(); $i->setPhotos("this is my list of photos"); $this->assertEqual($i->related_data["photos"], "this is my list of photos"); $i->setPosts("my posts"); $this->assertEqual($i->related_data["posts"], "my posts"); $i->setLineChart("line chart data goes here"); $this->assertEqual($i->related_data["line_chart"], "line chart data goes here"); $i->setBarChart("bar chart data goes here"); $this->assertEqual($i->related_data["bar_chart"], "bar chart data goes here"); $i->setPeople("list 'o users"); $this->assertEqual($i->related_data["people"], "list 'o users"); $i->setLinks("listoflinks"); $this->assertEqual($i->related_data["links"], "listoflinks"); $i->setMilestoneNumber("milestone_number"); $this->assertEqual($i->related_data["milestone_number"], "milestone_number"); }
public function getInsightForCounts($this_period_count, $last_period_count, $instance, $matching_posts) { $insight = null; if ($this_period_count > 0) { $insight = new Insight(); $insight->slug = $this->getSlug(); $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $network = ucfirst($instance->network); $potential_headlines = array(); if ($this_period_count > 1) { $potential_headlines[] = '%username gave %total f***s'; $potential_headlines[] = 'F-bombs rain from the sky'; } else { $potential_headlines[] = '%username really gave a f**k'; } if ($instance->network == 'facebook') { $potential_headlines[] = 'Facebook users curse knowledgeably'; } $insight->headline = $this->getVariableCopy($potential_headlines, array('total' => $this_period_count)); $insight->text = $this->username . ' said “f**k” ' . $this->terms->getOccurrencesAdverb($this_period_count) . ' in the past month.'; if ($this_period_count != $last_period_count && $last_period_count > 0) { $f_diff = $this_period_count - $last_period_count; $diff = $f_diff < 0 ? 'fewer' : 'more'; $insight->text .= ' That\'s ' . number_format(abs($f_diff)) . ' ' . $diff . ' than the prior month. '; if ($diff == 'fewer') { $insight->text .= 'F*****g Awesome.'; } else { $insight->text .= 'WTF?'; } } $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; if (count($this->posts_to_include) > 0) { $insight->setPosts(array_slice($this->posts_to_include, 0, 10)); if (count($this->posts_to_include) > 1) { //plural $insight->text .= $this->getVariableCopy(array(" Here are some of the %posts that elicited a \"f**k.\"", " These are some of the %posts that inspired %username to say \"f**k\".")); } else { //singular $insight->text .= $this->getVariableCopy(array(" Here is the %post that elicited a \"f**k.\"", " This is the %post that inspired %username to say \"f**k\".")); } } } return $insight; }
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, $count_related_posts = null, array('instagram')); 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}"; $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->filename = basename(__FILE__, ".php"); $insight->header_image = $user->avatar; $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 tweeted %total times in %year", 'body' => "In %year, %username posted a total of <b>%total tweets</b>%qualified_year. " . "At 15 seconds per tweet, that amounts to <b>%time</b>. %username's followers probably " . "appreciated it.")), 'facebook' => array('normal' => array('headline' => "%username posted to Facebook %total times in %year", 'body' => "This year, %username posted a grand total of " . "<b>%total times</b> on Facebook%qualified_year. If each status update and comment " . "took about 15 seconds, that's " . "over <b>%time</b> dedicated to keeping in touch with friends."))); $network = $instance->network; $total_post_count = $this->getTotalPostCount($instance, $year); $posting_time = $this->getPostingTime($total_post_count); if ($total_post_count > 1) { $type = 'normal'; } else { return; } $insight->headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('total' => number_format($total_post_count), 'year' => $year)); $insight->text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('total' => number_format($total_post_count), 'year' => $year, 'time' => $posting_time, 'qualified_year' => $qualified_year)); $milestones = array("label_type" => "icon", "items" => array(0 => array("number" => number_format($total_post_count)))); $insight->setMilestones($milestones); $this->insight_dao->insertInsight($insight); $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); } }
public function getInsightForCounts($this_period_count, $last_period_count, $instance, $matching_posts) { $insight = null; if ($this_period_count > 0) { $unique_friends = array(); $posts_to_show = array(); $post_dao = DAOFactory::getDAO('PostDAO'); foreach ($matching_posts as $post) { if (!in_array($post->in_reply_to_user_id, $unique_friends)) { $unique_friends[] = $post->in_reply_to_user_id; } $replied_post = $post_dao->getPost($post->in_reply_to_post_id, $instance->network); if ($replied_post) { $posts_to_show[] = $replied_post; } } $insight = new Insight(); $insight->slug = $this->getSlug(); $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $insight->emphasis = Insight::EMPHASIS_MED; $network = $instance->network; $other_user = ($network == 'twitter' ? '@' : '') . $posts_to_show[0]->author_username; $posts = $this_period_count > 1 ? '%posts' : '%post'; $insight->headline = $this->getVariableCopy(array((count($posts_to_show) == 1 ? 'A c' : 'C') . 'ongrats-worthy ' . $posts, 'Championing %other_user', 'Congrats to %other_user', '%other_user had some great news'), array('network' => ucfirst($network), 'other_user' => $other_user)); $these = $this_period_count > 1 ? 'these' : 'this'; $are = $this_period_count > 1 ? 'are' : 'is'; $people_term = count($unique_friends) > 1 ? 'people' : 'person'; $someone = count($unique_friends) > 1 ? 'people' : 'someone'; $insight->text = $this->getVariableCopy(array("%username congratulated %total_friends {$people_term} in the past month for {$these} {$posts}.", "%total_posts {$posts} inspired %username to congratulate {$someone} this past month.", "Here {$are} the {$posts} that inspired %username to congratulate {$someone} this month."), array('network' => ucfirst($instance->network), 'total_posts' => $this_period_count, 'total_friends' => count($unique_friends))); $insight->filename = basename(__FILE__, ".php"); if (count($posts_to_show)) { $insight->setPosts($posts_to_show); } } return $insight; }
private function runInsightForConfig($config, $instance) { $regex = '/\\b(' . join('|', array_map('preg_quote', $config['words'])) . ')\\b/i'; $usage = array_fill_keys(array_map('strtolower', $config['words']), 0); $post_dao = DAOFactory::getDAO('PostDAO'); $posts = $post_dao->getAllPostsByUsernameIterator($instance->network_username, $instance->network); $first_date = time(); foreach ($posts as $post) { if (preg_match_all($regex, $post->post_text, $matches)) { foreach ($matches[1] as $match) { $usage[strtolower($match)]++; } if (strtotime($post->pub_date) < $first_date) { $first_date = strtotime($post->pub_date); } } } $usage = array_filter($usage); if (count($usage)) { $formatted_usage = array(); foreach ($usage as $word => $times) { foreach ($config['words'] as $formatted_word) { if (strtolower($formatted_word) == $word) { $formatted_usage[$formatted_word] = $times; break; } } } arsort($formatted_usage); $insight = new Insight(); $insight->slug = 'new_dictionary_words'; $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_MED; if (!empty($config['hero_image'])) { $insight->setHeroImage($config['hero_image']); } if (count($formatted_usage) == 1) { $words = array_keys($formatted_usage); $template = $config['single_template']; $params = array('first_mention' => date('F Y', $first_date), 'word' => $words[0], 'total_times' => $this->terms->getOccurrencesAdverb($formatted_usage[$words[0]])); } else { $formatted_usage = array_slice($formatted_usage, 0, 5, true); $words = array_keys($formatted_usage); $template = $config['multiple_template']; $params = array('first_mention' => date('F Y', $first_date)); $times = array(); $quoted_words = array(); foreach ($formatted_usage as $word => $t) { $times[] = '"' . $word . '" ' . $this->terms->getOccurrencesAdverb($t); $quoted_words[] = '"' . $word . '"'; } $last = count($times) - 1; $times[$last] = 'and ' . $times[$last]; $quoted_words[$last] = 'and ' . $quoted_words[$last]; $sep = count($times) == 2 ? ' ' : ', '; $params['word_times_list'] = join($sep, $times); $params['word_list'] = join($sep, $quoted_words); } $insight->text = $this->getVariableCopy(array($template), $params); $insight->headline = $this->getVariableCopy(array($config['headline']), array('word' => $words[0])); $this->insight_dao->insertInsight($insight); } return array_sum($usage); }
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__); $filename = basename(__FILE__, ".php"); $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $post_dao = DAOFactory::getDAO('PostDAO'); $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = "this 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 = "this year (at least since " . $since . ")."; } } $copy = array('twitter' => array('normal' => array('headline' => "%username's most talkative day on Twitter in %year", 'body' => "%username tweeted <strong>%total times on %talkative_date</strong>, " . "more than any other day %qualified_year (Strange — the " . "forecast didn't say anything about a tweetstorm.) " . "These are %username's most popular tweets from that day."), 'multiple' => array('headline' => "%username's most talkative day on Twitter in %year", 'body' => "In the running for %username's most talkative day " . "on Twitter, %year, we've got a tie: %username tweeted " . "<strong>%total times on %talkative_date</strong> — more than on any other " . "days %qualified_year These are %username's most popular tweets " . "from each day.")), 'facebook' => array('normal' => array('headline' => "%username's most talkative day on Facebook in %year", 'body' => "%username posted to Facebook <strong>%total times on " . "%talkative_date</strong>, more than any other day %qualified_year " . "These are %username's most popular status updates from that day."), 'multiple' => array('headline' => "%username's most talkative day on Facebook in %year", 'body' => "In the running for %username's most talkative day " . "on Facebook, %year, we've got a tie: %username posted " . "<strong>%total times on %talkative_date</strong> — more than on any other " . "days %qualified_year These are %username's most popular " . "status updates from each day.")), 'instagram' => array('normal' => array('headline' => "%username's most Instagrammed day in %year", 'body' => "%username posted on Instagram <strong>%total times on " . "%talkative_date</strong>, more than any other day %qualified_year " . "These are %username's most popular photos and videos from that day."), 'multiple' => array('headline' => "%username's most Instagrammed day in %year", 'body' => "In the running for %username's most Instagrammed day " . "in %year, we've got a tie: %username posted " . "<strong>%total times on %talkative_date</strong> — more than on any other " . "days %qualified_year These are %username's most popular " . "posts from each day."))); $network = $instance->network; $most_talkative_days = $this->getMostTalkativeDays($instance); if (sizeof($most_talkative_days) == 1) { $type = 'normal'; $date = new DateTime($most_talkative_days[0]['pub_date']); $query_date = $date->format("Y-m-d"); $talkative_dates = $date->format('F jS'); $popular_posts = $this->mostPopularPosts($instance, $date = $query_date); } else { if (sizeof($most_talkative_days) > 1) { $type = 'multiple'; $dates = array(); $popular_posts = array(); foreach ($most_talkative_days as $day) { $date = new DateTime($day['pub_date']); $query_date = $date->format("Y-m-d"); $dates[] = $date->format('F jS'); $posts = $this->mostPopularPosts($instance, $date = $query_date, $limit = 1); $popular_posts[] = $posts[0]; } $talkative_dates = $this->makeList($dates); } } $insight->headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year)); $insight->text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'total' => $most_talkative_days[0]['post_count'], 'talkative_date' => $talkative_dates, 'qualified_year' => $qualified_year)); $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->filename = $filename; //Populate Instagram photos if ($instance->network == 'instagram') { $photo_dao = DAOFactory::getDAO('PhotoDAO'); $popular_photos = array(); foreach ($popular_posts as $post) { if ($post->network == 'instagram') { $post = $photo_dao->getPhoto($post->post_id, 'instagram'); $popular_photos[] = $post; } } $popular_posts = $popular_photos; } foreach ($popular_posts as $post) { //Avoid broken avatars $post->author_avatar = $user->avatar; } $insight->setPosts($popular_posts); $this->insight_dao->insertInsight($insight); $insight = null; $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); $thanksgiving_day = date('m/j', strtotime("3 weeks thursday", mktime(0, 0, 0, 11, 1, date('Y')))); $regenerate = false; //test // $thanksgiving_day = date('11/20'); // $regenerate = true; if (!$this->shouldGenerateAnnualInsight($this->slug, $instance, 'today', $regenerate, $thanksgiving_day, null, array('instagram'))) { $this->logger->logInfo("Skipped generating insight on " . $instance->network, __METHOD__ . ',' . __LINE__); return; } $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $user_dao = DAOFactory::getDAO('UserDAO'); $post_dao = DAOFactory::getDAO('PostDAO'); $post_iterator = $post_dao->getThisYearOfPostsIterator($instance->network_user_id, $instance->network); $thankees = array(); $thankees_totals = array(); foreach ($post_iterator as $post) { $in_reply_id = $post->in_reply_to_user_id; if ($in_reply_id == 0 || $in_reply_id == $instance->network_user_id) { // No self thanks, untargeted thanks, or rethanking continue; } $text = strtolower($post->post_text); $has_thanks = preg_match('/(\\W|^)(thanks|thank you)(\\W|$)/', $text); if ($has_thanks) { if (preg_match('/(\\W|^)no (thanks|thank you)/', $text) || preg_match('/thank(s| you),? but/', $text)) { $has_thanks = false; } } if (!$has_thanks) { continue; } if (isset($thankees_totals[$in_reply_id])) { $thankees_totals[$in_reply_id] = $thankees_totals[$in_reply_id] + 1; } else { $thankees_totals[$in_reply_id] = 0; } } arsort($thankees_totals, SORT_NUMERIC); foreach ($thankees_totals as $user_id => $count) { $user = $user_dao->getDetails($user_id, $instance->network); if ($user) { $thankees[] = $user; } } if (count($thankees) > 1) { $this->logger->logInfo("More than one thankee", __METHOD__ . ',' . __LINE__); $insight = new Insight(); $insight->slug = $this->slug; $insight->instance_id = $instance->id; $insight->date = $this->insight_date; if ($instance->network == 'facebook') { $insight->headline = $this->username . ' had friends to be thankful for in ' . date('Y'); $insight->text = "These are the friends " . $this->username . " was thankful for this year."; $insight->setHeroImage(array('url' => 'https://www.thinkup.com/assets/images/insights/2014-11/thanksgiving-2.jpg', 'alt_text' => $insight->headline, 'credit' => 'Photo: John-Morgan', 'img_link' => 'https://www.flickr.com/photos/aidanmorgan/4135626581/')); } else { $insight->headline = 'Who ' . $this->username . " was thankful for in " . date('Y'); if (count($thankees) > 20) { $insight->text = "These are just some of the <strong>" . count($thankees) . " people</strong> " . $this->username . " thanked this year."; } else { $insight->text = "These are all the people " . $this->username . " thanked this year."; } $insight->setHeroImage(array('url' => 'https://www.thinkup.com/assets/images/insights/2014-11/thanksgiving-1.jpg', 'alt_text' => $insight->headline, 'credit' => 'Photo: Steve Voght', 'img_link' => 'https://www.flickr.com/photos/voght/2441818832/')); } $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $this->logger->logInfo("About to setPeople, total is " . count($thankees), __METHOD__ . ',' . __LINE__); $thankees_sliced = array_slice($thankees, 0, 20); $insight->setPeople($thankees_sliced); $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, $count_related_posts = null, array('instagram')); 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); foreach ($last_year_of_posts as $post) { if ($this->hasLOL($post)) { $count++; } } $most_popular_lolees = $this->getMostPopularLOLees($instance); $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 Twitter LOLs, %year", 'body' => array('normal' => "%username found <strong>%total things</strong> to LOL about on " . "Twitter in %qualified_year, including these LOLed-at tweets.", 'one' => "%username found <strong>%total things</strong> to LOL about on " . "Twitter in %qualified_year, including this LOLed-at tweet.", 'none' => "%username found <strong>%total things</strong> to LOL about on " . "Twitter in %qualified_year. Not a bad year!")), 'one' => array('headline' => "Funny, but rarely LOL-funny", 'body' => array('normal' => "%username found <strong>1 thing</strong> to LOL about on " . "Twitter in %qualified_year."))), 'facebook' => array('normal' => array('headline' => "%username's LOLs of Facebook, %year", 'body' => array('normal' => "ROFL. %username LOLed at <strong>%total things</strong> on Facebook " . "in %qualified_year, including these LOL-worthy status updates.", 'one' => "ROFL. %username LOLed at <strong>%total things</strong> on Facebook " . "in %qualified_year, including this LOL-worthy status update.", 'none' => "ROFL. %username LOLed at <strong>%total things</strong> on Facebook " . "in %qualified_year. Gotta love a good LOL.")), 'one' => array('headline' => "%username's one LOL on Facebook, %year", 'body' => array('normal' => "%username LOLed <strong>once</strong> on Facebook " . "in %qualified_year. Not the funniest of years.")))); if ($count === 0) { return; } if ($count > 1) { $type = 'normal'; if (count($most_popular_lolees) > 1) { $body_type = 'normal'; } else { if (count($most_popular_lolees) === 1) { $body_type = 'one'; } else { $body_type = 'none'; } } } else { $type = 'one'; $body_type = 'normal'; } $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('total' => $count, 'year' => $year)); $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body'][$body_type]), array('total' => $count, 'qualified_year' => $qualified_year)); $insight->headline = $headline; $insight->text = $insight_text; $lolees = array_slice($most_popular_lolees, 0, 12); $insight->setPosts($lolees); $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }