Esempio n. 1
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__);
     $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__);
 }
Esempio n. 2
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__);
     $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__);
 }
Esempio n. 3
0
 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");
 }
Esempio n. 4
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. 5
0
 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 &ldquo;f**k&rdquo; ' . $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;
 }
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__);
     $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__);
     }
 }
Esempio n. 7
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__);
     $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__);
 }
Esempio n. 8
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__);
     $filename = basename(__FILE__, ".php");
     $insight_text = '';
     //Find out if insight already exists
     $should_generate_insight = self::shouldGenerateInsight('top_amplifier', $instance, date('Y-m-d'));
     if ($should_generate_insight) {
         //insight does not exist
         //Get yesterday's retweets
         $yesterdays_retweets = array();
         $simplified_date_yesterday = date('Y-m-d', strtotime('-1 day'));
         foreach ($last_week_of_posts as $post) {
             if ($post->in_retweet_of_post_id != null && $post->in_rt_of_user_id != null) {
                 $simplified_post_date = date('Y-m-d', strtotime($post->pub_date));
                 if ($simplified_date_yesterday == $simplified_post_date) {
                     $yesterdays_retweets[] = $post;
                 }
             }
         }
         $largest_added_audience = 0;
         $insight_retweeted_user = null;
         $insight_retweet = null;
         //Get top amplifier from yesterday
         foreach ($yesterdays_retweets as $post) {
             if (!isset($user_dao)) {
                 $user_dao = DAOFactory::getDAO('UserDAO');
             }
             $retweeted_user = $user_dao->getDetails($post->in_rt_of_user_id, $post->network);
             //if user exists and has fewer followers than instance user compare to current top
             if (isset($retweeted_user) && $retweeted_user->follower_count < $user->follower_count) {
                 $added_audience = $user->follower_count - $retweeted_user->follower_count;
                 if ($added_audience > $largest_added_audience) {
                     $largest_added_audience = $added_audience;
                     $insight_retweeted_user = $retweeted_user;
                     $insight_retweet = $post;
                 }
             }
         }
         //If there's a top amplifier from yesterday, insert the insight
         if ($largest_added_audience > 0 && isset($insight_retweeted_user) && isset($insight_retweet)) {
             $multiplier = floor($user->follower_count / $insight_retweeted_user->follower_count);
             if ($multiplier > 1 && TimeHelper::getTime() / 10 % 2 == 1) {
                 $largest_added_audience = number_format($multiplier) . 'x';
             } else {
                 $largest_added_audience = number_format($largest_added_audience);
             }
             $retweeted_username = $insight_retweeted_user->username;
             if ($instance->network == 'twitter') {
                 $retweeted_username = '******' . $retweeted_username;
             }
             $headline = $this->getVariableCopy(array($insight_retweeted_user->full_name . " can thank %username for %added more people seeing this %post", "%added more people saw %repostedee's %post thanks to %username", '%username boosted ' . $insight_retweeted_user->full_name . '\'s %post to %added more people'), array('repostedee' => $retweeted_username, 'added' => $largest_added_audience));
             $my_insight = new Insight();
             $my_insight->instance_id = $instance->id;
             $my_insight->slug = 'top_amplifier';
             //slug to label this insight's content
             $my_insight->date = date('Y-m-d');
             //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 = $insight_retweeted_user->avatar;
             $my_insight->emphasis = Insight::EMPHASIS_MED;
             $my_insight->filename = basename(__FILE__, ".php");
             $my_insight->setPosts(array($insight_retweet));
             $my_insight->setPeople(array($insight_retweeted_user));
             $this->insight_dao->insertInsight($my_insight);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Esempio n. 9
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__);
     $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__);
 }
Esempio n. 10
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__);
     $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__);
 }
Esempio n. 11
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__);
     $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->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('ferguson' => array("Ferguson", "Mike Brown", "Michael Brown"), 'obamacare' => array("Obamacare"), 'immigration' => array("immigration"), 'gamergate' => array("GamerGate"), 'isis' => array("ISIS"), 'israel' => array("Israel"), 'palestine' => array("Palestine"), 'hamas' => array("Hamas"), 'donaldsterling' => array("Donald Sterling"), 'marriage' => array("gay marriage", "marriage equality", "same-sex marriage"), 'ebola' => array("ebola"), 'climatechange' => array("climate change", "global warming"));
         $matches = array();
         foreach ($last_year_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;
                     }
                 }
             }
         }
         $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 . ' kept the drama off Facebook in 2014';
             $insight_text = $this->username . " avoided contentious topics like immigration and ebola in {$year}" . $qualified_year . ', which can be a good way to keep Facebook more friendly.';
             $posts = null;
             //Show avatar if there are no posts
             $insight->header_image = $user->avatar;
         } else {
             $headline = $this->username . " took on {$year}'s hot-button issues";
             $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);
             $insight_text = $this->username . " mentioned {$mention_string} on Facebook in {$year}. " . "It's great to use Facebook to discuss issues that matter.";
         }
         $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__);
 }
