public function testUpdateInsightBaseline() { $dao = new InsightBaselineMySQLDAO(); //update existing baseline $result = $dao->updateInsightBaseline('avg_replies_per_week', 1, 101, '2012-05-01'); $this->assertTrue($result); //check that value was updated $result = $dao->getInsightBaseline('avg_replies_per_week', 1, '2012-05-01'); $this->assertEqual($result->value, 101); //update nonexistent baseline $result = $dao->updateInsightBaseline('avg_replies_per_week', 1, 101, '2012-05-10'); $this->assertFalse($result); //no date specified $result = $dao->updateInsightBaseline('avg_replies_per_week', 1, 101); $this->assertFalse($result); }
public function testResponseTimeInsightForTwitterNoPriorBaseline() { // Get data ready that insight requires $instance = new Instance(); $instance->id = 10; $instance->network_username = '******'; $instance->network = 'twitter'; $posts = array(); $posts[] = new Post(array('reply_count_cache' => 5, 'retweet_count_cache' => 15, 'favlike_count_cache' => 3)); $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 5, 'favlike_count_cache' => 15)); $posts[] = new Post(array('reply_count_cache' => 2, 'retweet_count_cache' => 5, 'favlike_count_cache' => 1)); // Calculate time for each new retweet $time_per_response = InsightTerms::getSyntacticTimeDifference(floor(60 * 60 * 24 * 7 / 25)); $insight_plugin = new ResponseTimeInsight(); $insight_plugin->generateInsight($instance, null, $posts, 3); // Assert that insight got inserted $insight_dao = new InsightMySQLDAO(); $today = date('Y-m-d'); $result = $insight_dao->getInsight('response_time', 10, $today); $this->debug(Utils::varDumpToString($result)); $this->assertNotNull($result); $this->assertIsA($result, "Insight"); $this->assertPattern('/\\@testeriffic\'s tweets averaged <strong>1 new retweet/', $result->headline); $this->assertPattern('/every <strong>' . $time_per_response . '<\\/strong>./', $result->headline); // Assert that baselines got inserted $insight_baseline_dao = new InsightBaselineMySQLDAO(); $result_1 = $insight_baseline_dao->getInsightBaseline('response_count_reply', 10); $result_2 = $insight_baseline_dao->getInsightBaseline('response_count_retweet', 10); $result_3 = $insight_baseline_dao->getInsightBaseline('response_count_like', 10); $this->assertNotNull($result_1); $this->assertNotNull($result_2); $this->assertNotNull($result_3); $this->assertIsA($result_1, "InsightBaseline"); $this->assertIsA($result_2, "InsightBaseline"); $this->assertIsA($result_3, "InsightBaseline"); $this->assertEqual($result_1->value, 7); $this->assertEqual($result_2->value, 25); $this->assertEqual($result_3->value, 19); $this->debug($this->getRenderedInsightInHTML($result)); $this->debug($this->getRenderedInsightInEmail($result)); }
public function testBaseLines() { $insight_baseline_dao = new InsightBaselineMySQLDAO(); $post1 = FixtureBuilder::build('posts', array('id' => 1, 'post_id' => '1', 'author_username' => 'ev', 'post_text' => 'My Great Video 1', 'pub_date' => '-1d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null)); $video1 = FixtureBuilder::build('videos', array('id' => 1, 'post_key' => '1', 'likes' => 10)); $post2 = FixtureBuilder::build('posts', array('id' => 2, 'post_id' => '2', 'author_username' => 'ev', 'post_text' => 'My Great Video 2', 'pub_date' => '-20d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null)); $video2 = FixtureBuilder::build('videos', array('id' => 2, 'post_key' => '2', 'likes' => 20)); $post3 = FixtureBuilder::build('posts', array('id' => 3, 'post_id' => '3', 'author_username' => 'ev', 'post_text' => 'My Great Video 3', 'pub_date' => '-50d', 'network' => 'youtube', 'in_reply_to_post_id' => null, 'in_reply_to_user_id' => null)); $video3 = FixtureBuilder::build('videos', array('id' => 3, 'post_key' => '3', 'likes' => 30)); $posts[] = new Post($post1->columns); $posts[] = new Post($post2->columns); $posts[] = new Post($post3->columns); $instance = new Instance(); $instance->id = 1; $instance->network_user_id = '1'; $instance->network = 'youtube'; $instance->network_username = '******'; $like_spike_insight = new LikeSpikeInsight(); $like_spike_insight->generateInsight($instance, null, $posts, 7); // Check the average for 30 days is correct $avg_30 = $insight_baseline_dao->getInsightBaseline('avg_like_count_last_30_days', 1); $this->assertEqual($avg_30->value, 15); // Check the high for 30 days is correct $high_30 = $insight_baseline_dao->getInsightBaseline('high_like_count_last_30_days', 1); $this->assertEqual($high_30->value, 20); // Check the average for 90 days is correct $avg_90 = $insight_baseline_dao->getInsightBaseline('avg_like_count_last_90_days', 1); $this->assertEqual($avg_90->value, 20); // Check the high for 90 days is correct $high_90 = $insight_baseline_dao->getInsightBaseline('high_like_count_last_90_days', 1); $this->assertEqual($high_90->value, 30); // Check the high for 365 days is correct $high_365 = $insight_baseline_dao->getInsightBaseline('high_like_count_last_365_days', 1); $this->assertEqual($high_365->value, 30); }
public function testBaseLines() { $insight_baseline_dao = new InsightBaselineMySQLDAO(); $post1_builder = FixtureBuilder::build('posts', array('id' => 28, 'post_id' => '28', 'author_user_id' => '13', 'author_username' => 'ev', 'author_fullname' => 'Ev Williams', 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is post 28', 'source' => 'web', 'pub_date' => '-1d', 'reply_count_cache' => 10, 'is_protected' => 0, 'retweet_count_cache' => 0, 'network' => 'twitter', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'is_geo_encoded' => 0, 'in_reply_to_user_id' => null)); $post2_builder = FixtureBuilder::build('posts', array('id' => 29, 'post_id' => '29', 'author_user_id' => '13', 'author_username' => 'ev', 'author_fullname' => 'Ev Williams', 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is post 29', 'source' => 'web', 'pub_date' => '-20d', 'reply_count_cache' => 20, 'is_protected' => 0, 'retweet_count_cache' => 0, 'network' => 'twitter', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'is_geo_encoded' => 0, 'in_reply_to_user_id' => null)); $post3_builder = FixtureBuilder::build('posts', array('id' => 30, 'post_id' => '30', 'author_user_id' => '13', 'author_username' => 'ev', 'author_fullname' => 'Ev Williams', 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is post 30', 'source' => 'web', 'pub_date' => '-50d', 'reply_count_cache' => 30, 'is_protected' => 0, 'retweet_count_cache' => 0, 'network' => 'twitter', 'old_retweet_count_cache' => 0, 'in_rt_of_user_id' => null, 'in_reply_to_post_id' => null, 'in_retweet_of_post_id' => null, 'is_geo_encoded' => 0, 'in_reply_to_user_id' => null)); $post1 = new Post($post1_builder->columns); $post2 = new Post($post2_builder->columns); $post3 = new Post($post3_builder->columns); $posts[] = $post1; $posts[] = $post2; $posts[] = $post3; $instance = new Instance(); $instance->id = 1; $instance->network_user_id = '13'; $instance->network = 'twitter'; $instance->network_username = '******'; $reply_spike_insight = new ReplySpikeInsight(); $reply_spike_insight->generateInsight($instance, $posts, 7); // Check the average for 7 days is correct $avg_7 = $insight_baseline_dao->getInsightBaseline('avg_reply_count_last_7_days', 1); $this->assertEqual($avg_7->value, 10); // Check the high for 7 days is correct $high_7 = $insight_baseline_dao->getInsightBaseline('high_reply_count_last_7_days', 1); $this->assertEqual($high_7->value, 10); // Check the average for 30 days is correct $avg_30 = $insight_baseline_dao->getInsightBaseline('avg_reply_count_last_30_days', 1); $this->assertEqual($avg_30->value, 15); // Check the high for 30 days is correct $high_30 = $insight_baseline_dao->getInsightBaseline('high_reply_count_last_30_days', 1); $this->assertEqual($high_30->value, 20); // Check the high for 365 days is correct $high_365 = $insight_baseline_dao->getInsightBaseline('high_reply_count_last_365_days', 1); $this->assertEqual($high_365->value, 30); }
public function testBaselineGeneration() { $post_builder = FixtureBuilder::build('posts', array('id' => 1, 'post_id' => '1', 'author_username' => 'ev', 'post_text' => 'My Great Video', 'pub_date' => '-1d', 'network' => 'youtube')); $video_builder = FixtureBuilder::build('videos', array('id' => 1, 'post_key' => '1', 'minutes_watched' => 4, 'average_view_percentage' => 54.6)); $post_builder2 = FixtureBuilder::build('posts', array('id' => 2, 'post_id' => '2', 'author_username' => 'ev', 'post_text' => 'My Great Video 2', 'pub_date' => '-40d', 'network' => 'youtube')); $video_builder2 = FixtureBuilder::build('videos', array('id' => 2, 'post_key' => '2', 'minutes_watched' => 2, 'average_view_percentage' => 54.6)); $posts[] = new Post($post_builder->columns); $posts[] = new Post($post_builder2->columns); $instance = new Instance(); $instance->id = 1; $instance->network_user_id = '1'; $instance->network = 'youtube'; $instance->network_username = '******'; $insight = new MinutesViewedInsight(); $insight->generateInsight($instance, null, $posts, 1); $insight_dao = new InsightBaselineMySQLDAO(); $result = $insight_dao->getInsightBaseline('avg_minutes_viewed_all_time', 1, date('Y-m-d')); $this->assertNotNull($result); $this->assertEqual($result->slug, 'avg_minutes_viewed_all_time'); $this->assertEqual($result->value, 3); $result = $insight_dao->getInsightBaseline('avg_minutes_viewed_month', 1, date('Y-m-d')); $this->assertNotNull($result); $this->assertEqual($result->slug, 'avg_minutes_viewed_month'); $this->assertEqual($result->value, 4); $result = $insight_dao->getInsightBaseline('avg_minutes_viewed_90', 1, date('Y-m-d')); $this->assertNotNull($result); $this->assertEqual($result->slug, 'avg_minutes_viewed_90'); $this->assertEqual($result->value, 3); $result = $insight_dao->getInsightBaseline('all_time_mins_viewed_high', 1, date('Y-m-d')); $this->assertNotNull($result); $this->assertEqual($result->slug, 'all_time_mins_viewed_high'); $this->assertEqual($result->value, 4); $result = $insight_dao->getInsightBaseline('year_mins_viewed_high', 1, date('Y-m-d')); $this->assertNotNull($result); $this->assertEqual($result->slug, 'year_mins_viewed_high'); $this->assertEqual($result->value, 4); $result = $insight_dao->getInsightBaseline('90_mins_viewed_high', 1, date('Y-m-d')); $this->assertNotNull($result); $this->assertEqual($result->slug, '90_mins_viewed_high'); $this->assertEqual($result->value, 4); }