Skip to content

Commit

Permalink
Delete deprecated post-specific insights [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed May 19, 2012
1 parent 47940a0 commit 00e1ab2
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 13 deletions.
15 changes: 15 additions & 0 deletions tests/TestOfInsightMySQLDAO.php
Expand Up @@ -97,4 +97,19 @@ public function testUpdateInsight() {
$result = $dao->updateInsight('avg_replies_per_week', 1, '2012-05-10', 'ooooh burn');
$this->assertFalse($result);
}

public function testDeleteInsight() {
$dao = new InsightMySQLDAO();

//delete existing baseline
$result = $dao->deleteInsight('avg_replies_per_week', 1, '2012-05-01', 'LOLlerskates', Insight::EMPHASIS_MED);
$this->assertTrue($result);
//check that insight was deleted
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-01');
$this->assertNull($result);

//delete nonexistent baseline
$result = $dao->deleteInsight('avg_replies_per_week', 1, '2012-05-10', 'ooooh burn');
$this->assertFalse($result);
}
}
13 changes: 13 additions & 0 deletions webapp/_lib/model/class.InsightMySQLDAO.php
Expand Up @@ -87,6 +87,19 @@ public function getInsights($instance_id, $page_count=10, $page_number=1) {
return $insights;
}

public function deleteInsight($slug, $instance_id, $date) {
$q = "DELETE FROM #prefix#insights WHERE ";
$q .= "slug=:slug AND date=:date AND instance_id=:instance_id";
$vars = array(
':slug'=>$slug,
':date'=>$date,
':instance_id'=>$instance_id
);
$ps = $this->execute($q, $vars);
$result = $this->getUpdateCount($ps);
return ($result > 0);
}

public function updateInsight($slug, $instance_id, $date, $text, $emphasis=Insight::EMPHASIS_LOW,
$related_data=null) {
$q = "UPDATE #prefix#insights SET text=:text, related_data=:related_data, emphasis=:emphasis ";
Expand Down
8 changes: 8 additions & 0 deletions webapp/_lib/model/interface.InsightDAO.php
Expand Up @@ -47,6 +47,14 @@ public function insertInsight($slug, $instance_id, $date, $text, $emphasis=Insig
* @return Insight
*/
public function getInsight($slug, $instance_id, $date);
/**
* Remove insight from storage.
* @param str $slug
* @param int $instance_id
* @param str $date
* @return bool
*/
public function deleteInsight($slug, $instance_id, $date);
/**
* Get a page of insights for an instance.
* @param int $instance_id
Expand Down
63 changes: 50 additions & 13 deletions webapp/plugins/twitter/model/class.TwitterCrawler.php
Expand Up @@ -1864,32 +1864,69 @@ public function generateInsights() {
}
if (isset($high_retweet_count_365_days->value)
&& $post->all_retweets >= $high_retweet_count_365_days->value) {
$insight_dao->insertInsight('retweet_high_365_day', $this->instance->id, $simplified_post_date,
"New 365-day high! ".$post->all_retweets." people retweeted your tweet.", Insight::EMPHASIS_HIGH,
serialize($post));
$insight_dao->insertInsight('retweet_high_365_day_'.$post->id, $this->instance->id,
$simplified_post_date, "New 365-day high! ".$post->all_retweets." people retweeted your tweet.",
Insight::EMPHASIS_HIGH, serialize($post));

$insight_dao->deleteInsight('retweet_high_30_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_high_7_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_spike_30_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_spike_7_day_'.$post->id, $this->instance->id,
$simplified_post_date);
} elseif (isset($high_retweet_count_30_days->value)
&& $post->all_retweets >= $high_retweet_count_30_days->value) {
$insight_dao->insertInsight('retweet_high_30_day', $this->instance->id, $simplified_post_date,
"New 30-day high! ".$post->all_retweets." people retweeted your tweet.", Insight::EMPHASIS_MED,
serialize($post));
$insight_dao->insertInsight('retweet_high_30_day_'.$post->id, $this->instance->id,
$simplified_post_date, "New 30-day high! ".$post->all_retweets." people retweeted your tweet.",
Insight::EMPHASIS_MED, serialize($post));

$insight_dao->deleteInsight('retweet_high_7_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_spike_30_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_spike_7_day_'.$post->id, $this->instance->id,
$simplified_post_date);
} elseif (isset($high_retweet_count_7_days->value)
&& $post->all_retweets >= $high_retweet_count_7_days->value) {
$insight_dao->insertInsight('retweet_high_7_day', $this->instance->id, $simplified_post_date,
$insight_dao->insertInsight('retweet_high_7_day_'.$post->id, $this->instance->id, $simplified_post_date,
"New 7-day high! ".$post->all_retweets." people retweeted your tweet.",
Insight::EMPHASIS_MED, serialize($post));

$insight_dao->deleteInsight('retweet_high_30_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_spike_30_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_spike_7_day_'.$post->id, $this->instance->id,
$simplified_post_date);
} elseif (isset($average_retweet_count_30_days->value)
&& $post->all_retweets > ($average_retweet_count_30_days->value*2)) {
$multiplier = floor($post->all_retweets/$average_retweet_count_30_days->value);
$insight_dao->insertInsight('retweet_spike_30_day', $this->instance->id, $simplified_post_date,
"Retweet spike! ".$post->all_retweets." people reshared your tweet, more than ".$multiplier.
"x your 30-day average.", Insight::EMPHASIS_LOW,
$insight_dao->insertInsight('retweet_spike_30_day_'.$post->id, $this->instance->id,
$simplified_post_date, "Retweet spike! ".$post->all_retweets.
" people reshared your tweet, more than ".$multiplier. "x your 30-day average.", Insight::EMPHASIS_LOW,
serialize($post));

$insight_dao->deleteInsight('retweet_high_30_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_high_7_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_spike_7_day_'.$post->id, $this->instance->id,
$simplified_post_date);
} elseif (isset($average_retweet_count_7_days->value)
&& $post->all_retweets > ($average_retweet_count_7_days->value*2)) {
$multiplier = floor($post->all_retweets/$average_retweet_count_7_days->value);
$insight_dao->insertInsight('retweet_spike_7_day', $this->instance->id, $simplified_post_date,
"Retweet spike! ".$post->all_retweets." people reshared your tweet, more than ".$multiplier.
"x your 7-day average.", Insight::EMPHASIS_LOW, serialize($post));
$insight_dao->insertInsight('retweet_spike_7_day_'.$post->id, $this->instance->id,
$simplified_post_date, "Retweet spike! ".$post->all_retweets." people reshared your tweet, more than "
.$multiplier. "x your 7-day average.", Insight::EMPHASIS_LOW, serialize($post));

$insight_dao->deleteInsight('retweet_high_30_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_high_7_day_'.$post->id, $this->instance->id,
$simplified_post_date);
$insight_dao->deleteInsight('retweet_spike_30_day_'.$post->id, $this->instance->id,
$simplified_post_date);
}
}

Expand Down

0 comments on commit 00e1ab2

Please sign in to comment.