Esempio n. 13
0
 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     self::generateInsightBaselines($instance, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $insight_baseline_dao = DAOFactory::getDAO('InsightBaselineDAO');
     // We test for the presence of the high_fave_count_last_365_days since it's most likely to exist.
     $do365 = $insight_baseline_dao->doesInsightBaselineExistBefore('high_fave_count_last_365_days', $instance->id, date('Y-m-d', time() - 365 * 24 * 60 * 60));
     // We can skip this query if do365 is already true.
     $do30 = $do365 || $insight_baseline_dao->doesInsightBaselineExistBefore('high_fave_count_last_365_days', $instance->id, date('Y-m-d', time() - 30 * 24 * 60 * 60));
     // We can skip this query if do30 is already true.
     $do7 = $do30 || $insight_baseline_dao->doesInsightBaselineExistBefore('high_fave_count_last_365_days', $instance->id, date('Y-m-d', time() - 7 * 24 * 60 * 60));
     $post_date = '';
     $share_verb = $instance->network == 'twitter' ? 'retweeted' : 'reshared';
     $present_tense_share_verb = $instance->network == 'twitter' ? 'retweeting' : 'sharing';
     foreach ($last_week_of_posts as $post) {
         $headline = null;
         if ($post->network == 'instagram') {
             $photo_dao = DAOFactory::getDAO('PhotoDAO');
             $post = $photo_dao->getPhoto($post->post_id, 'instagram');
         }
         // Only show insight for posts with activity
         if ($post->favlike_count_cache > 2 || $post->all_retweets > 2 || $post->reply_count_cache > 2) {
             if ($post_date != date('Y-m-d', strtotime($post->pub_date))) {
                 $post_date = date('Y-m-d', strtotime($post->pub_date));
                 $baselines_to_load = array('avg_fave_count_last_7_days', 'avg_fave_count_last_30_days', 'high_fave_count_last_7_days', 'high_fave_count_last_30_days', 'high_fave_count_last_365_days', 'avg_retweet_count_last_7_days', 'avg_retweet_count_last_30_days', 'high_retweet_count_last_7_days', 'high_retweet_count_last_30_days', 'high_retweet_count_last_365_days', 'avg_reply_count_last_7_days', 'avg_reply_count_last_30_days', 'high_reply_count_last_7_days', 'high_reply_count_last_30_days', 'high_reply_count_last_365_days');
                 $baselines = array();
                 foreach ($baselines_to_load as $bl_slug) {
                     $baselines[$bl_slug] = $insight_baseline_dao->getInsightBaseline($bl_slug, $instance->id, $post_date);
                 }
             }
             $activities = array('reply' => 'reply_count_cache', 'retweet' => 'all_retweets', 'fave' => 'favlike_count_cache');
             // first we check 365 day highs
             if ($do365) {
                 $winning_percent = 0;
                 $winning_activity = null;
                 foreach ($activities as $activity => $object_key) {
                     if (isset($baselines['high_' . $activity . '_count_last_365_days']->value)) {
                         $base_value = $baselines['high_' . $activity . '_count_last_365_days']->value;
                         $value = $post->{$object_key};
                         $percent_change = $value / ($base_value == 0 ? 1 : $base_value);
                         if ($value > $base_value && $percent_change > $winning_percent) {
                             $winning_percent = $percent_change;
                             $winning_activity = $activity;
                         }
                     }
                 }
                 if ($winning_activity) {
                     $slug = $winning_activity . '_high_365_day_' . $post->id;
                     $emphasis = Insight::EMPHASIS_HIGH;
                     $my_insight_posts = array($post);
                     switch ($winning_activity) {
                         case 'fave':
                             $headline = "A 365-day record for " . $this->terms->getNoun('like', InsightTerms::PLURAL) . "!";
                             $insight_text = "<strong>" . number_format($post->favlike_count_cache) . " people</strong> " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post') . ".";
                             break;
                         case 'reply':
                             $headline = "{$this->username} got <strong>" . number_format($post->reply_count_cache) . " " . $this->terms->getNoun('reply', InsightTerms::PLURAL) . "</strong> &mdash; a 365-day high!";
                             $insight_text = "Why do you think this " . $this->terms->getNoun('post') . " did so well?";
                             break;
                         case 'retweet':
                             $headline = "A new 365-day record!";
                             $insight_text = "<strong>" . number_format($post->all_retweets) . " people</strong> {$share_verb} {$this->username}'s " . $this->terms->getNoun('post') . ".";
                             break;
                     }
                 }
             }
             if ($do30 && !$headline) {
                 $winning_percent = 0;
                 $winning_activity = null;
                 foreach ($activities as $activity => $object_key) {
                     if (isset($baselines['high_' . $activity . '_count_last_30_days']->value)) {
                         $base_value = $baselines['high_' . $activity . '_count_last_30_days']->value;
                         $value = $post->{$object_key};
                         $percent_change = $value / ($base_value == 0 ? 1 : $base_value);
                         if ($value > $base_value && $percent_change > $winning_percent) {
                             $winning_percent = $percent_change;
                             $winning_activity = $activity;
                         }
                     }
                 }
                 if ($winning_activity) {
                     $slug = $winning_activity . '_high_30_day_' . $post->id;
                     $emphasis = Insight::EMPHASIS_HIGH;
                     $my_insight_posts = array($post);
                     switch ($winning_activity) {
                         case 'fave':
                             $headline = "Highest number of " . $this->terms->getNoun('like', InsightTerms::PLURAL) . " in the past 30 days";
                             $insight_text = "<strong>" . number_format($post->favlike_count_cache) . " people</strong> " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post') . ".";
                             break;
                         case 'reply':
                             $headline = $this->username . " got <strong>" . number_format($post->reply_count_cache) . " " . $this->terms->getNoun('reply', InsightTerms::PLURAL) . "</strong>";
                             $insight_text = "That's a new 30-day record for {$this->username}.";
                             break;
                         case 'retweet':
                             $headline = "<strong>" . number_format($post->all_retweets) . " people</strong> {$share_verb} {$this->username}";
                             $insight_text = "That's the most one of " . $this->username . "'s " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " has been " . $share_verb . " in the past month!";
                             break;
                     }
                 }
             }
             if ($do7 && !$headline) {
                 $winning_percent = 0;
                 $winning_activity = null;
                 foreach ($activities as $activity => $object_key) {
                     if (isset($baselines['high_' . $activity . '_count_last_7_days']->value)) {
                         $base_value = $baselines['high_' . $activity . '_count_last_7_days']->value;
                         $value = $post->{$object_key};
                         $percent_change = $value / ($base_value == 0 ? 1 : $base_value);
                         if ($value > $base_value && $percent_change > $winning_percent) {
                             $winning_percent = $percent_change;
                             $winning_activity = $activity;
                         }
                     }
                 }
                 if ($winning_activity) {
                     $slug = $winning_activity . '_high_7_day_' . $post->id;
                     $emphasis = Insight::EMPHASIS_MED;
                     $my_insight_posts = array($post);
                     switch ($winning_activity) {
                         case 'fave':
                             $headline = $this->username . ' really got some ' . $this->terms->getNoun('like', InsightTerms::PLURAL);
                             $insight_text = "<strong>" . number_format($post->favlike_count_cache) . " people</strong> " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post') . ".";
                             break;
                         case 'reply':
                             $plural = $post->reply_count_cache == 1 ? InsightTerms::SINGULAR : InsightTerms::PLURAL;
                             $headline = $this->username . " got <strong>" . number_format($post->reply_count_cache) . " " . $this->terms->getNoun('reply', $plural) . '</strong>';
                             $insight_text = "That's a new 7-day record.";
                             break;
                         case 'retweet':
                             $headline = "<strong>" . number_format($post->all_retweets) . " people</strong> {$share_verb} {$this->username}";
                             $insight_text = "That's a new 7-day record.";
                             $emphasis = Insight::EMPHASIS_MED;
                             break;
                     }
                 }
             }
             if ($do30 && !$headline) {
                 $winning_percent = 0;
                 $winning_activity = null;
                 foreach ($activities as $activity => $object_key) {
                     if (isset($baselines['avg_' . $activity . '_count_last_30_days']->value)) {
                         $base_value = $baselines['avg_' . $activity . '_count_last_30_days']->value;
                         $value = $post->{$object_key};
                         $percent_change = $value / ($base_value == 0 ? 1 : $base_value);
                         if ($value > $base_value * 2 && $percent_change > $winning_percent) {
                             $winning_percent = $percent_change;
                             $winning_activity = $activity;
                             $winning_multiplier = floor($value / $base_value);
                         }
                     }
                 }
                 if ($winning_activity) {
                     $slug = $winning_activity . '_spike_30_day_' . $post->id;
                     $emphasis = Insight::EMPHASIS_MED;
                     $my_insight_posts = array($post);
                     switch ($winning_activity) {
                         case 'fave':
                             $headline = $this->username . ' got ' . $this->terms->getMultiplierAdverb($winning_multiplier) . ' the ' . $this->terms->getNoun('like', InsightTerms::PLURAL);
                             $insight_text = "<strong>" . number_format($post->favlike_count_cache) . " people</strong> " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post') . ", which is more than " . "<strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> {$this->username}'s 30-day average.";
                             break;
                         case 'reply':
                             $plural = $post->reply_count_cache == 1 ? InsightTerms::SINGULAR : InsightTerms::PLURAL;
                             $headline = $this->username . " got <strong>" . number_format($post->reply_count_cache) . " " . $this->terms->getNoun('reply', $plural) . '</strong>';
                             $insight_text = "That's more than <strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> " . $this->username . "'s 30-day average.";
                             break;
                         case 'retweet':
                             $headline = "<strong>" . number_format($post->all_retweets) . " people</strong>" . " {$share_verb} " . "{$this->username}!";
                             $insight_text = "Seems like this one is going viral. This " . $this->terms->getNoun('post') . " got more than <strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> {$this->username}'s 30-day average.";
                             break;
                     }
                 }
             }
             if ($do7 && !$headline) {
                 $winning_percent = 0;
                 $winning_activity = null;
                 foreach ($activities as $activity => $object_key) {
                     if (isset($baselines['avg_' . $activity . '_count_last_7_days']->value)) {
                         $base_value = $baselines['avg_' . $activity . '_count_last_7_days']->value;
                         $value = $post->{$object_key};
                         $percent_change = $value / ($base_value == 0 ? 1 : $base_value);
                         if ($value > $base_value * 2 && $percent_change > $winning_percent) {
                             $winning_percent = $percent_change;
                             $winning_activity = $activity;
                             $winning_multiplier = floor($value / $base_value);
                         }
                     }
                 }
                 if ($winning_activity) {
                     $slug = $winning_activity . '_spike_7_day_' . $post->id;
                     $emphasis = Insight::EMPHASIS_LOW;
                     $my_insight_posts = array($post);
                     switch ($winning_activity) {
                         case 'fave':
                             $headline = $this->username . ' hit a nerve this week';
                             $insight_text = "<strong>" . number_format($post->favlike_count_cache) . " people</strong> " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post') . ", more than <strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> {$this->username}'s 7-day average.";
                             break;
                         case 'reply':
                             $plural = $post->reply_count_cache == 1 ? InsightTerms::SINGULAR : InsightTerms::PLURAL;
                             $headline = $this->username . " got <strong>" . number_format($post->reply_count_cache) . " " . $this->terms->getNoun('reply', $plural) . '</strong>';
                             $insight_text = "That's more than <strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> {$this->username}'s 7-day average.";
                             break;
                         case 'retweet':
                             $headline = "<strong>" . number_format($post->all_retweets) . " people</strong> thought {$this->username} " . "was worth " . $present_tense_share_verb;
                             $insight_text = "That's more than <strong>" . $this->terms->getMultiplierAdverb($winning_multiplier) . "</strong> {$this->username}'s average over the last 7 days.";
                             break;
                     }
                 }
             }
             if (isset($slug) && isset($headline)) {
                 // Clean up previous insights for this post
                 $to_delete = array('fave_high_365', 'fave_high_30', 'fave_high_7', 'fave_spike_30', 'fave_spike_7', 'reply_high_365', 'reply_high_30', 'reply_high_7', 'reply_spike_30', 'reply_spike_7', 'retweet_high_365', 'retweet_high_30', 'retweet_high_7', 'retweet_spike_30', 'retweet_spike_7');
                 foreach ($to_delete as $base_slug) {
                     $delete_slug = $base_slug . '_day_' . $post->id;
                     if ($slug != $delete_slug) {
                         $this->insight_dao->deleteInsight($delete_slug, $instance->id, $post_date);
                     }
                 }
                 $my_insight = new Insight();
                 $my_insight->slug = $slug;
                 $my_insight->instance_id = $instance->id;
                 $my_insight->date = $post_date;
                 $my_insight->headline = $headline;
                 $my_insight->text = $insight_text;
                 $my_insight->header_image = '';
                 $my_insight->filename = basename(__FILE__, ".php");
                 $my_insight->emphasis = $emphasis;
                 if (isset($my_insight_posts)) {
                     $my_insight->setPosts($my_insight_posts);
                 }
                 $this->insight_dao->insertInsight($my_insight);
             }
             $headline = null;
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Esempio n. 14
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__);
     $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->getThisYearOfPostsWithLinksIterator($author_id = $instance->network_user_id, $network = $network);
         $domain_counts = $this->getDomainCounts($last_year_of_posts);
         $this->logger->logInfo("Got domain counts ", __METHOD__ . ',' . __LINE__);
         $popular_domain = $this->getPopularDomain($domain_counts);
         $this->logger->logInfo("Got popular domain " . Utils::varDumpToString($popular_domain), __METHOD__ . ',' . __LINE__);
         $posts = $this->getMostPopularPostsLinkingTo($instance, $popular_domain);
         $this->logger->logInfo("Got popular posts linking to ", __METHOD__ . ',' . __LINE__);
         $most_recent_unexpanded_link_date = $post_dao->getMostRecentUnexpandedLinkPubDate($instance);
         if (isset($most_recent_unexpanded_link_date)) {
             $this->logger->logInfo("Most recent unexpanded link date is " . $most_recent_unexpanded_link_date . " - " . date('Y-m-d', strtotime($most_recent_unexpanded_link_date)), __METHOD__ . ',' . __LINE__);
         } else {
             $this->logger->logInfo("No links have gone unexpanded ", __METHOD__ . ',' . __LINE__);
         }
         $qualified_year = "";
         if (isset($most_recent_unexpanded_link_date) && date('Y', strtotime($most_recent_unexpanded_link_date)) == date('Y')) {
             if (date('n', strtotime($most_recent_unexpanded_link_date)) > 1) {
                 //not January
                 //Earliest post was this year; figure out what month we have data since this year
                 $since = date('F', strtotime($most_recent_unexpanded_link_date));
                 $qualified_year = " (at least since " . $since . ")";
             }
         }
         $copy = array('twitter' => array('normal' => array('headline' => "ICYMI: %username's most linked-to site of {$year}", 'body' => "What's Twitter without the tabs? In {$year}, %username " . "shared more #content from <strong>%domain</strong> than from any other web " . "site%qualified_year. These were %username's most popular tweets with a link to " . "<strong>%domain</strong>."), 'one' => array('headline' => "ICYMI: %username's most linked-to site of {$year}", 'body' => "What's Twitter without the tabs? In {$year}, %username " . "shared more #content from <strong>%domain</strong> than from any other web " . "site%qualified_year. This was %username's most popular tweet with a link to " . "<strong>%domain</strong>."), 'none' => array('headline' => "%username tweeted nary a link in {$year}", 'body' => "This year, %username didn't post a single link on " . "Twitter%qualified_year. You can do better than that, internet!")), 'facebook' => array('normal' => array('headline' => "%username's most-shared site of {$year}", 'body' => "Looks like <strong>%domain</strong> owes %username a thank you. In " . "{$year}, %username directed friends to <strong>%domain</strong> more than " . "to any other site%qualified_year. Here are the posts with links to " . "<strong>%domain</strong>."), 'one' => array('headline' => "%username's most-shared site of {$year}", 'body' => "Looks like <strong>%domain</strong> owes %username a thank you. In " . "{$year}, %username directed friends to <strong>%domain</strong> more than " . "to any other site%qualified_year. Here is the post that links to <strong>%domain</strong>."), 'none' => array('headline' => "%username shared no links in {$year}", 'body' => "%username didn't share any links on Facebook this year%qualified_year. " . "Maybe the internet will do better in 2015!")));
         if (sizeof($posts) > 1) {
             $type = 'normal';
         } else {
             if (sizeof($posts) == 1) {
                 $type = 'one';
             } else {
                 $type = 'none';
                 //Don't show this insight if there are no multiple posts linking to a single popular domain
                 return;
             }
         }
         $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']));
         $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('domain' => str_replace('www.', '', $popular_domain), '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__);
 }
Esempio n. 15
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 (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__);
 }
Esempio n. 16
0
 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;
 }
Esempio n. 17
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. 18
0
 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;
 }
Esempio n. 19
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 == 'twitter') {
         $day_of_week = 3;
     } elseif ($instance->network == 'instagram') {
         $day_of_week = 5;
     } else {
         $day_of_week = 0;
     }
     $should_generate_insight = self::shouldGenerateWeeklyInsight('weekly_graph', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = $day_of_week, count($last_week_of_posts));
     if ($should_generate_insight) {
         $most_popular_post = null;
         $best_popularity_params = array('index' => 0, 'reply' => 0, 'retweet' => 0, 'like' => 0);
         $total_replies = 0;
         $total_retweets = 0;
         $total_likes = 0;
         $engaged_posts = array();
         //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;
         }
         foreach ($last_week_of_posts as $post) {
             $reply_count = $post->reply_count_cache;
             $retweet_count = $post->retweet_count_cache;
             $fav_count = $post->favlike_count_cache;
             $total_replies += $reply_count;
             $total_retweets += $retweet_count;
             $total_likes += $fav_count;
             if ($instance->network !== 'instagram') {
                 $popularity_index = 5 * $reply_count + 3 * $retweet_count + 2 * $fav_count;
             } else {
                 $popularity_index = 3 * $reply_count + 0 * $retweet_count + 5 * $fav_count;
             }
             if ($popularity_index > $best_popularity_params['index']) {
                 $best_popularity_params['index'] = $popularity_index;
                 $best_popularity_params['reply'] = $reply_count;
                 if ($instance->network !== 'instagram') {
                     $best_popularity_params['retweet'] = $retweet_count;
                 }
                 $best_popularity_params['like'] = $fav_count;
                 $most_popular_post = $post;
             }
             if ($popularity_index > 0) {
                 $post->popularity_index = $popularity_index;
                 $engaged_posts[] = $post;
             }
         }
         if (isset($most_popular_post)) {
             usort($engaged_posts, array($this, 'compareEngagedPosts'));
             $posts = array_slice($engaged_posts, 0, 10);
             if ($total_replies >= $total_likes && $total_replies >= $total_retweets) {
                 $insight_headline = $this->username . " really inspired conversations";
                 $lower = array();
                 if ($total_replies > $total_likes) {
                     $lower[] = $this->terms->getNoun('like', InsightTerms::PLURAL);
                 }
                 if ($total_replies > $total_retweets) {
                     $lower[] = $this->terms->getNoun('retweet', InsightTerms::PLURAL);
                 }
                 if (count($lower) == 0) {
                     $insight_text = $this->username . ' got more ' . $this->terms->getNoun('reply', InsightTerms::PLURAL) . " than anything else.";
                 } else {
                     $insight_text = 'In the past week, ' . $this->terms->getNoun('reply', InsightTerms::PLURAL) . ' to ' . $this->username . ' outnumbered ' . join(' or ', $lower) . '.';
                 }
             } else {
                 if ($total_likes >= $total_replies && $total_likes >= $total_retweets) {
                     if ($instance->network !== 'instagram') {
                         $insight_headline = "Whatever " . $this->username . " said must have been memorable";
                     } else {
                         $insight_headline = $this->username . " really won hearts";
                     }
                     $insight_text = 'In the past week, ' . $this->username . ' got ' . number_format($total_likes) . ' ' . $this->terms->getNoun('like', $total_likes == 1 ? InsightTerms::SINGULAR : InsightTerms::PLURAL);
                     $lower = array();
                     if ($total_likes > $total_replies && $total_replies > 0) {
                         $plural = $total_replies == 1 ? InsightTerms::SINGULAR : InsightTerms::PLURAL;
                         $lower[] = number_format($total_replies) . ' ' . $this->terms->getNoun('reply', $plural);
                     }
                     if ($total_likes > $total_retweets && $total_retweets > 0) {
                         $plural = $total_retweets == 1 ? InsightTerms::SINGULAR : InsightTerms::PLURAL;
                         $lower[] = number_format($total_retweets) . ' ' . $this->terms->getNoun('retweet', $plural);
                     }
                     if (count($lower) == 0) {
                         $insight_text .= '.';
                     } else {
                         $insight_text .= ', beating out ' . join(' and ', $lower) . '.';
                     }
                 } else {
                     $insight_headline = $this->username . " shared lots of things people wanted to amplify";
                     $lower = array();
                     if ($total_retweets > $total_replies) {
                         $lower[] = $this->terms->getNoun('reply', InsightTerms::PLURAL) . ' by ' . number_format($total_retweets - $total_replies);
                     }
                     if ($total_retweets > $total_likes) {
                         $lower[] = $this->terms->getNoun('like', InsightTerms::PLURAL) . ' by ' . number_format($total_retweets - $total_likes);
                     }
                     if (count($lower) > 0) {
                         $insight_text = 'This past week, ' . $this->username . "'s " . $this->terms->getNoun('retweet', InsightTerms::PLURAL) . ' outnumbered ' . join(' and ', $lower) . '.';
                     }
                 }
             }
             //Only show this insight if there's a chart with more than 3 posts on it
             if (count($posts) > 3) {
                 $my_insight = new Insight();
                 $my_insight->slug = 'weekly_graph';
                 $my_insight->instance_id = $instance->id;
                 $my_insight->date = $this->insight_date;
                 $my_insight->headline = $insight_headline;
                 $my_insight->text = $insight_text;
                 $my_insight->header_image = $user->avatar;
                 $my_insight->filename = basename(__FILE__, ".php");
                 $my_insight->emphasis = Insight::EMPHASIS_MED;
                 $formatted_posts = array(ChartHelper::getPostActivityVisualizationData($posts, $instance->network));
                 $my_insight->setPosts($formatted_posts);
                 $this->insight_dao->insertInsight($my_insight);
             } else {
                 $this->logger->logInfo("Not enough posts to display chart", __METHOD__ . ',' . __LINE__);
             }
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Esempio n. 20
0
 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     if ($instance->network == 'twitter') {
         parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
         $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
         if (self::shouldGenerateInsight('favorited_links', $instance, $insight_date = 'today', $regenerate_existing_insight = true)) {
             $fav_post_dao = DAOFactory::getDAO('FavoritePostDAO');
             $favorited_posts = $fav_post_dao->getRecentlyFavoritedPosts($instance->network_user_id, $instance->network, self::MAX_POSTS * 3);
             $todays_favorited_posts_with_links = array();
             $num_good_links = 0;
             $num_good_posts = 0;
             $seen_urls = array();
             foreach (array_reverse($favorited_posts) as $post) {
                 if (date('Y-m-d', strtotime($post->favorited_timestamp)) == date('Y-m-d')) {
                     $good_links = array();
                     $good_post = false;
                     foreach ($post->links as $link) {
                         if (!empty($link->title)) {
                             $url = !empty($link->expanded_url) ? $link->expanded_url : $link->url;
                             // Skipping photos that look like links
                             if (!preg_match('/pic.twitter.com/', $url) && !preg_match('/twitter.com\\/.*\\/photo\\//', $url)) {
                                 $seen_expanded = !empty($link->expanded_url) && in_array($link->expanded_url, $seen_urls);
                                 // Skip URLs we've seen before
                                 if (!$seen_expanded && !in_array($link->url, $seen_urls)) {
                                     $good_links[] = $link;
                                     $seen_urls[] = $link->url;
                                     $seen_urls[] = $link->expanded_url;
                                     $num_good_links++;
                                     $good_post = true;
                                 }
                             }
                         }
                     }
                     if ($good_post) {
                         $num_good_posts++;
                     }
                     if (count($good_links)) {
                         $post->links = $good_links;
                         $todays_favorited_posts_with_links[] = $post;
                     }
                 }
             }
             $todays_favorited_posts_with_links = array_reverse($todays_favorited_posts_with_links);
             $todays_favorited_posts_with_links = array_slice($todays_favorited_posts_with_links, 0, self::MAX_POSTS);
             if ($num_good_posts) {
                 if ($num_good_posts == 1) {
                     if ($num_good_links == 1) {
                         $insight_text = $this->username . " " . $this->terms->getVerb('liked') . " 1 " . $this->terms->getNoun('post') . " with a link in it.";
                     } else {
                         $insight_text = $this->username . " " . $this->terms->getVerb('liked') . " 1 " . $this->terms->getNoun('post') . " with <strong>{$num_good_links} links</strong> in it.";
                     }
                 } else {
                     if ($num_good_posts >= self::MAX_POSTS) {
                         //Since number of posts is at max limit, some may have been cut off
                         //So let's not cite specific totals
                         $insight_text = "Here are the latest links from " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " " . $this->username . " " . $this->terms->getVerb('liked') . ".";
                     } else {
                         $insight_text = $this->username . " " . $this->terms->getVerb('liked') . " " . $num_good_posts . " " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " with <strong>{$num_good_links} links</strong> in them.";
                     }
                 }
                 $my_insight = new Insight();
                 $my_insight->instance_id = $instance->id;
                 $my_insight->slug = 'favorited_links';
                 $my_insight->date = $this->insight_date;
                 $my_insight->headline = $this->getVariableCopy(array('The latest link%s %username %liked', '%total link%s %username %liked'), array('total' => number_format($num_good_links), 's' => $num_good_links == 1 ? '' : 's'));
                 $my_insight->text = $insight_text;
                 $my_insight->header_image = '';
                 $my_insight->emphasis = Insight::EMPHASIS_LOW;
                 $my_insight->filename = basename(__FILE__, ".php");
                 $my_insight->setPosts($todays_favorited_posts_with_links);
                 $this->insight_dao->insertInsight($my_insight);
             }
         }
         $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
     }
 }
