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__);
 }
Esempio n. 2
0
 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");
 }
Esempio n. 3
0
 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__);
     $milestones = array();
     $info = array('text' => '');
     if ($instance->network == 'twitter') {
         $day_of_week = 1;
     } elseif ($instance->network == 'instagram') {
         $day_of_week = 3;
     } else {
         $day_of_week = 5;
     }
     $should_generate_insight = self::shouldGenerateWeeklyInsight('frequency', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = $day_of_week);
     if ($should_generate_insight) {
         $count = sizeof($last_week_of_posts);
         $this->logger->logInfo("Last week had {$count} posts", __METHOD__ . ',' . __LINE__);
         //Load photos for Instagram to display whether or not it was a video
         if ($instance->network == 'instagram') {
             $photo_dao = DAOFactory::getDAO('PhotoDAO');
             $last_week_of_posts_with_photos = array();
             foreach ($last_week_of_posts as $post) {
                 $post = $photo_dao->getPhoto($post->post_id, 'instagram');
                 $last_week_of_posts_with_photos[] = $post;
             }
             $last_week_of_posts = $last_week_of_posts_with_photos;
             $photo_count = 0;
             $video_count = 0;
             foreach ($last_week_of_posts as $post) {
                 if ($post->is_short_video) {
                     $video_count++;
                 } else {
                     $photo_count++;
                 }
             }
         }
         if ($count > 1) {
             if ($instance->network !== 'instagram') {
                 $info['headline'] = $this->getVariableCopy(array('%username %posted <strong>%count times</strong> in the past week', '%username had <strong>%count %posts</strong> over the past week', '%username had <strong>%count %posts</strong> over the past week'), array('count' => number_format($count)));
                 $milestones = array("per_row" => 1, "label_type" => "icon", "items" => array(0 => array("number" => number_format($count), "label" => $this->terms->getNoun('post', $count))));
             } else {
                 //Network is Instagram so count photos and videos separately
                 if ($photo_count > 0 && $video_count > 0) {
                     $photos_term = $photo_count == 1 ? 'photo' : 'photos';
                     $videos_term = $video_count == 1 ? 'video' : 'videos';
                     $headline = $this->username . " had {$photo_count} {$photos_term} and {$video_count} {$videos_term} over the past week";
                 } else {
                     if ($photo_count > 0) {
                         $headline = $this->username . " had {$photo_count} photos over the past week";
                     } else {
                         $headline = $this->username . " had {$video_count} videos over the past week";
                     }
                 }
                 $info['headline'] = $headline;
                 $milestones = array("per_row" => 1, "label_type" => "icon", "items" => array(0 => array("number" => number_format($count), "label" => $this->terms->getNoun('post', $count))));
             }
         } elseif ($count == 1) {
             $info['headline'] = $this->getVariableCopy(array('%username %posted <strong>once</strong> in the past week'), array('count' => number_format($count)));
             $milestones = array("per_row" => 1, "label_type" => "icon", "items" => array(0 => array("number" => number_format($count), "label" => $this->terms->getNoun('post', $count))));
         } else {
             if ($instance->network == 'twitter') {
                 $info = $this->getVariableCopyArray(array(array('headline' => "%username didn't have any new %posts this week", 'text' => "Nothing wrong with waiting until there's something to say.", 'button' => array("url" => "http://twitter.com/intent/tweet?text=Hey there, friends.", "label" => "Have anything to say now?")), array('headline' => '%username didn\'t post anything new on Twitter in the past week', 'text' => 'Sometimes we just don\'t have anything to say. Maybe let someone know you ' . 'appreciate their work?', 'button' => array("url" => "http://twitter.com/intent/tweet?text=You know who is really great?", "label" => "Tweet a word of praise")), array('headline' => "Seems like %username was pretty quiet on Twitter this past week", 'text' => "Nothing wrong with waiting until there's something to say.", 'button' => array("url" => "http://twitter.com/intent/tweet?text=Sorry I haven't tweeted in a while!", "label" => "Or just say hi to everyone."))));
             } else {
                 if ($instance->network == 'facebook') {
                     $info = $this->getVariableCopyArray(array(array('headline' => '%username didn\'t have any new %posts this week', 'text' => 'Nothing wrong with waiting until there\'s something to say.', 'button' => array('url' => 'http://www.facebook.com/sharer/sharer.php?t=ThinkUp told me to say hi.', 'label' => 'Maybe you\'ve got something to say now?')), array('headline' => '%username didn\'t post anything new on Facebook in the past week', 'text' => 'Nothing wrong with being quiet. If you want, you could ask your friends ' . 'what they\'ve read lately.', 'button' => array('url' => 'http://www.facebook.com/sharer/sharer.php' . '?u=http://upload.wikimedia.org/wikipedia/en/4/43/' . 'FlanneryOConnorCompleteStories.jpg&' . 't=Ready any good books lately?', 'label' => 'Read any good books lately?')), array('headline' => 'Seems like %username was pretty quiet on Facebook this past week', 'text' => "Nothing wrong with waiting until there's something to say.", 'button' => array('url' => 'http://www.facebook.com/sharer/sharer.php?t=Hey there, friends!', 'label' => 'Or just say hi to your friends?'))));
                 } else {
                     $info = array('headline' => $this->getVariableCopy(array('%username didn\'t post any new %posts this week')), 'text' => "Huh, nothing. Fill the emptiness inside you by donating to an underfunded classroom.", 'button' => array("url" => "http://www.donorschoose.org/", "label" => "Give to DonorsChoose.org"));
                 }
             }
         }
         $insight_baseline_dao = DAOFactory::getDAO('InsightBaselineDAO');
         $insight_baseline_dao->insertInsightBaseline("frequency", $instance->id, $count, $this->insight_date);
         if ($instance->network == 'instagram') {
             $insight_baseline_dao->insertInsightBaseline("frequency_photo_count", $instance->id, $photo_count, $this->insight_date);
             $insight_baseline_dao->insertInsightBaseline("frequency_video_count", $instance->id, $video_count, $this->insight_date);
         }
         if ($count > 0) {
             //Week over week comparison
             $week_ago_date = date('Y-m-d', strtotime('-7 day'));
             if ($instance->network !== 'instagram') {
                 //Just compare total posts
                 //Get insight baselines from a week ago
                 $week_ago_insight_baseline = $insight_baseline_dao->getInsightBaseline("frequency", $instance->id, $week_ago_date);
                 if (isset($week_ago_insight_baseline)) {
                     $this->logger->logInfo("Baseline had {$week_ago_insight_baseline->value} posts", __METHOD__ . ',' . __LINE__);
                     //compare it to today's number, and add a sentence comparing it
                     $diff = abs($week_ago_insight_baseline->value - $count);
                     $comp = $week_ago_insight_baseline->value > $count ? 'fewer' : 'more';
                     if ($diff == 1) {
                         $info['text'] = $this->terms->getProcessedText("That's 1 {$comp} %post than the prior week.");
                     } elseif ($diff > 0) {
                         $info['text'] = $this->terms->getProcessedText("That's " . number_format($diff) . " {$comp} %posts than the prior week.");
                     }
                 }
             } else {
                 //Compare photos and videos separately
                 //Get insight baselines from a week ago
                 $week_ago_photo_count_insight_baseline = $insight_baseline_dao->getInsightBaseline("frequency_photo_count", $instance->id, $week_ago_date);
                 $week_ago_video_count_insight_baseline = $insight_baseline_dao->getInsightBaseline("frequency_video_count", $instance->id, $week_ago_date);
                 if (isset($week_ago_photo_count_insight_baseline) && isset($week_ago_video_count_insight_baseline)) {
                     $this->logger->logInfo("Baseline had {$week_ago_photo_count_insight_baseline->value} photos " . " and {$week_ago_video_count_insight_baseline->value} videos", __METHOD__ . ',' . __LINE__);
                     //compare it to today's number, and add a sentence comparing it
                     //First, photos
                     $diff_photos = abs($week_ago_photo_count_insight_baseline->value - $photo_count);
                     $comp_photos = $week_ago_photo_count_insight_baseline->value > $photo_count ? 'fewer' : 'more';
                     //Next, videos
                     $diff_videos = abs($week_ago_video_count_insight_baseline->value - $video_count);
                     $comp_videos = $week_ago_video_count_insight_baseline->value > $video_count ? 'fewer' : 'more';
                     $this->logger->logInfo("Diff photos " . $diff_photos . ", diff videos " . $diff_videos, __METHOD__ . ',' . __LINE__);
                     if ($diff_photos > 0) {
                         if ($diff_photos == 1) {
                             $photo_comp_phrase = " 1 {$comp_photos} photo ";
                         } else {
                             $photo_comp_phrase = " " . number_format($diff_photos) . " {$comp_photos} photos ";
                         }
                         if ($diff_videos > 0) {
                             if ($diff_videos == 1) {
                                 $video_comp_phrase = " and 1 {$comp_videos} video ";
                             } else {
                                 $video_comp_phrase = " and " . number_format($diff_videos) . " {$comp_videos} videos ";
                             }
                         } else {
                             $video_comp_phrase = '';
                         }
                         $info['text'] = "That's " . $photo_comp_phrase . $video_comp_phrase . " than the prior week.";
                     }
                 }
             }
         }
         //Instantiate the Insight object
         $my_insight = new Insight();
         //REQUIRED: Set the insight's required attributes
         $my_insight->instance_id = $instance->id;
         $my_insight->slug = 'frequency';
         //slug to label this insight's content
         $my_insight->date = $this->insight_date;
         //date of the data this insight applies to
         $my_insight->header_image = $user->avatar;
         $my_insight->emphasis = Insight::EMPHASIS_LOW;
         //Set emphasis optionally, default is Insight::EMPHASIS_LOW
         $my_insight->filename = basename(__FILE__, ".php");
         //Same for every insight, must be set exactly this way
         $my_insight->setMilestones($milestones);
         if (isset($info['button'])) {
             $my_insight->setButton($info['button']);
         }
         $my_insight->headline = $info['headline'];
         if (!empty($info['text'])) {
             $my_insight->text = $info['text'];
             $this->insight_dao->insertInsight($my_insight);
         } else {
             $this->logger->logInfo("No insight text set, so no insight inserted", __METHOD__ . ',' . __LINE__);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Esempio n. 4
0
 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->logger->logInfo("Done generating insight (Skipped Non-Facebook)", __METHOD__.','.__LINE__);
     //     return;
     // }
     $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__);
         $post_dao = DAOFactory::getDAO('PostDAO');
         $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $instance->network);
         $topics = array('the U.S. Presidential election' => array('trump', 'clinton', 'sanders', 'jeb bush'), 'the Syrian refugee crisis' => array('Syria', 'refugee'), 'terror attacks' => array(' ISIS ', 'daesh', ' ISIL ', ' Paris ', 'hebdo', 'jesuischarlie'), 'the Nepal earthquake' => array('Nepal', 'earthquake'), 'marriage equality' => array('marriage equality', 'gay marriage', 'obergefell', 'lovewins'), 'the Planned Parenthood attack' => array('planned parenthood', 'abortion', 'colorado springs'), '#BlackLivesMatter' => array('Freddie Gray', 'Baltimore', 'blacklivesmatter'), 'Charleston' => array('Charleston', 'confederate', 'emanuel'), 'Ahmed Mohamed' => array('Ahmed Mohamed', 'istandwithahmed'), 'Floyd Mayweather, Jr.' => array('mayweather'), 'Manny Pacquiao' => array('pacquiao'), 'Ronda Rousey' => array('ronda rousey', 'RondaRousey'), 'Tom Brady' => array('tom brady'), 'Stephen Curry' => array('stephen curry'), 'Serena Williams' => array('serena'), 'Ed Sheeran' => array('sheeran'), 'Taylor Swift' => array('taylor swift', 'taylorswift13'), 'Kanye West' => array('kanye'), 'Caitlyn Jenner' => array('jenner', 'Caitlyn_Jenner'), 'Star Wars' => array('star wars', 'force awakens', 'episode vii', 'episode 7', 'bb8', 'starwarstheforceawakens', 'starwars', 'theforceawakens'), 'Avengers: Age of Ultron' => array('avengers'), 'Mad Max: Fury Road' => array('mad max', 'fury road', 'imperator', 'furiosa'), 'Magic Mike XXL' => array('magic mike'), 'Game of Thrones' => array('game of thrones', 'jon snow', 'seven hells'), 'The Walking Dead' => array('walking dead'));
         $matches = array();
         foreach ($last_year_of_posts as $post) {
             foreach ($topics as $key => $strings) {
                 foreach ($strings as $string) {
                     if (stristr($post->post_text, $string) !== FALSE) {
                         $matches[$key] = array('term' => $key, 'post' => $post);
                         $this->logger->logInfo("Matched  " . $string . " with \"" . $post->post_text . "\"", __METHOD__ . ',' . __LINE__);
                         unset($topics[$key]);
                         break;
                     }
                 }
             }
         }
         if (count($matches) == 0) {
             if ($instance->network == 'facebook') {
                 $insight = new Insight();
                 $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 . ")";
                     }
                 }
                 $headline = $this->username . " didn't rehash 2015's top news on Facebook";
                 $insight_text = "No Trump or Syrian refugee crisis here. " . $this->username . " broke away from the herd and avoided talking about 2015's biggest stories " . "on Facebook this year" . $qualified_year . '.';
                 $posts = null;
                 //Show avatar if there are no posts
                 $insight->header_image = $user->avatar;
                 //Show button if there are no posts
                 $insight->setButton(array('url' => 'http://newsroom.fb.com/news/2015/12/2015-year-in-review/', 'label' => "See Facebook's Year in Review"));
             }
         } else {
             $insight = new Insight();
             $headline = $this->username . " was part of {$year}'s biggest trends";
             $posts = array();
             $mentioned = array();
             foreach ($matches as $m) {
                 if (count($posts) < 12) {
                     $posts[] = $m['post'];
                 }
                 $mentioned[] = $m['term'];
             }
             $num = count($mentioned);
             if ($num > 1) {
                 $mentioned[$num - 1] = 'and ' . $mentioned[$num - 1];
             }
             $mention_string = join($num == 2 ? ' ' : ', ', $mentioned);
             $thatwas = $num == 1 ? 'That was one' : 'Those were some';
             $insight_text = $this->username . "'s {$year} included {$mention_string}. {$thatwas} of " . '<a href="http://newsroom.fb.com/news/2015/12/2015-year-in-review/">Facebook\'s top topics of ' . "the year</a>.";
         }
         if (isset($insight)) {
             $insight->instance_id = $instance->id;
             $insight->slug = $this->slug;
             $insight->date = "{$year}-{$this->run_date}";
             $insight->headline = $headline;
             $insight->text = $insight_text;
             $insight->filename = basename(__FILE__, ".php");
             $insight->emphasis = Insight::EMPHASIS_HIGH;
             if ($posts) {
                 $link_dao = DAOFactory::getDAO('LinkDAO');
                 foreach ($posts as $post) {
                     $post->links = $link_dao->getLinksForPost($post->post_id, $post->network);
                 }
                 $insight->setPosts($posts);
             }
             $this->insight_dao->insertInsight($insight);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Esempio n. 5
0
 private function generateMonthlyInsight($instance, $posts)
 {
     $located_posts = 0;
     $geo_data = array();
     foreach ($posts as $p) {
         if ($this->isPreciselyLocated($p)) {
             $geo_data[] = $p->geo;
             $located_posts++;
         }
     }
     if ($located_posts < 1) {
         return;
     }
     $insight = new Insight();
     $insight->slug = $this->slug;
     $insight->instance_id = $instance->id;
     $insight->date = $this->insight_date;
     $insight->related_data = array('map_points' => array_unique($geo_data));
     $insight->headline = $this->getHeadline($located_posts, 'month');
     $insight->text = $this->getText('month', $located_posts);
     $insight->emphasis = Insight::EMPHASIS_HIGH;
     $insight->setHeroImage($this->getHeroImage());
     $button = $this->getButton($instance);
     if ($button) {
         $insight->setButton($button);
     }
     $insight->filename = basename(__FILE__, ".php");
     $this->insight_dao->insertInsight($insight);
 }
Esempio n. 6
0
 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->logger->logInfo("Done generating insight (Skipped Non-Facebook)", __METHOD__ . ',' . __LINE__);
         return;
     }
     $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__);
         $post_dao = DAOFactory::getDAO('PostDAO');
         $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $instance->network);
         $topics = array('the Ice Bucket Challenge' => array('ice bucket', 'ALS Ice'), 'Robin Williams' => array('Robin Williams'), 'the Super Bowl' => array('Super Bowl', 'Superbowl'), 'MH370' => array('MH370', 'MH 370', 'Malaysia Airlines'), 'the World Cup' => array("World Cup"), 'the Sochi Olympics' => array('Sochi', 'Olympics'), 'LeBron James' => array('lebron'), 'Derek Jeter' => array('jeter'), 'Floyd Wayweather Jr.' => array('mayweather'), 'Carmelo Anthony' => array('carmelo'), 'Cristiano Ronaldo' => array('ronaldo'), 'Dale Earnhardt Jr.' => array('earnhardt'), 'Dale Earnhardt Jr.' => array('earnhardt'), 'Beyoncé' => array('beyonce'), 'Pharrell' => array('pharrell'), 'Nicki Minaj' => array('minaj'), 'Taylor Swift' => array('Taylor Swift'), 'Sam Smith' => array('Sam Smith'), 'Jimmy Fallon' => array('fallon'), 'Kim Kardashian' => array('kardashian'), 'Game of Thrones' => array('game of thrones'), 'Orange is the New Black' => array('Orange is the New Black', 'oitnb'), 'The Walking Dead' => array('walking dead'), 'Downton Abbey' => array('downton'), 'True Detective' => array('True Detective'), 'Guardians of the Galaxy' => array('Guardians of the Galaxy'), 'The Lego Movie' => array('lego movie'), 'Gone Girl' => array('Gone Girl'));
         $matches = array();
         foreach ($last_year_of_posts as $post) {
             foreach ($topics as $key => $strings) {
                 foreach ($strings as $string) {
                     if (stristr($post->post_text, $string) !== FALSE) {
                         $matches[$key] = array('term' => $key, 'post' => $post);
                         unset($topics[$key]);
                         break;
                     }
                 }
             }
         }
         $insight = new Insight();
         if (count($matches) == 0) {
             $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 . ")";
                 }
             }
             $headline = $this->username . " didn't rehash 2014's top news on Facebook";
             $insight_text = "No Ice Bucket Challenge, Robin Williams, or Malaysia Airlines here. " . $this->username . " broke away from the herd and avoided talking about 2014's biggest stories " . "on Facebook this year" . $qualified_year . '.';
             $posts = null;
             //Show avatar if there are no posts
             $insight->header_image = $user->avatar;
             //Show button if there are no posts
             $insight->setButton(array('url' => 'http://newsroom.fb.com/news/2014/12/2014-year-in-review/', 'label' => "See Facebook's Year in Review"));
         } else {
             $headline = $this->username . " was part of {$year}'s biggest trends";
             $posts = array();
             $mentioned = array();
             foreach ($matches as $m) {
                 if (count($posts) < 3) {
                     $posts[] = $m['post'];
                 }
                 $mentioned[] = $m['term'];
             }
             $num = count($mentioned);
             if ($num > 1) {
                 $mentioned[$num - 1] = 'and ' . $mentioned[$num - 1];
             }
             $mention_string = join($num == 2 ? ' ' : ', ', $mentioned);
             $thatwas = $num == 1 ? 'That was one' : 'Those were some';
             $insight_text = $this->username . "'s {$year} included {$mention_string}. {$thatwas} of " . '<a href="http://newsroom.fb.com/news/2014/12/2014-year-in-review/">Facebook\'s top topics of ' . "the year</a> &mdash; that's so {$year}!";
         }
         $insight->instance_id = $instance->id;
         $insight->slug = $this->slug;
         $insight->date = "{$year}-{$this->run_date}";
         $insight->headline = $headline;
         $insight->text = $insight_text;
         $insight->filename = basename(__FILE__, ".php");
         $insight->emphasis = Insight::EMPHASIS_HIGH;
         if ($posts) {
             $posts = array_slice($posts, 0, 12);
             $link_dao = DAOFactory::getDAO('LinkDAO');
             foreach ($posts as $post) {
                 $post->links = $link_dao->getLinksForPost($post->post_id, $post->network);
             }
             $insight->setPosts($posts);
         }
         $this->insight_dao->insertInsight($insight);
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }