Skip to content

Commit

Permalink
Add follower count history milestones to Sundays and day 1 of the mon…
Browse files Browse the repository at this point in the history
…th [ci skip]
  • Loading branch information
ginatrapani committed May 19, 2012
1 parent 00e1ab2 commit e95ef19
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 18 deletions.
2 changes: 2 additions & 0 deletions webapp/_lib/model/class.InsightMySQLDAO.php
Expand Up @@ -79,6 +79,8 @@ public function getInsights($instance_id, $page_count=10, $page_number=1) {
} elseif (is_array($insight->related_data)) {
if ($insight->related_data[0] instanceof User) {
$insight->related_data_type = "users";
} elseif (isset($insight->related_data['history'])) {
$insight->related_data_type = "follower_count_history";
}
}
//assume insight came at same time of day as now for relative day notation
Expand Down
51 changes: 51 additions & 0 deletions webapp/_lib/view/dashboard.insights.tpl
Expand Up @@ -29,6 +29,57 @@
<br><br>
{/if}

{if $i->related_data_type eq 'follower_count_history'}
<br><br>
<div id="follower_count_history_by_week_{$i->id}"></div>

<script type="text/javascript">
// Load the Visualization API and the standard charts
google.load('visualization', '1');
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart{$i->id});
{literal}
var formatter = new google.visualization.NumberFormat({fractionDigits: 0});
var formatter_date = new google.visualization.DateFormat({formatType: 'medium'});
function drawChart{/literal}{$i->id}() {literal}{
{/literal}
var follower_count_history_by_week_data = new google.visualization.DataTable(
{$i->related_data.vis_data});
formatter.format(follower_count_history_by_week_data, 1);
formatter_date.format(follower_count_history_by_week_data, 0);
{literal}
var follower_count_history_by_week_chart = new google.visualization.ChartWrapper({
{/literal}
containerId: 'follower_count_history_by_week_{$i->id}',
{literal}
chartType: 'LineChart',
dataTable: follower_count_history_by_week_data,
options: {
width: 325,
height: 250,
legend: "none",
interpolateNulls: true,
pointSize: 2,
hAxis: {
baselineColor: '#eee',
format: 'MMM d',
textStyle: { color: '#999' },
gridlines: { color: '#eee' }
},
vAxis: {
baselineColor: '#eee',
textStyle: { color: '#999' },
gridlines: { color: '#eee' }
},
},
});
follower_count_history_by_week_chart.draw();
}
{/literal}
</script>
<br><br>
{/if}
<!--end attachment data-->
</span>
Expand Down
53 changes: 53 additions & 0 deletions webapp/plugins/twitter/model/class.TwitterCrawler.php
Expand Up @@ -1956,5 +1956,58 @@ public function generateInsights() {
}
$days_ago++;
}

//Follower count history milestones
$days_ago = 31;
while ($days_ago > -1) {
$insight_date = new DateTime();
$insight_date->modify('-'.$days_ago.' day');

$insight_day_of_week = (int) $insight_date->format('w');
//echo $days_ago." days ago, day ".$insight_day_of_week." of the week <br>";
if ($insight_day_of_week == 0) { //it's Sunday
$follower_count_dao = DAOFactory::getDAO('FollowerCountDAO');
//by week
$follower_count_history_by_week = $follower_count_dao->getHistory($this->instance->network_user_id,
$this->instance->network, 'WEEK', 5);
if ( isset($follower_count_history_by_week['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 '.
number_format($follower_count_history_by_week['milestone']['next_milestone']);
$insight_text .= ' followers at this rate.';

$insight_date_formatted = $insight_date->format('Y-m-d');
$insight_dao->insertInsight('follower_count_history_by_week_milestone', $this->instance->id,
$insight_date_formatted, $insight_text, Insight::EMPHASIS_HIGH,
serialize($follower_count_history_by_week));
}
}

$insight_day_of_month = (int) $insight_date->format('j');
if ($insight_day_of_month == 1) { //New month
$follower_count_dao = DAOFactory::getDAO('FollowerCountDAO');
//by week
$follower_count_history_by_month = $follower_count_dao->getHistory($this->instance->network_user_id,
$this->instance->network, 'MONTH', 5);
if ( isset($follower_count_history_by_month['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 '.
number_format($follower_count_history_by_month['milestone']['next_milestone']);
$insight_text .= ' followers at this rate.';

$insight_date_formatted = $insight_date->format('Y-m-d');
$insight_dao->insertInsight('follower_count_history_by_month_milestone', $this->instance->id,
$insight_date_formatted, $insight_text, Insight::EMPHASIS_HIGH,
serialize($follower_count_history_by_month));
}
}
$days_ago--;
}
}
}
36 changes: 18 additions & 18 deletions webapp/plugins/twitter/model/class.TwitterPlugin.php
Expand Up @@ -148,24 +148,24 @@ public function crawl() {
$instance_dao->updateLastRun($instance->id);

// No auth for public Twitter users
$crawler->fetchInstanceUserTweets();

if (!$noauth) {
// Auth req'd, for calling user only
$crawler->fetchInstanceUserMentions();
$crawler->fetchInstanceUserFriends();
$crawler->fetchInstanceFavorites();
$crawler->fetchInstanceUserFollowers();
$crawler->fetchInstanceUserGroups();
$crawler->fetchRetweetsOfInstanceUser();
$crawler->cleanUpMissedFavsUnFavs();
$crawler->updateStaleGroupMemberships();
}

$crawler->fetchStrayRepliedToTweets();
$crawler->fetchUnloadedFollowerDetails();
$crawler->cleanUpFollows();
$crawler->fetchFriendTweetsAndFriends();
// $crawler->fetchInstanceUserTweets();
//
// if (!$noauth) {
// // Auth req'd, for calling user only
// $crawler->fetchInstanceUserMentions();
// $crawler->fetchInstanceUserFriends();
// $crawler->fetchInstanceFavorites();
// $crawler->fetchInstanceUserFollowers();
// $crawler->fetchInstanceUserGroups();
// $crawler->fetchRetweetsOfInstanceUser();
// $crawler->cleanUpMissedFavsUnFavs();
// $crawler->updateStaleGroupMemberships();
// }
//
// $crawler->fetchStrayRepliedToTweets();
// $crawler->fetchUnloadedFollowerDetails();
// $crawler->cleanUpFollows();
// $crawler->fetchFriendTweetsAndFriends();
$crawler->generateInsightBaselines();
$crawler->generateInsights();

Expand Down

0 comments on commit e95ef19

Please sign in to comment.