Esempio n. 21
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__);
     //Monthly
     $did_monthly = false;
     $should_generate_insight = $this->shouldGenerateMonthlyInsight($slug = 'monthly_best', $instance, $this->insight_date, $regenerate_existing_insight = false, $day_of_month = 1, $count_related_posts = null, $excluded_networks = null, $enable_bonus_alternate_day = false);
     if ($should_generate_insight) {
         $most_popular_post = null;
         $best_popularity_params = array('index' => 0, 'reply' => 0, 'retweet' => 0, 'like' => 0);
         $insight_text = '';
         $post_dao = DAOFactory::getDAO('PostDAO');
         //There's probably a better way to get the number of days in last month
         $last_month_time = strtotime('first day of last month');
         $last_month_year = date('Y', $last_month_time);
         $last_month_month = date('m', $last_month_time);
         $days_of_posts_to_retrieve = TimeHelper::getDaysInMonth($last_month_year, $last_month_month);
         $last_months_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = $days_of_posts_to_retrieve, $iterator = false, $is_public = false);
         foreach ($last_months_posts as $post) {
             if ($post->network == 'instagram') {
                 $photo_dao = DAOFactory::getDAO('PhotoDAO');
                 $post = $photo_dao->getPhoto($post->post_id, 'instagram');
             }
             $reply_count = $post->reply_count_cache;
             $retweet_count = $post->retweet_count_cache;
             $fav_count = $post->favlike_count_cache;
             $popularity_index = 5 * $reply_count + 3 * $retweet_count + 2 * $fav_count;
             if ($popularity_index > $best_popularity_params['index']) {
                 $best_popularity_params['index'] = $popularity_index;
                 $best_popularity_params['reply'] = $reply_count;
                 $best_popularity_params['retweet'] = $retweet_count;
                 $best_popularity_params['like'] = $fav_count;
                 $most_popular_post = $post;
             }
         }
         if (isset($most_popular_post)) {
             $my_insight = new Insight();
             $my_insight->headline = $this->getVariableCopy(array('%username\'s best of %last_month'), array('last_month' => date('F', $last_month_time)));
             if ($instance->network == 'instagram' && $most_popular_post->is_short_video) {
                 $my_insight->text = $this->getVariableCopy(array("Happy %new_month! %username's most popular Instagram post of %last_month %month_year was a video.", "Welcome to %new_month! This video was %username's most popular Instagram post " . "of %last_month %month_year."), array('last_month' => date('F', $last_month_time), 'month_year' => date('Y', $last_month_time), 'new_month' => date('F')));
             } else {
                 $my_insight->text = $this->getVariableCopy(array("Happy %new_month! This was %username's most popular %post of %last_month %month_year.", "Welcome to %new_month! Take a quick look back at %username's most popular %post " . "of %last_month %month_year."), array('last_month' => date('F', $last_month_time), 'month_year' => date('Y', $last_month_time), 'new_month' => date('F')));
             }
             $my_insight->slug = 'monthly_best';
             //slug to label this insight's content
             $my_insight->instance_id = $instance->id;
             $my_insight->date = $this->insight_date;
             //date is often this or $simplified_post_date
             $my_insight->filename = basename(__FILE__, ".php");
             $my_insight->emphasis = Insight::EMPHASIS_HIGH;
             $my_insight->setPosts(array($most_popular_post));
             $this->insight_dao->insertInsight($my_insight);
             $did_monthly = true;
         }
     }
     //Weekly
     if ($instance->network == 'twitter') {
         $day_of_week = 4;
     } elseif ($instance->network == 'instagram') {
         $day_of_week = 2;
     } else {
         $day_of_week = 0;
     }
     $should_generate_insight = self::shouldGenerateWeeklyInsight('weekly_best', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = $day_of_week, count($last_week_of_posts));
     if (!$did_monthly && $should_generate_insight) {
         $most_popular_post = null;
         $best_popularity_params = array('index' => 0, 'reply' => 0, 'retweet' => 0, 'like' => 0);
         $insight_text = '';
         foreach ($last_week_of_posts as $post) {
             if ($post->network == 'instagram') {
                 $photo_dao = DAOFactory::getDAO('PhotoDAO');
                 $post = $photo_dao->getPhoto($post->post_id, 'instagram');
             }
             $reply_count = $post->reply_count_cache;
             $retweet_count = $post->retweet_count_cache;
             $fav_count = $post->favlike_count_cache;
             $popularity_index = 5 * $reply_count + 3 * $retweet_count + 2 * $fav_count;
             if ($popularity_index > $best_popularity_params['index']) {
                 $best_popularity_params['index'] = $popularity_index;
                 $best_popularity_params['reply'] = $reply_count;
                 $best_popularity_params['retweet'] = $retweet_count;
                 $best_popularity_params['like'] = $fav_count;
                 $most_popular_post = $post;
             }
         }
         if (isset($most_popular_post)) {
             if ($instance->network !== 'instagram') {
                 $headlines = array("{$this->username}'s biggest %post last week", "{$this->username}'s most popular %post last week");
             } else {
                 //Instagram: Be video-aware
                 if ($most_popular_post->is_short_video) {
                     $headlines = array("{$this->username}'s biggest post last week was a video", "{$this->username}'s most popular post last week was a video");
                 } else {
                     $headlines = array("{$this->username}'s biggest %post last week", "{$this->username}'s most popular %post last week");
                 }
             }
             $insight_text = $this->username . " earned ";
             foreach ($best_popularity_params as $key => $value) {
                 if ($value && $key != 'index') {
                     $insight_text .= "<strong>" . $value . " " . $this->terms->getNoun($key, $value > 1) . "</strong>, ";
                 }
             }
             $insight_text = rtrim($insight_text, ", ");
             $insight_text .= '.';
             if (!(strpos($insight_text, ',') === false)) {
                 $insight_text = substr_replace($insight_text, " and", strpos($insight_text, strrchr($insight_text, ',')), 1);
             }
             $simplified_post_date = date('Y-m-d', strtotime($most_popular_post->pub_date));
             $my_insight = new Insight();
             $my_insight->slug = 'weekly_best';
             //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 = $this->getVariableCopy($headlines);
             $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->setPosts(array($most_popular_post));
             $this->insight_dao->insertInsight($my_insight);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Esempio n. 22
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__);
     $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;
         }
         //Populate Instagram photos
         if ($instance->network == 'instagram') {
             $photo_dao = DAOFactory::getDAO('PhotoDAO');
             $popular_photos = array();
             foreach ($top_posts as $key => $post) {
                 $post = $photo_dao->getPhoto($post->post_id, 'instagram');
                 $popular_photos[] = $post;
             }
             $top_posts = $popular_photos;
         }
         $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")), 'instagram' => array('normal' => array('headline' => "%username's biggest Instagram posts of each month in %year", 'body' => "The calendar is about to flip to a new year. Before it does, check out " . "%username's most popular Instagram photos and videos 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__);
 }
