Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Insights code cleanup
* Code style guide: Convert tabs to spaces
* Tweak insight prefixes, and add strong tags inside insight text
* Optimize InsightsGenerator queries, clarify code comments
* Fix list insight spacing
* Fix Flashback post prefix
* Fix failing tests
* Delete bootstrap-timeline.html
  • Loading branch information
ginatrapani committed Jul 18, 2012
1 parent f6b82e1 commit 99cca37
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 696 deletions.
7 changes: 0 additions & 7 deletions tests/TestOfInstaller.php
Expand Up @@ -136,7 +136,6 @@ public function testInstallerShowTables() {
$config->getValue('table_prefix')."group_member_count, ".
$config->getValue('table_prefix')."hashtags," .
$config->getValue('table_prefix')."hashtags_posts, " .
$config->getValue('table_prefix')."insights, ".
$config->getValue('table_prefix')."instances, ".
$config->getValue('table_prefix')."instances_twitter, ".
$config->getValue('table_prefix')."invites," .
Expand Down Expand Up @@ -215,7 +214,6 @@ public function testInstallerCheckTable() {
$config->getValue('table_prefix')."group_member_count, ".
$config->getValue('table_prefix')."hashtags," .
$config->getValue('table_prefix')."hashtags_posts, " .
$config->getValue('table_prefix')."insights, ".
$config->getValue('table_prefix')."instances, ".
$config->getValue('table_prefix')."instances_twitter, ".
$config->getValue('table_prefix')."invites," .
Expand Down Expand Up @@ -285,7 +283,6 @@ public function testDoThinkUpTablesExist() {
$config->getValue('table_prefix')."group_member_count, ".
$config->getValue('table_prefix')."hashtags," .
$config->getValue('table_prefix')."hashtags_posts, " .
$config->getValue('table_prefix')."insights, ".
$config->getValue('table_prefix')."instances, ".
$config->getValue('table_prefix')."instances_twitter, ".
$config->getValue('table_prefix')."invites," .
Expand Down Expand Up @@ -331,7 +328,6 @@ public function testInstallerIsThinkUpInstalled() {
$config->getValue('table_prefix')."group_member_count, ".
$config->getValue('table_prefix')."hashtags," .
$config->getValue('table_prefix')."hashtags_posts, " .
$config->getValue('table_prefix')."insights, ".
$config->getValue('table_prefix')."instances, ".
$config->getValue('table_prefix')."instances_twitter, ".
$config->getValue('table_prefix')."invites," .
Expand Down Expand Up @@ -414,7 +410,6 @@ public function testInstallerPopulateTables() {
$config->getValue('table_prefix')."group_member_count, ".
$config->getValue('table_prefix')."hashtags," .
$config->getValue('table_prefix')."hashtags_posts, " .
$config->getValue('table_prefix')."insights, ".
$config->getValue('table_prefix')."instances, ".
$config->getValue('table_prefix')."instances_twitter, ".
$config->getValue('table_prefix')."invites," .
Expand Down Expand Up @@ -459,7 +454,6 @@ public function testInstallerPopulateTables() {
$config->getValue('table_prefix')."group_member_count, ".
$config->getValue('table_prefix')."hashtags," .
$config->getValue('table_prefix')."hashtags_posts, " .
$config->getValue('table_prefix')."insights, ".
$config->getValue('table_prefix')."instances, ".
$config->getValue('table_prefix')."instances_twitter, ".
$config->getValue('table_prefix')."invites," .
Expand Down Expand Up @@ -503,7 +497,6 @@ public function testInstallerPopulateTables() {
$config->getValue('table_prefix')."group_member_count, ".
$config->getValue('table_prefix')."hashtags," .
$config->getValue('table_prefix')."hashtags_posts, " .
$config->getValue('table_prefix')."insights, ".
$config->getValue('table_prefix')."instances, ".
$config->getValue('table_prefix')."instances_twitter, ".
$config->getValue('table_prefix')."invites," .
Expand Down
45 changes: 22 additions & 23 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 @@ -266,15 +265,15 @@ private function generateInsightFeedItems($number_days=3) {
$new_groups[0]->setMetadata();
$insight_dao->insertInsight('new_group_memberships', $this->instance->id, $insight_date, "Filed:",
"You got added to a new list, ".'<a href="'.$new_groups[0]->url.'">'.$new_groups[0]->keyword.
"</a>, bringing your total to ".
"</a>, bringing your total to <strong>".
number_format(end($list_membership_count_history_by_day['history'])).
".", Insight::EMPHASIS_LOW, serialize($list_membership_count_history_by_day));
" lists</strong>.", Insight::EMPHASIS_LOW, serialize($list_membership_count_history_by_day));
}
}
$days_ago++;
}

//Follower count history milestone
// Follower count history milestone
$days_ago = $number_days;
while ($days_ago > -1) {
$insight_date = new DateTime();
Expand All @@ -290,20 +289,20 @@ private function generateInsightFeedItems($number_days=3) {
//by month
$follower_count_history_by_month = $follower_count_dao->getHistory($this->instance->network_user_id,
$this->instance->network, 'MONTH', 15, $insight_date_formatted);
$insight_text = "<strong>";
if ( isset($follower_count_history_by_month['milestone'])
&& $follower_count_history_by_month["milestone"]["will_take"] > 0
&& $follower_count_history_by_month["milestone"]["next_milestone"] > 0) {
$insight_text = "Upcoming milestone: ";
$insight_text .= $follower_count_history_by_month['milestone']['will_take'].' month';
if ($follower_count_history_by_month['milestone']['will_take'] > 1) {
$insight_text .= 's';
}
$insight_text .= ' till you reach '.
$insight_text .= '</strong> till you reach <strong>'.
number_format($follower_count_history_by_month['milestone']['next_milestone']);
$insight_text .= ' followers at your current growth rate.';
$insight_text .= '</strong> followers at your current growth rate.';

$insight_dao->insertInsight('follower_count_history_by_month_milestone', $this->instance->id,
$insight_date_formatted, "Milestone:", $insight_text, Insight::EMPHASIS_HIGH,
$insight_date_formatted, "Upcoming milestone:", $insight_text, Insight::EMPHASIS_HIGH,
serialize($follower_count_history_by_month));
}
} else if ($insight_day_of_week == 0) { //it's Sunday
Expand All @@ -314,22 +313,22 @@ private function generateInsightFeedItems($number_days=3) {
$this->logger->logInfo($insight_date_formatted." is Sunday; Count by week stats are ".
Utils::varDumpToString($follower_count_history_by_week) , __METHOD__.','
.__LINE__);
$insight_text = "<strong>";
if ( isset($follower_count_history_by_week['milestone'])
&& $follower_count_history_by_week["milestone"]["will_take"] > 0
&& $follower_count_history_by_week["milestone"]["next_milestone"] > 0 ) {
$insight_text = "Upcoming milestone: ";
$insight_text .= $follower_count_history_by_week['milestone']['will_take'].' week';
if ($follower_count_history_by_week['milestone']['will_take'] > 1) {
$insight_text .= 's';
}
$insight_text .= ' till you reach '.
$insight_text .= '</strong> till you reach <strong>'.
number_format($follower_count_history_by_week['milestone']['next_milestone']);
$insight_text .= ' followers at your current growth rate.';
$insight_text .= '</strong> followers at your current growth rate.';
$this->logger->logInfo("Storing insight ".$insight_text, __METHOD__.','
.__LINE__);

$insight_dao->insertInsight('follower_count_history_by_week_milestone', $this->instance->id,
$insight_date_formatted, "Milestone:", $insight_text, Insight::EMPHASIS_HIGH,
$insight_date_formatted, "Upcoming milestone:", $insight_text, Insight::EMPHASIS_HIGH,
serialize($follower_count_history_by_week));
}
}
Expand Down
42 changes: 21 additions & 21 deletions webapp/_lib/view/_insights.post.tpl
@@ -1,9 +1,9 @@
{if $hide_insight_header}

{else}
<span class="label label-{if $i->emphasis eq '1'}info{elseif $i->emphasis eq '2'}success{elseif $i->emphasis eq '3'}error{else}inverse{/if}">{$i->prefix}</span>
<i class="icon-{if $i->emphasis eq '1'}time{elseif $i->emphasis eq '2'}thumbs-up{elseif $i->emphasis eq '3'}warning-sign{else}retweet{/if}"></i>
{$i->text}
<i class="icon-{if $i->emphasis eq '1'}time{elseif $i->emphasis eq '2'}thumbs-up{elseif $i->emphasis eq '3'}warning-sign{else}retweet{/if}"></i>
{$i->text}
{/if}

<div class="post lead">
Expand Down Expand Up @@ -35,24 +35,24 @@
<a href="{$site_root_path}post/?t={$post->in_reply_to_post_id}&n={$post->network|urlencode}"><span class="ui-icon ui-icon-arrowthick-1-w" title="reply to..."></span></a>
{/if}

<div class="metaroll">
<a href="{$site_root_path}post/?t={$post->post_id}&n={$post->network|urlencode}">{$post->adj_pub_date|relative_datetime} ago</a>
{if $post->is_geo_encoded < 2}
{if $show_distance}
{if $unit eq 'km'}
{$post->reply_retweet_distance|number_format} kms away
{else}
{$post->reply_retweet_distance|number_format} miles away in
{/if}
{/if}
from {$post->location|truncate:60:' ...'}
{/if}
{if $post->network == 'twitter'}
<a href="http://twitter.com/intent/tweet?in_reply_to={$post->post_id}"><span class="ui-icon ui-icon-arrowreturnthick-1-w" title="reply"></span></a>
<a href="http://twitter.com/intent/retweet?tweet_id={$post->post_id}"><span class="ui-icon ui-icon-arrowreturnthick-1-e" title="retweet"></span></a>
<a href="http://twitter.com/intent/favorite?tweet_id={$post->post_id}"><span class="ui-icon ui-icon-star" title="favorite"></span></a>
{/if}
</div>
<div class="metaroll">
<a href="{$site_root_path}post/?t={$post->post_id}&n={$post->network|urlencode}">{$post->adj_pub_date|relative_datetime} ago</a>
{if $post->is_geo_encoded < 2}
{if $show_distance}
{if $unit eq 'km'}
{$post->reply_retweet_distance|number_format} kms away
{else}
{$post->reply_retweet_distance|number_format} miles away in
{/if}
{/if}
from {$post->location|truncate:60:' ...'}
{/if}
{if $post->network == 'twitter'}
<a href="http://twitter.com/intent/tweet?in_reply_to={$post->post_id}"><span class="ui-icon ui-icon-arrowreturnthick-1-w" title="reply"></span></a>
<a href="http://twitter.com/intent/retweet?tweet_id={$post->post_id}"><span class="ui-icon ui-icon-arrowreturnthick-1-e" title="retweet"></span></a>
<a href="http://twitter.com/intent/favorite?tweet_id={$post->post_id}"><span class="ui-icon ui-icon-star" title="favorite"></span></a>
{/if}
</div>
</div>

{if $i->slug eq 'geoencoded_replies'}
Expand Down
3 changes: 1 addition & 2 deletions webapp/_lib/view/_insights.posts.tpl
Expand Up @@ -11,8 +11,7 @@

{* Show "X years ago you posted" text if post is from a different year than the last one *}
{if !$smarty.foreach.bar.first and $prev_post_year neq $p->adj_pub_date|date_format:"%Y"}

<p><span class="label label-info">{$i->prefix}</span> <i class="icon-time"></i> {$p->adj_pub_date|relative_datetime} ago in {$p->adj_pub_date|date_format:"%Y"}, you posted:</p>
<p>{$p->adj_pub_date|relative_datetime} ago in {$p->adj_pub_date|date_format:"%Y"}, you posted:</p>
{/if}

{include file="_insights.post.tpl" post=$p hide_insight_header='1'}
Expand Down
2 changes: 1 addition & 1 deletion webapp/_lib/view/dashboard.tpl
@@ -1,6 +1,6 @@
{include file="_header.tpl"}
{if $smarty.get.v eq "insights"}
{include file="insights.tpl"}
{include file="insights.tpl"}
{else}

{include file="_statusbar.tpl"}
Expand Down

0 comments on commit 99cca37

Please sign in to comment.