本文整理汇总了PHP中InsightPluginParent::generateInsight方法的典型用法代码示例。如果您正苦于以下问题:PHP InsightPluginParent::generateInsight方法的具体用法?PHP InsightPluginParent::generateInsight怎么用?PHP InsightPluginParent::generateInsight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InsightPluginParent
的用法示例。
在下文中一共展示了InsightPluginParent::generateInsight方法的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__);
$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__);
}
}
示例2: 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__);
$video_dao = DAOFactory::getDAO('VideoDAO');
$filename = basename(__FILE__, ".php");
foreach ($last_week_of_posts as $post) {
if ($post->network == 'youtube') {
$video = $video_dao->getVideoByID($post->post_id, 'youtube');
$simplified_post_date = date('Y-m-d', strtotime($video->pub_date));
} else {
break;
}
// Get the average baselines
$total_likes_and_dislikes = $video->likes + $video->dislikes;
$percent_likes = round($video->likes / $total_likes_and_dislikes * 100, 2);
$percent_dislikes = round($video->dislikes / $total_likes_and_dislikes * 100, 2);
// If the video splits opinion in the range of 60/40 likes / dislikes or 40/60 likes / dislikes
if ($percent_likes >= 40 && $percent_likes <= 60) {
$headline = $video->post_text . " really touched a nerve!";
$insight_text = "{$percent_likes}" . "% of people liked ";
$insight_text .= "<a href=\"http://plus.google.com/{$instance->network_user_id}/about\">" . $instance->network_username;
$insight_text .= '</a>\'s video ';
$insight_text .= "<a href=\"http://www.youtube.com/watch?v={$post->post_id}\">" . $video->post_text . "</a> ";
$insight_text .= "and " . $percent_dislikes . "% disliked it.";
$this->insight_dao->insertInsightDeprecated("split_opinions" . $video->id, $instance->id, $simplified_post_date, $headline, $insight_text, $filename, 1, serialize($video));
}
}
}
示例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__);
$baseline_dao = DAOFactory::getDAO('InsightBaselineDAO');
foreach ($this->getSchedule() as $baseline_slug => $data) {
$now = TimeHelper::getTime();
if ($now >= strtotime($data['start']) && $now <= strtotime($data['end'])) {
$this->logger->logInfo("{$now} is in-schedule", __METHOD__ . ',' . __LINE__);
$baseline = $baseline_dao->getMostRecentInsightBaseline($baseline_slug, $instance->id);
if (!$baseline) {
if ($instance->network == 'facebook' && date('w') == 4 || $instance->network == 'twitter' && date('w') == 1 || Utils::isTest()) {
$found = $this->runInsightForConfig($data, $instance);
$baseline_dao->insertInsightBaseline($baseline_slug, $instance->id, $found);
} else {
$this->logger->logInfo("Not today", __METHOD__ . ',' . __LINE__);
}
} else {
$this->logger->logInfo("Already exists", __METHOD__ . ',' . __LINE__);
}
} else {
$this->logger->logInfo("Not in-schedule", __METHOD__ . ',' . __LINE__);
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例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__);
$network = $instance->network;
$user_id = $instance->network_user_id;
if ($network == 'twitter' && $this->shouldGenerateMonthlyInsight($this->slug, $instance, 'today', false, 8)) {
$my_count = $user->follower_count;
$follow_dao = DAOFactory::getDAO('FollowDAO');
$follow_count = $follow_dao->countTotalFriends($user_id, $network);
$median = $follow_dao->getMedianFollowerCountOfFriends($user_id, $network);
$number_under = $follow_dao->getCountOfFriendsWithFewerFollowers($user_id, $network, $my_count);
$rank = $follow_count - $number_under + 1;
$percentile = (int) sprintf('%d', 100 * ($number_under / $follow_count));
if ($percentile >= 50 && $my_count > $median) {
$insight = new Insight();
$insight->slug = $this->slug;
$insight->date = $this->insight_date;
$insight->instance_id = $instance->id;
$insight->filename = basename(__FILE__, ".php");
$insight->emphasis = Insight::EMPHASIS_MED;
$insight->headline = $this->getVariableCopy(array('%username has it good', 'A closer look at %username\'s follower count', '%username could lend a hand'));
$insight->text = $this->getVariableCopy(array("%username has more followers than %percentile% of the %total people %username follows. That means " . "<strong>%percentoftotal</strong> of %username's friends would reach a bigger audience " . "if %username retweeted them.", "%username has more followers than %percentile% of the people %username follows. That means " . "<strong>%percentoftotal</strong> of %username's friends would reach a bigger audience " . "if %username retweeted them."), array('total' => number_format($follow_count), 'percentoftotal' => number_format($number_under), 'percentile' => $percentile));
$this->insight_dao->insertInsight($insight);
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例5: generateInsight
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$since_date = date("Y-m-d");
$insight_date = new DateTime();
$insight_day_of_week = (int) $insight_date->format('w');
$insight_day_of_month = (int) $insight_date->format('j');
$filename = basename(__FILE__, ".php");
if ($insight_day_of_month == 1) {
//it's the first day of the month
// Past 30 days
if (self::shouldGenerateInsight('biggest_fans_last_30_days', $instance, $insight_date = $since_date)) {
$fav_dao = DAOFactory::getDAO('FavoritePostDAO');
$fans = $fav_dao->getUsersWhoFavoritedMostOfYourPosts($instance->network_user_id, $instance->network, 30);
if (isset($fans) && sizeof($fans) > 0) {
$this->insight_dao->insertInsightDeprecated("biggest_fans_last_30_days", $instance->id, $since_date, "Biggest fans:", "People who " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " the most over the last 30 days: ", $filename, Insight::EMPHASIS_LOW, serialize($fans));
}
}
} else {
if ($insight_day_of_week == 0) {
//it's Sunday
// Past 7 days
if (self::shouldGenerateInsight('biggest_fans_last_7_days', $instance, $insight_date = $since_date)) {
$fav_dao = DAOFactory::getDAO('FavoritePostDAO');
$fans = $fav_dao->getUsersWhoFavoritedMostOfYourPosts($instance->network_user_id, $instance->network, 7);
if (isset($fans) && sizeof($fans) > 0) {
$this->insight_dao->insertInsightDeprecated("biggest_fans_last_7_days", $instance->id, $since_date, "Biggest fans:", "People who " . $this->terms->getVerb('liked') . " {$this->username}'s " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " the most over the last 7 days: ", $filename, Insight::EMPHASIS_LOW, serialize($fans));
}
}
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例6: generateInsight
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
if (self::shouldGenerateInsight('link_prompt', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = null, $count_last_week_of_posts = null, $excluded_networks = array('foursquare', 'youtube'), $alternate_day = (int) date('j') % 2)) {
$post_dao = DAOFactory::getDAO('PostDAO');
$link_dao = DAOFactory::getDAO('LinkDAO');
// Check from midnight two days ago until an hour from now
// (to avoid clock-sync issues)
$recent_posts = $post_dao->getPostsByUserInRange($instance->network_user_id, $instance->network, date('Y-m-d H:i:s', strtotime('-2 days midnight')), date('Y-m-d H:i:s', strtotime('+1 hour')));
$posts_with_links = array();
foreach ($recent_posts as $post) {
$post_text = $post->post_text;
$text_parser = new Twitter_Extractor($post_text);
$elements = $text_parser->extract();
if (count($elements['urls'])) {
$posts_with_links[] = $post;
}
}
$num_posts = $post_dao->countAllPostsByUserSinceDaysAgo($instance->network_user_id, $instance->network, 30);
$num_links = $link_dao->countLinksPostedByUserSinceDaysAgo($instance->network_user_id, $instance->network, 30);
if ($num_posts && $num_links / $num_posts > 0.2 && count($recent_posts) && !count($posts_with_links)) {
$insight_text = $this->username . " hasn't " . $this->terms->getVerb('posted') . " a link in the last 2 days. It may be time to share an interesting link with " . $this->terms->getNoun('friend', InsightTerms::PLURAL) . ".";
$this->insight_dao->insertInsightDeprecated('link_prompt', $instance->id, $this->insight_date, "Nudge:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW);
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例7: generateInsight
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$filename = basename(__FILE__, ".php");
$follow_dao = DAOFactory::getDAO('FollowDAO');
// Least likely followers based on follower-to-followee ratio
$least_likely_followers = $follow_dao->getLeastLikelyFollowersByDay($instance->network_user_id, $instance->network, 0, 3);
if (sizeof($least_likely_followers) > 0) {
//if not null, store insight
if (sizeof($least_likely_followers) > 1) {
$this->insight_dao->insertInsightDeprecated('least_likely_followers', $instance->id, $this->insight_date, "Standouts:", '<strong>' . sizeof($least_likely_followers) . " interesting users</strong> " . "followed {$this->username}.", $filename, Insight::EMPHASIS_LOW, serialize($least_likely_followers));
} else {
$this->insight_dao->insertInsightDeprecated('least_likely_followers', $instance->id, $this->insight_date, "Standout:", "An interesting user followed {$this->username}.", $filename, Insight::EMPHASIS_LOW, serialize($least_likely_followers));
}
}
// Verified followers
$verified_followers = $follow_dao->getVerifiedFollowersByDay($instance->network_user_id, $instance->network, 0, 3);
if (sizeof($verified_followers) > 0) {
//if not null, store insight
if (sizeof($verified_followers) > 1) {
$this->insight_dao->insertInsightDeprecated('verified_followers', $instance->id, $this->insight_date, "Verified followers!", '<strong>' . sizeof($verified_followers) . " verified users</strong> " . "followed {$this->username}.", $filename, Insight::EMPHASIS_LOW, serialize($verified_followers));
} else {
$this->insight_dao->insertInsightDeprecated('verified_followers', $instance->id, $this->insight_date, "Verified follower!", "A verified user followed {$this->username}.", $filename, Insight::EMPHASIS_LOW, serialize($verified_followers));
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例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__);
$possible_messaging = array(array('headline' => 'Ohai', 'text' => 'Greetings, humans', 'header_image' => 'http://farm3.staticflickr.com/2713/4098259769_725b5fb65b_o.jpg'), array('headline' => 'Hello', 'text' => 'Greetings, earthlings', 'header_image' => 'http://farm9.staticflickr.com/8078/8276342554_5a51725f5f_n.jpg'), array('headline' => 'Yo', 'text' => 'Greetings, peeps', 'header_image' => 'http://farm6.staticflickr.com/5006/5367216303_83c5f2dc39_n.jpg'));
//Instantiate the Insight object
$my_insight = new Insight();
//REQUIRED: Set the insight's required attributes
//We pull some from the options above. But the could just be strings like 'Ohai'
$which_messaging = TimeHelper::getTime() % count($possible_messaging);
foreach ($possible_messaging[$which_messaging] as $field => $value) {
$my_insight->{$field} = $value;
}
$my_insight->slug = 'my_test_insight_hello_thinkup';
//slug to label this insight's content
$my_insight->instance_id = $instance->id;
$my_insight->date = $this->insight_date;
//date is often this or $simplified_post_date
$my_insight->filename = basename(__FILE__, ".php");
//Same for every insight, must be set exactly this way
$my_insight->emphasis = Insight::EMPHASIS_MED;
//Set emphasis optionally, default is Insight::EMPHASIS_LOW
//OPTIONAL: Attach related data of various types using Insight setter functions
//$my_insight->setPosts($my_insight_posts);
//$my_insight->setLinks($my_insight_links);
//$my_insight->setPeople($my_insight_people);
//$my_insight->setMilestones($my_insight_milestones);
//etc
$this->insight_dao->insertInsight($my_insight);
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例9: generateInsight
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$post_dao = DAOFactory::getDAO('PostDAO');
$user_dao = DAOFactory::getDAO('UserDAO');
$service_user = $user_dao->getDetails($instance->network_user_id, $instance->network);
$share_verb = $instance->network == 'twitter' ? 'retweeted' : 'reshared';
foreach ($last_week_of_posts as $post) {
$big_reshares = $post_dao->getRetweetsByAuthorsOverFollowerCount($post->post_id, $instance->network, $service_user->follower_count);
if (isset($big_reshares) && sizeof($big_reshares) > 0) {
if (!isset($config)) {
$config = Config::getInstance();
}
$post_link = '<a href="' . $config->getValue('site_root_path') . 'post/?t=' . $post->post_id . '&n=' . $post->network . '&v=fwds">';
if (sizeof($big_reshares) > 1) {
$notification_text = "People with lots of followers {$share_verb} " . $post_link . "{$this->username}'s post</a>.";
} else {
$follower_count_multiple = intval($big_reshares[0]->follower_count / $service_user->follower_count);
if ($follower_count_multiple > 1) {
$notification_text = "Someone with <strong>" . $follower_count_multiple . "x</strong> more followers than {$this->username} {$share_verb} " . $post_link . "this post</a>.";
} else {
$notification_text = "Someone with lots of followers {$share_verb} " . $post_link . "{$this->username}'s post</a>.";
}
}
//Replace each big resharer's bio line with the text of the post
foreach ($big_reshares as $sharer) {
$sharer->description = '"' . $post->post_text . '"';
}
$simplified_post_date = date('Y-m-d', strtotime($post->pub_date));
$this->insight_dao->insertInsight("big_reshare_" . $post->id, $instance->id, $simplified_post_date, "Big reshare!", $notification_text, basename(__FILE__, ".php"), Insight::EMPHASIS_HIGH, serialize($big_reshares));
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例10: 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__);
}
示例11: generateInsight
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
//Instantiate the Insight object
$my_insight = new Insight();
//REQUIRED: Set the insight's required attributes
$my_insight->instance_id = 1;
$my_insight->slug = 'my_test_insight_hello_thinkup';
//slug to label this insight's content
$my_insight->date = '2013-12-21';
//date of the data this insight applies to
$my_insight->headline = 'Ohai';
$my_insight->text = "Greetings humans";
$my_insight->emphasis = Insight::EMPHASIS_MED;
//Set emphasis optionally, default is Insight::EMPHASIS_LOW
$my_insight->filename = basename(__FILE__, ".php");
//Same for every insight, must be set exactly this way
//OPTIONAL: Attach related data of various types using Insight setter functions
//$my_insight->setPosts($my_insight_posts);
//$my_insight->setLinks($my_insight_links);
//$my_insight->setPeople($my_insight_people);
//etc
$this->insight_dao->insertInsight($my_insight);
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例12: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
if ($instance->network == 'twitter' || $instance->network == 'test_no_monthly') {
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$monthly = 0;
$weekly = 0;
if ($instance->network == 'twitter') {
$weekly = 6;
$monthly = 28;
} else {
if ($instance->network == 'test_no_monthly') {
$monthly = 0;
$weekly = 2;
}
}
$did_monthly = false;
if ($monthly && self::shouldGenerateMonthlyInsight($this->slug, $instance, 'today', false, $monthly)) {
$post_dao = DAOFactory::getDAO('PostDAO');
$posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = date('t'), $iterator = false, $is_public = false);
$this->generateMonthlyInsight($instance, $posts);
$did_monthly = true;
}
$do_weekly = $weekly && !$did_monthly;
if ($do_weekly && self::shouldGenerateWeeklyInsight($this->slug, $instance, 'today', false, $weekly)) {
$this->generateWeeklyInsight($instance, $last_week_of_posts);
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
}
示例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__);
$year = date('Y');
$regenerate = false;
//testing
//$regenerate = true;
$should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date);
if ($should_generate_insight) {
$this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
$insight = new Insight();
$insight->instance_id = $instance->id;
$insight->slug = $this->slug;
$insight->date = "{$year}-{$this->run_date}";
$network = $instance->network;
$count = 0;
$post_dao = DAOFactory::getDAO('PostDAO');
$last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network);
$total_posts = 0;
foreach ($last_year_of_posts as $post) {
$count += AllAboutYouInsight::hasFirstPersonReferences($post->post_text) ? 1 : 0;
$total_posts++;
}
$earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance);
$qualified_year = "";
if (date('Y', strtotime($earliest_pub_date)) == date('Y')) {
if (date('n', strtotime($earliest_pub_date)) > 1) {
//not January
//Earliest post was this year; figure out what month we have data since this year
$since = date('F', strtotime($earliest_pub_date));
$qualified_year = " (at least since " . $since . ")";
}
}
if ($instance->network == 'twitter') {
$headline = $this->getVariableCopy(array("A year's worth of %username"));
} elseif ($instance->network == 'instagram') {
$headline = $this->getVariableCopy(array("A year of %username photos"));
} else {
$headline = $this->getVariableCopy(array("A year about %username"));
}
$percent = round($count / $total_posts * 100);
if ($count > 0) {
if ($instance->network == 'twitter' || $instance->network == 'facebook') {
$insight_text = $this->getVariableCopy(array("In %year, <strong>{$percent}%</strong> of %username's %posts " . "— a grand total of %total — contained " . "the words “I”, “me”, “my”, " . "“mine”, or “myself”%qualified_year. " . ($instance->network == 'facebook' ? "Go ahead: tell your story" : "Sometimes, you've just got to get personal") . "."), array('total' => number_format($count), 'year' => $year, 'qualified_year' => $qualified_year));
} else {
$insight_text = $this->getVariableCopy(array("In %year, <strong>{$percent}%</strong> of %username's Instagram captions " . "— a grand total of %total — contained " . "the words “I”, “me”, “my”, " . "“mine”, or “myself”%qualified_year. " . "What a life in pictures!"), array('total' => number_format($count), 'year' => $year, 'qualified_year' => $qualified_year));
}
} else {
$insight_text = $this->getVariableCopy(array("In %year, none of %username's %posts contained " . "the words “I”, “me”, “my”, " . "“mine”, or “myself”%qualified_year. Sometimes, " . "you've just got to get personal — unless you're " . "%username, apparently!"), array('total' => number_format($count), 'year' => $year, 'qualified_year' => $qualified_year));
}
$insight->headline = $headline;
$insight->text = $insight_text;
$insight->filename = basename(__FILE__, ".php");
$insight->emphasis = Insight::EMPHASIS_HIGH;
$insight->header_image = $user->avatar;
$this->insight_dao->insertInsight($insight);
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例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__);
if ($instance->network == 'twitter' || $instance->network == 'facebook') {
if ($instance->network == 'facebook' && self::shouldGenerateWeeklyInsight($this->slug, $instance, 'today', false, 1)) {
$run = true;
} else {
if ($instance->network == 'twitter' && self::shouldGenerateWeeklyInsight($this->slug, $instance, 'today', false, 5)) {
$run = true;
}
}
if ($run) {
$photo_this_week = $this->findPostWithPhoto($last_week_of_posts);
if (!$photo_this_week) {
$post_dao = DAOFactory::getDAO('PostDAO');
$posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = 14, $iterator = false, $is_public = false);
$photo_at_all = $this->findPostWithPhoto($posts);
if ($photo_at_all) {
$insight = new Insight();
$insight->slug = $this->slug;
$insight->instance_id = $instance->id;
$insight->date = $this->insight_date;
$days = floor((time() - strtotime($photo_at_all->pub_date)) / (60 * 60 * 24));
$insight->headline = $this->getVariableCopy(array("A great time for a pic", "%total days without a pic", "A thousand words unsaid"), array('total' => $days));
$insight->text = $this->username . " hasn't posted a photo in {$days} day" . ($days == 1 ? "" : "s") . ". " . "It might be worth finding something to share.";
$insight->filename = basename(__FILE__, ".php");
$insight->emphasis = Insight::EMPHASIS_LOW;
$this->insight_dao->insertInsight($insight);
}
}
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例15: generateInsight
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$filename = basename(__FILE__, ".php");
foreach ($last_week_of_posts as $post) {
$simplified_post_date = date('Y-m-d', strtotime($post->pub_date));
// Map insight: If not a reply or retweet and geoencoded, show the map in the stream
if (!isset($post->in_reply_to_user_id) && !isset($post->in_reply_to_post_id) && !isset($post->in_retweet_of_post_id) && $post->reply_count_cache > 5) {
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('geoencoder', true);
if (isset($options['gmaps_api_key']->option_value) && $post->is_geo_encoded == 1) {
//Get post's replies and loop through them to make sure at least 5 are indeed geoencoded
$post_dao = DAOFactory::getDAO('PostDAO');
$post_replies = $post_dao->getRepliesToPost($post->post_id, $post->network);
$total_geoencoded_replies = 0;
foreach ($post_replies as $reply) {
if ($reply->is_geo_encoded == 1) {
$total_geoencoded_replies++;
}
}
if ($total_geoencoded_replies > 4) {
$this->insight_dao->insertInsight('geoencoded_replies', $instance->id, $simplified_post_date, "Going global!", "{$this->username}'s post got responses from locations all over the map.", $filename, Insight::EMPHASIS_LOW, serialize($post));
}
}
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}