本文整理汇总了PHP中Insight类的典型用法代码示例。如果您正苦于以下问题:PHP Insight类的具体用法?PHP Insight怎么用?PHP Insight使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Insight类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
if ($this->shouldGenerateInsight($this->slug, $instance, $insight_date = 'today', $regenerate = false)) {
$baseline_dao = DAOFactory::getDAO('InsightBaselineDAO');
$met_milestone = 0;
foreach ($this->milestones as $count => $text) {
if ($user->follower_count > $count && $user->follower_count < $count * 2) {
$met_milestone = $count;
} else {
if ($user->follower_count < $count) {
break;
}
}
}
if ($met_milestone) {
$baseline = $baseline_dao->getMostRecentInsightBaseline('follower_vis_last_run', $instance->id);
if (!isset($baseline->value) || isset($baseline->value) && $met_milestone > $baseline->value) {
$baseline_dao->insertInsightBaseline('follower_vis_last_run', $instance->id, $met_milestone);
$insight = new Insight();
$insight->slug = $this->slug;
$insight->instance_id = $instance->id;
$insight->date = $this->insight_date;
$insight->filename = basename(__FILE__, ".php");
$insight->emphasis = Insight::EMPHASIS_HIGH;
$insight->headline = $this->getVariableCopy(array($this->milestones[$met_milestone]['headline']), array('total' => number_format($user->follower_count)));
$insight->text = $this->getVariableCopy(array($this->milestones[$met_milestone]['text']), array('total' => number_format($user->follower_count), 'thres' => number_format($met_milestone)));
$insight->setHeroImage($this->milestones[$met_milestone]["hero_image"]);
$this->insight_dao->insertInsight($insight);
}
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例2: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
if (Utils::isTest() || date("Y-m-d") == '2015-02-23') {
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-02/oscars2015.jpg', 'alt_text' => 'Oprah got a Lego Oscar!', 'credit' => 'Photo: Disney | ABC Television Group', 'img_link' => 'https://www.flickr.com/photos/disneyabc/16620198142');
$post_dao = DAOFactory::getDAO('PostDAO');
$last_month_of_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = 30, $iterator = false, $is_public = false);
if (self::shouldGenerateWeeklyInsight('oscars_2015', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = 1, count($last_month_of_posts))) {
foreach ($last_month_of_posts as $post) {
$this->logger->logInfo("Post text is: " . $post->post_text, __METHOD__ . ',' . __LINE__);
// see if $post date is before the awards aired
if ($post->pub_date < "2015-02-22 18:00:00") {
$mentioned_oscar_winner = self::detectOscarWinnerReferences($post->post_text);
$mentioned_oscar_loser = self::detectOscarLoserReferences($post->post_text);
$oscar_mention_count = self::countOscarMentions($post->post_text);
if ($mentioned_oscar_winner) {
$this->logger->logInfo("Winner mention: {$mentioned_oscar_winner}", __METHOD__ . ',' . __LINE__);
$insight_body = "{$this->username} was talking about {$mentioned_oscar_winner} before the " . "Academy Award winners were even announced!";
} else {
$this->logger->logInfo("No winners mentioned, skipping insight. ", __METHOD__ . ',' . __LINE__);
}
if ($mentioned_oscar_loser) {
$this->logger->logInfo("Loser mention: {$mentioned_oscar_loser}", __METHOD__ . ',' . __LINE__);
$insight_body_suffix = " Looks like the Academy voters might have missed " . "{$this->username}'s " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " about " . $mentioned_oscar_loser . ", though.";
}
}
}
if ($insight_body_suffix) {
$insight_text = $insight_body . $insight_body_suffix;
} else {
$insight_text = $insight_body;
}
if ($insight_body) {
$headline = "Somebody was ready for the Oscars party!";
$my_insight = new Insight();
$my_insight->slug = 'oscars_2015';
//slug to label this insight's content
$my_insight->instance_id = $instance->id;
$my_insight->date = $this->insight_date;
//date is often this or $simplified_post_date
$my_insight->headline = $headline;
// or just set a string like 'Ohai';
$my_insight->text = $insight_text;
// or just set a strong like "Greetings humans";
$my_insight->filename = basename(__FILE__, ".php");
//Same for every insight, must be set this way
$my_insight->emphasis = Insight::EMPHASIS_HIGH;
//Optional emphasis, default Insight::EMPHASIS_LOW
$my_insight->setHeroImage($hero_image);
$this->insight_dao->insertInsight($my_insight);
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
}
示例3: generateInsight
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__);
}
示例4: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
if ($instance->network == 'facebook' && $this->shouldGenerateMonthlyInsight($slug, $instance, 'today', false, 15)) {
$ok_to_generate = false;
// Find the last time we prompted (or "beginning of time" if we have never prompted)
$baseline_slug = 'facebook_profile_prompted';
$insight_baseline_dao = DAOFactory::getDAO('InsightBaselineDAO');
$last_baseline = $insight_baseline_dao->getMostRecentInsightBaseline($baseline_slug, $instance->id);
$last_prompted = 0;
if ($last_baseline) {
$last_prompted = strtotime($last_baseline->date);
}
// Only prompt at most every other month. At least 57 days are between two 15ths of the month.
$time_diff = time() - $last_prompted;
if ($time_diff > 60 * 60 * 24 * 57) {
// Swap for the FacebookInstance so we have profile_updated
$facebook_instance_dao = DAOFactory::getDAO('FacebookInstanceDAO');
$instance = $facebook_instance_dao->get($instance->id);
$profile_updated_ts = time();
if ($instance->profile_updated) {
$profile_updated_ts = strtotime($instance->profile_updated);
}
$time_since_update = time() - $profile_updated_ts;
if ($time_since_update > 60 * 60 * 24 * 60) {
$ok_to_generate = true;
}
}
if ($ok_to_generate) {
$insight = new Insight();
$insight->slug = 'facebook_profile_prompt';
$insight->filename = basename(__FILE__, ".php");
$insight->emphasis = Insight::EMPHASIS_LOW;
$insight->instance_id = $instance->id;
$insight->date = $this->insight_date;
$months = floor($time_since_update / (60 * 60 * 24 * 30));
$insight->headline = $this->getVariableCopy(array("%username's %months-month-old profile", "%username's Facebook profile is a little stale"), array('months' => $months));
if (date('Y') == date('Y', $profile_updated_ts)) {
$nice_date = date('F jS', $profile_updated_ts);
} else {
$nice_date = date('F jS, Y', $profile_updated_ts);
}
$insight->text = $this->getVariableCopy(array("%username's Facebook profile hasn't been updated since {$nice_date}. " . "Might be worth checking if it's still up to date. ", "%username's Facebook profile hasn't been updated since {$nice_date}. " . "Can't hurt to see if that profile info is still accurate. "));
$insight->setButton(array('label' => 'Edit Facebook Profile', 'url' => 'https://www.facebook.com/me?sk=info&edit=eduwork&ref=update_info_button'));
$this->insight_dao->insertInsight($insight);
$insight_baseline_dao->insertInsightBaseline($baseline_slug, $instance->id, $months);
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例5: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
if (Utils::isTest() || date("Y-m-d") == '2014-02-23') {
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2014-02/olympics2014.jpg', 'alt_text' => 'The Olympic rings in Sochi', 'credit' => 'Photo: Atos International', 'img_link' => 'http://www.flickr.com/photos/atosorigin/12568057033/');
$post_dao = DAOFactory::getDAO('PostDAO');
$last_month_of_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = 30, $iterator = false, $is_public = false);
if (self::shouldGenerateWeeklyInsight('olympics_2014', $instance, $insight_date = 'today', $regenerate_existing_insight = true, $day_of_week = 0, count($last_month_of_posts))) {
$event_count = 0;
foreach ($last_month_of_posts as $post) {
$event_count += self::countOlympicReferences($post->post_text);
}
$this->logger->logInfo("There are {$event_count} Olympic-related mentions", __METHOD__ . ',' . __LINE__);
if ($event_count > 0) {
$headline = "Do they give out medals for " . $this->terms->getNoun('post', InsightTerms::PLURAL) . "?";
$insight_text = "{$this->username} mentioned ";
if ($event_count > 0) {
$this->logger->logInfo("There are event mentions", __METHOD__ . ',' . __LINE__);
$insight_text .= "the Olympics ";
if ($event_count > 1) {
$this->logger->logInfo("there is more than one event mention", __METHOD__ . ',' . __LINE__);
$insight_text .= "{$event_count} times since they started.";
$insight_text .= " That's kind of like winning {$event_count} gold medals in " . ucfirst($instance->network) . ", right?";
} else {
$insight_text .= "just as the whole world's attention was focused on the Games.";
$insight_text .= " That's a pretty great way to join a global conversation.";
}
}
$my_insight = new Insight();
$my_insight->slug = 'olympics_2014';
//slug to label this insight's content
$my_insight->instance_id = $instance->id;
$my_insight->date = $this->insight_date;
//date is often this or $simplified_post_date
$my_insight->headline = $headline;
// or just set a string like 'Ohai';
$my_insight->text = $insight_text;
// or just set a strong like "Greetings humans";
$my_insight->filename = basename(__FILE__, ".php");
//Same for every insight, must be set this way
$my_insight->emphasis = Insight::EMPHASIS_HIGH;
//Optional emphasis, default is Insight::EMPHASIS_LOW
$my_insight->setHeroImage($hero_image);
$this->insight_dao->insertInsight($my_insight);
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
}
示例6: generateInsight
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__);
}
示例7: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$year = date('Y');
$regenerate = false;
//testing
//$regenerate = true;
$should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date);
if ($should_generate_insight) {
$this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
$insight = new Insight();
$insight->instance_id = $instance->id;
$insight->slug = $this->slug;
$insight->date = "{$year}-{$this->run_date}";
$post_dao = DAOFactory::getDAO('PostDAO');
$network = $instance->network;
$last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network);
$streaks = $this->getStreaks($last_year_of_posts);
$longest_streak = $this->getLongestStreak($streaks);
$earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance);
$qualified_year = $year;
if (date('Y', strtotime($earliest_pub_date)) == date('Y')) {
if (date('n', strtotime($earliest_pub_date)) > 1) {
//not January
//Earliest post was this year; figure out what month we have data since this year
$since = date('F', strtotime($earliest_pub_date));
$qualified_year = $year . " (at least since " . $since . ")";
}
}
$copy = array('twitter' => array('normal' => array('headline' => "%username's longest tweet-streak of %year", 'body' => "Sometimes the tweets flow like water and you just " . "don't need a day off. In %qualified_year, %username's longest " . "tweeting streak lasted for <strong>%total days</strong>, from %date1 to %date2."), 'everyday' => array('headline' => "%username has tweeted every single day in %year!", 'body' => "Sometimes the tweets flow like water and you just " . "don't need a day off. So far in %qualified_year, %username hasn't taken off " . "a single day, with a streak that has so far lasted for <strong>%total " . "days</strong>, from %date1 to %date2.")), 'facebook' => array('normal' => array('headline' => "%username's longest update streak of %year", 'body' => "Facebook is great for sharing what we're up to, " . "and sometimes we're up to a lot. In %qualified_year, %username " . "posted at least one status update or comment to Facebook " . "for <strong>%total days</strong> in a row, from %date1 to %date2."), 'everyday' => array('headline' => "%username has posted to Facebook every single day in %year!", 'body' => "Facebook is great for sharing what we're up to, and in %year, " . "%username was up to a lot — posting at least one time every day " . "so far in %qualified_year for a streak of <strong>%total days</strong>, " . "from %date1 through %date2.")), 'instagram' => array('normal' => array('headline' => "%username's longest Instagram streak of %year", 'body' => "Instagram is the place to share scenes from your life, " . "and sometimes there's a lot of life to share. In %qualified_year, %username " . "posted at least one photo or video on Instagram " . "for <strong>%total days</strong> in a row, from %date1 to %date2."), 'everyday' => array('headline' => "%username has posted to Instagram every single day in %year!", 'body' => "Instagram is the place to share scenes from your life, and in %year, " . "%username had lots of life to share — posting at least one time every day " . "so far in %qualified_year for a streak of <strong>%total days</strong>, " . "from %date1 through %date2.")));
if ($longest_streak['length'] - 2 == date('z') - 1) {
$type = 'everyday';
} else {
$type = 'normal';
}
$headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year));
$insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'total' => $longest_streak['length'], 'date1' => $this->getDateFromDay($longest_streak['start_day'], 'F jS'), 'date2' => $this->getDateFromDay($longest_streak['end_day'], 'F jS'), 'qualified_year' => $qualified_year));
$milestones = array("per_row" => 1, "label_type" => "text", "items" => array(0 => array("number" => $longest_streak['length'], "label" => "days")));
$insight->setMilestones($milestones);
$insight->headline = $headline;
$insight->text = $insight_text;
$insight->filename = basename(__FILE__, ".php");
$insight->emphasis = Insight::EMPHASIS_HIGH;
$insight->header_image = $user->avatar;
$this->insight_dao->insertInsight($insight);
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例8: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
if ($instance->network == 'twitter') {
$day_of_week = 4;
} else {
$day_of_week = 1;
}
$should_generate_insight = self::shouldGenerateWeeklyInsight('long_lost_contacts', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = $day_of_week);
if ($should_generate_insight) {
$follow_dao = DAOFactory::getDAO('FollowDAO');
$contacts = $follow_dao->getFolloweesRepliedToThisWeekLastYear($instance->network_user_id, $instance->network);
$long_lost_contacts = array();
$insight_text = '';
if (count($contacts)) {
$post_dao = DAOFactory::getDAO('PostDAO');
foreach ($contacts as $contact) {
if ($post_dao->getDaysAgoSinceUserRepliedToRecipient($instance->network_user_id, $contact->user_id, $instance->network) >= 365) {
$long_lost_contacts[] = $contact;
}
}
}
if (count($long_lost_contacts)) {
$headline = $this->username . " hasn't replied to " . (count($long_lost_contacts) > 1 ? "<strong>" . count($long_lost_contacts) . " people</strong> " : $long_lost_contacts[0]->full_name . " ") . "in over a year";
$insight_text = "It's good to reflect after some time has passed.";
//Instantiate the Insight object
$my_insight = new Insight();
//REQUIRED: Set the insight's required attributes
$my_insight->slug = 'long_lost_contacts';
//slug to label this insight's content
$my_insight->instance_id = $instance->id;
$my_insight->date = $this->insight_date;
//date is often this or $simplified_post_date
$my_insight->headline = $headline;
// or just set a string like 'Ohai';
$my_insight->text = $insight_text;
// or just set a strong like "Greetings humans";
if (count($long_lost_contacts) == 1) {
$my_insight->header_image = $long_lost_contacts[0]->avatar;
}
$my_insight->filename = basename(__FILE__, ".php");
$my_insight->emphasis = Insight::EMPHASIS_MED;
$my_insight->setPeople($long_lost_contacts);
$this->insight_dao->insertInsight($my_insight);
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例9: generateInsight
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__);
}
示例10: getInsightForCounts
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;
}
示例11: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$year = date('Y');
$regenerate = false;
//testing
//$regenerate = true;
$should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date);
if ($should_generate_insight) {
$this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
$insight = new Insight();
$insight->instance_id = $instance->id;
$insight->slug = $this->slug;
$insight->date = "{$year}-{$this->run_date}";
$top_three_replied_to = $this->topThreeThisYear($instance);
foreach ($top_three_replied_to as $key => $post) {
$post->author_avatar = $user->avatar;
}
//Populate Instagram photos
if ($instance->network == 'instagram') {
$photo_dao = DAOFactory::getDAO('PhotoDAO');
$popular_photos = array();
foreach ($top_three_replied_to as $key => $post) {
$post = $photo_dao->getPhoto($post->post_id, 'instagram');
$popular_photos[] = $post;
}
$top_three_replied_to = $popular_photos;
}
$post_dao = DAOFactory::getDAO('PostDAO');
$earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance);
$qualified_year = "";
if (date('Y', strtotime($earliest_pub_date)) == date('Y')) {
if (date('n', strtotime($earliest_pub_date)) > 1) {
//not January
//Earliest post was this year; figure out what month we have data since this year
$since = date('F', strtotime($earliest_pub_date));
$qualified_year = " (at least since " . $since . ")";
}
}
$copy = array('twitter' => array('normal' => array('headline' => "%username's most replied-to tweets of %year", 'body' => "Come for the faves, stay for the mentions. " . "In %year, %username inspired the most conversation in " . "these tweets%qualified_year."), 'one' => array('headline' => "%username's most replied-to tweet of %year", 'body' => "Come for the faves, stay for the mentions. " . "In %year, %username inspired the most conversation in " . "this tweet%qualified_year."), 'none' => array('headline' => "Let's talk", 'body' => "%username didn't get any replies in %year" . $qualified_year . ", but that's " . "about to change. Give @thinkup a mention — we love to talk!")), 'facebook' => array('normal' => array('headline' => "%username's most commented-on status updates of %year", 'body' => "Some status updates are meant to " . "be trivial. Others sow the seeds of meaningful " . "conversation. In %year, %username received the most comments " . "on these status updates%qualified_year."), 'one' => array('headline' => "%username's most commented-on status update of %year", 'body' => "Some status updates are meant to " . "be trivial. Others sow the seeds of meaningful " . "conversation. In %year, %username received the most comments " . "on this status update%qualified_year."), 'none' => array('headline' => "No comment", 'body' => "Is this thing on? No one commented on %username's " . "status updates on Facebook in %year" . $qualified_year . ".")), 'instagram' => array('normal' => array('headline' => "%username's most commented-on Instagram posts of %year", 'body' => "There's lots of eye candy on Instagram, and not much conversation. " . "But some photos and videos are so good people can't help but respond. " . "In %year, %username received the most comments " . "on these Instagram posts%qualified_year."), 'one' => array('headline' => "%username's most commented-on Instagram of %year", 'body' => "There's lots of eye candy on Instagram, and not much conversation. " . "But some photos and videos are so good people can't help but respond. " . "In %year, %username received the most comments " . "on these Instagram posts%qualified_year."), 'none' => array('headline' => "No comment", 'body' => "Is this thing on? No one commented on %username's " . "Instagram photos and videos in %year" . $qualified_year . ".")));
$network = $instance->network;
if (sizeof($top_three_replied_to) > 1) {
$type = 'normal';
} else {
if (sizeof($top_three_replied_to) == 1) {
$type = 'one';
} else {
$type = 'none';
}
}
$insight->headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year));
$insight->text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'qualified_year' => $qualified_year));
$insight->emphasis = Insight::EMPHASIS_HIGH;
$insight->filename = basename(__FILE__, ".php");
$insight->setPosts($top_three_replied_to);
$this->insight_dao->insertInsight($insight);
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
}
示例12: getInsightForCounts
public function getInsightForCounts($this_period_count, $last_period_count, $instance, $matching_posts)
{
$insight = null;
if ($this_period_count > 0) {
$insight = new Insight();
$insight->slug = $this->getSlug();
$insight->instance_id = $instance->id;
$insight->date = $this->insight_date;
$insight->filename = basename(__FILE__, ".php");
$insight->emphasis = Insight::EMPHASIS_MED;
$insight->headline = $this->getVariableCopy(array('30 days of !!!', 'OMG %username is serious!'));
$showchart = count($this->point_chart) > 2;
$insight->text = $this->getVariableCopy(array("%username used exclamation points in %total %post" . ($this_period_count == 1 ? '' : 's') . " this past month! " . ($showchart ? "" : "That's %percent% of %username's %posts!")), array('total' => $this_period_count, 'percent' => floor($this_period_count / $this->total_posts * 100)));
if ($showchart) {
$insight->text .= " Some things are just one-exclamation-point exciting! " . "Others are really exciting!!!! Here's " . $this->username . "'s breakdown.";
asort($this->point_chart);
$rows = array();
foreach ($this->point_chart as $label => $number) {
$rows[] = array('c' => array(array('v' => str_repeat('!', $label)), array('v' => $number)));
}
$insight->setBarChart(array('cols' => array(array('label' => 'Exclamation Points', 'type' => 'string'), array('label' => 'Occurences', 'type' => 'number')), 'rows' => $rows));
}
}
return $insight;
}
示例13: generateInsight
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__);
}
示例14: generateInsight
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__);
}
示例15: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
if (Utils::isTest() || date("Y-m-d") == $this->run_date) {
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-02/llama.jpg', 'alt_text' => 'Llama', 'credit' => 'Photo: Eric Kilby', 'img_link' => 'https://www.flickr.com/photos/ekilby/8564867495/');
$should_generate_insight = self::shouldGenerateWeeklyInsight($this->slug, $instance, $insight_date = $this->run_date, $regenerate_existing_insight = false, $day_of_week = 5, count($last_week_of_posts));
if ($should_generate_insight) {
$this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
$post_dao = DAOFactory::getDAO('PostDAO');
$topics = array('llama' => array("llama", "llamas"));
$matches = array();
foreach ($last_week_of_posts as $post) {
foreach ($topics as $key => $strings) {
foreach ($strings as $string) {
if (preg_match_all('/\\b' . $string . '\\b/i', $post->post_text) > 0) {
$matches[$key] = array('term' => $string, 'post' => $post);
unset($topics[$key]);
break;
}
}
}
}
if (count($matches) == 0) {
$headline = $this->username . ' managed to avoid llamageddon!';
$insight_text = "It seems like half the internet was " . "<a href='http://www.theverge.com/2015/2/26/8116693/live-the-internet-is-going-bananas-" . "for-this-llama-chase'>talking about runaway llamas</a> " . 'yesterday. Kudos to ' . $this->username . ' for showing a llama restraint.';
} else {
$headline = $this->username . " showed a whole llama love";
$insight_text = "Two runaway llamas <a href='http://www.theverge.com/2015/2/26/8116693/live-" . "the-internet-is-going-bananas-for-this-llama-chase'>took over Twitter yesterday</a>" . ", and like a llama people, " . $this->username . " couldn't resist.";
}
$insight = new Insight();
$insight->instance_id = $instance->id;
$insight->slug = $this->slug;
$insight->date = $this->run_date;
$insight->headline = $headline;
$insight->text = $insight_text;
$insight->filename = basename(__FILE__, ".php");
$insight->emphasis = Insight::EMPHASIS_HIGH;
$insight->setHeroImage($hero_image);
$this->insight_dao->insertInsight($insight);
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
}