Esempio n. 23
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__);
     $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__);
 }
Esempio n. 24
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__);
     $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__);
 }
Esempio n. 25
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__);
     $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;
         }
         $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 . ".")));
         $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__);
     }
 }
Esempio n. 26
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 (self::shouldGenerateInsight('posts_on_this_day_popular_flashback', $instance)) {
         //Generate flashback post list
         $post_dao = DAOFactory::getDAO('PostDAO');
         $flashback_posts = $post_dao->getOnThisDayFlashbackPosts($instance->network_user_id, $instance->network, $this->insight_date);
         $posts = array();
         $most_popular_post = null;
         $most_responses = 0;
         $insight_text = '';
         if (isset($flashback_posts) && sizeof($flashback_posts) > 0) {
             foreach ($flashback_posts as $post) {
                 if ($post->network == 'instagram') {
                     $photo_dao = DAOFactory::getDAO('PhotoDAO');
                     $post = $photo_dao->getPhoto($post->post_id, 'instagram');
                 }
                 $total_responses = $post->reply_count_cache + $post->all_retweets + $post->favlike_count_cache;
                 if ($total_responses > 0 && $total_responses > $most_responses) {
                     $most_popular_post = $post;
                     $most_responses = $total_responses;
                 }
             }
             if (isset($most_popular_post)) {
                 $post_year = date(date('Y', strtotime($most_popular_post->pub_date)));
                 $current_year = date('Y');
                 $number_of_years_ago = $current_year - $post_year;
                 $plural = $number_of_years_ago > 1 ? 's' : '';
                 $time = strtotime("-" . $number_of_years_ago . " year", time());
                 $past_date = date('Y', $time);
                 $post_term = $most_popular_post->is_short_video ? 'video' : $this->terms->getNoun('post');
                 if (TimeHelper::getTime() % 2 == 0) {
                     if ($number_of_years_ago == 1) {
                         $headlines = array("A year ago today");
                     } else {
                         $headlines = array("%number_of_years_ago years ago today");
                     }
                     $insight_text = "On this day in " . $past_date . ", this was {$this->username}'s most popular " . $post_term . ".";
                 } else {
                     $headlines = array("On this day in " . $past_date);
                     $insight_text = "This was {$this->username}'s most popular " . $post_term . " <strong>{$number_of_years_ago} year{$plural} ago</strong>.";
                 }
                 $posts[] = $most_popular_post;
                 $my_insight = new Insight();
                 $my_insight->instance_id = $instance->id;
                 $my_insight->slug = 'posts_on_this_day_popular_flashback';
                 //slug to label this insight's content
                 $my_insight->date = $this->insight_date;
                 //date of the data this insight applies to
                 $my_insight->headline = $this->getVariableCopy($headlines, array('number_of_years_ago' => $number_of_years_ago));
                 $my_insight->text = $insight_text;
                 $my_insight->emphasis = Insight::EMPHASIS_LOW;
                 $my_insight->filename = basename(__FILE__, ".php");
                 $my_insight->setPosts($posts);
                 $this->insight_dao->insertInsight($my_insight);
             }
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Esempio n. 27
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__);
     $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__);
     }
 }
Esempio n. 28
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__);
 }