Permalink
Browse files

Delete deprecated post-specific insights [ci skip]

  • Loading branch information...
1 parent 47940a0 commit 00e1ab2ba84d7cf3a30a0aa4c0600911f176de37 @ginatrapani ginatrapani committed May 19, 2012
@@ -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);
+ }
}
@@ -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 ";
@@ -48,6 +48,14 @@ public function insertInsight($slug, $instance_id, $date, $text, $emphasis=Insig
*/
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
* @param int $page_count Number of insight baselines to return
@@ -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);
}
}

0 comments on commit 00e1ab2

Please sign in to comment.