Skip to content

Commit

Permalink
InsightsGenerator query optimization and clearer comments [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed Jul 8, 2012
1 parent 27bd787 commit af9bd4e
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions webapp/_lib/model/class.InsightsGenerator.php
Expand Up @@ -66,19 +66,19 @@ private function generateInsightFeedItems($number_days=3) {
$insight_baseline_dao = DAOFactory::getDAO('InsightBaselineDAO');
$insight_dao = DAOFactory::getDAO('InsightDAO');

// Get retweeted posts for last 7 days
$posts = $post_dao->getMostRetweetedPostsInLastWeek($this->instance->network_username,
$this->instance->network, 40, $is_public = false);
// Get posts for last 7 days
$posts = $post_dao->getAllPostsByUsernameOrderedBy($this->instance->network_username,
$network=$this->instance->network, $count=0, $order_by="pub_date", $in_last_x_days = $number_days,
$iterator = false, $is_public = false);

$baseline_date = null;
$simplified_post_date = "";
// foreach post
foreach ($posts as $post) {
$simplified_post_date = date('Y-m-d', strtotime($post->pub_date));
// Retweet spikes and high insights for 7/30/365 days
// First get spike/high 7/30/365 day baselines
if ($simplified_post_date != date('Y-m-d', strtotime($post->pub_date))) {
$simplified_post_date = date('Y-m-d', strtotime($post->pub_date));

if ($simplified_post_date != $baseline_date) { //need to get baselines
$average_retweet_count_7_days =
$insight_baseline_dao->getInsightBaseline('avg_retweet_count_last_7_days', $this->instance->id,
$simplified_post_date);
Expand All @@ -98,9 +98,8 @@ private function generateInsightFeedItems($number_days=3) {
$high_retweet_count_365_days =
$insight_baseline_dao->getInsightBaseline('high_retweet_count_last_365_days', $this->instance->id,
$simplified_post_date);

$baseline_date = $post->pub_date;
}
// Next compare post retweet counts to baselines and store insights where there's a spike or high
if (isset($high_retweet_count_365_days->value)
&& $post->all_retweets >= $high_retweet_count_365_days->value) {
$insight_dao->insertInsight('retweet_high_365_day_'.$post->id, $this->instance->id,
Expand Down Expand Up @@ -168,7 +167,7 @@ private function generateInsightFeedItems($number_days=3) {
$simplified_post_date);
}

//If not a reply or retweet and geoencoded, show the map in the stream
// 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');
Expand All @@ -180,7 +179,7 @@ private function generateInsightFeedItems($number_days=3) {
}
}

//If more than 20 replies, let user know most-frequently mentioned words are available
// Frequent word insight: If > 20 replies, let user know most-frequently mentioned words are available
if ($post->reply_count_cache >= 20) {
if (!isset($config)) {
$config = Config::getInstance();
Expand All @@ -193,7 +192,7 @@ private function generateInsightFeedItems($number_days=3) {
}
}

//Generate least likely followers insights
// Least likely followers insights
$follow_dao = DAOFactory::getDAO('FollowDAO');
$days_ago = 0;
while ($days_ago < $number_days) {
Expand Down Expand Up @@ -228,7 +227,7 @@ private function generateInsightFeedItems($number_days=3) {
$days_ago++;
}

//Generate new list membership insights
// List membership insights
$group_membership_dao = DAOFactory::getDAO('GroupMemberDAO');
$days_ago = 0;
while ($days_ago < $number_days) {
Expand Down Expand Up @@ -274,7 +273,7 @@ private function generateInsightFeedItems($number_days=3) {
$days_ago++;
}

//Follower count history milestone
// Follower count history milestone
$days_ago = $number_days;
while ($days_ago > -1) {
$insight_date = new DateTime();
Expand Down

0 comments on commit af9bd4e

Please sign in to comment.