Skip to content

Commit

Permalink
Fix follower count history charts; don't backfill them [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed May 19, 2012
1 parent 1cdcc0a commit 3c4b737
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 58 deletions.
20 changes: 10 additions & 10 deletions webapp/_lib/view/dashboard.insights.tpl
Expand Up @@ -20,18 +20,18 @@
{/foreach}
<br><br><br>
{/if}

{if $i->related_data_type eq 'post'}
<br><br>
<div style="background-color:white">
{$i->related_data->post_text}
</div>
<br><br>
{/if}

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

<script type="text/javascript">
// Load the Visualization API and the standard charts
Expand All @@ -44,17 +44,17 @@
function drawChart{/literal}{$i->id}() {literal}{
{/literal}
var follower_count_history_by_week_data = new google.visualization.DataTable(
var follower_count_history_data_{$i->id} = 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);
formatter.format(follower_count_history_data_{$i->id}, 1);
formatter_date.format(follower_count_history_data_{$i->id}, 0);
{literal}
var follower_count_history_by_week_chart = new google.visualization.ChartWrapper({
var follower_count_history_chart_{/literal}{$i->id}{literal} = new google.visualization.ChartWrapper({
{/literal}
containerId: 'follower_count_history_by_week_{$i->id}',
containerId: 'follower_count_history_{$i->id}',
{literal}
chartType: 'LineChart',
dataTable: follower_count_history_by_week_data,
dataTable: follower_count_history_data_{/literal}{$i->id}{literal},
options: {
width: 325,
height: 250,
Expand All @@ -74,7 +74,7 @@
},
},
});
follower_count_history_by_week_chart.draw();
follower_count_history_chart_{/literal}{$i->id}{literal}.draw();
}
{/literal}
</script>
Expand Down
90 changes: 42 additions & 48 deletions webapp/plugins/twitter/model/class.TwitterCrawler.php
Expand Up @@ -1957,59 +1957,53 @@ 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 = "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 '.
number_format($follower_count_history_by_week['milestone']['next_milestone']);
$insight_text .= ' followers at your current growth 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));
//Follower count history milestone
$insight_date = new DateTime();
$insight_day_of_week = (int) $insight_date->format('w');

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 = "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 '.
number_format($follower_count_history_by_week['milestone']['next_milestone']);
$insight_text .= ' followers at your current growth 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 = "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 '.
number_format($follower_count_history_by_month['milestone']['next_milestone']);
$insight_text .= ' followers at your current growth 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));
$insight_day_of_month = (int) $insight_date->format('j');
if ($insight_day_of_month == 1) { //It's the first day of the month
$follower_count_dao = DAOFactory::getDAO('FollowerCountDAO');
//by month
$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 = "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 '.
number_format($follower_count_history_by_month['milestone']['next_milestone']);
$insight_text .= ' followers at your current growth 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--;
}
}
}

0 comments on commit 3c4b737

Please sign in to comment.