Skip to content

Commit

Permalink
[DB MIGRATION REQ'D] Insights feed
Browse files Browse the repository at this point in the history
* Create insight baseline model and DAOs

Add new pluggable Insights Generator plugin
* Abstract all the insights logic into individual "plugin" PHP files
* Set up hooks for the Insight Generator plugin to dynamically call the individual insight plugin files

Bootstrapify insights feed, login/register, web crawl
  • Loading branch information
ginatrapani committed Aug 14, 2012
1 parent dcd783f commit 894b999
Show file tree
Hide file tree
Showing 106 changed files with 10,660 additions and 432 deletions.
4 changes: 2 additions & 2 deletions extras/dev/makemodel/classes/class.ModelMaker.php
Expand Up @@ -3,7 +3,7 @@
*
* ThinkUp/extras/dev/makemodel/classes/class.ModelMaker.php
*
* Copyright (c) 2009-2010 Gina Trapani
* Copyright (c) 2011-2012 Gina Trapani
*
* LICENSE:
*
Expand All @@ -22,7 +22,7 @@
*
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2010 Gina Trapani
* @copyright 2011-2012 Gina Trapani
*
* ModelMaker
*
Expand Down
4 changes: 2 additions & 2 deletions extras/dev/makemodel/makemodel.php
Expand Up @@ -3,7 +3,7 @@
*
* ThinkUp/extras/dev/makemodel/makemodel.php
*
* Copyright (c) 2009-2010 Gina Trapani
* Copyright (c) 2011-2012 Gina Trapani
*
* LICENSE:
*
Expand All @@ -22,7 +22,7 @@
*
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2010 Gina Trapani
* @copyright 2011-2012 Gina Trapani
*
* Usage:
* makemode.php <table_name> <object_name> [<parent_object_name>]
Expand Down
25 changes: 25 additions & 0 deletions extras/dev/ramdisk/parse_config.php
@@ -1,4 +1,29 @@
<?php
/**
*
* ThinkUp/extras/dev/ramdisk/parse_config.php
*
* Copyright (c) 2009-2012 mwilkie
*
* LICENSE:
*
* This file is part of ThinkUp (http://thinkupapp.com).
*
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
* later version.
*
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*
* @author mwilkie <mark[at]bitterpill[dot]org>
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2012 mwilkie
*/
require_once 'webapp/config.inc.php';

array_shift($argv);
Expand Down
25 changes: 25 additions & 0 deletions extras/scripts/getversion.php
@@ -1,4 +1,29 @@
<?php
/**
*
* ThinkUp/extras/scripts/getversion.php
*
* Copyright (c) 2009-2012 Gina Trapani
*
* LICENSE:
*
* This file is part of ThinkUp (http://thinkupapp.com).
*
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
* later version.
*
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2012 Gina Trapani
*/
chdir(dirname(dirname(dirname(__FILE__))));
require_once 'webapp/install/version.php';

Expand Down
18 changes: 9 additions & 9 deletions tests/TestOfAccountConfigurationController.php
Expand Up @@ -349,7 +349,7 @@ public function testAuthControlLoggedInNotAdmin() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand All @@ -372,7 +372,7 @@ public function testAuthControlLoggedInAdmin() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -463,7 +463,7 @@ public function testAuthControlLoggedInChangePasswordSuccess() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -498,7 +498,7 @@ public function testAuthControlLoggedInChangePasswordOldPwdDoesntMatch() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -527,7 +527,7 @@ public function testAuthControlLoggedInChangePasswordOldPwdEmpty() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -556,7 +556,7 @@ public function testAuthControlLoggedInChangePasswordNewPwdsDontMatch() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -586,7 +586,7 @@ public function testAuthControlLoggedInChangePasswordNewPwdTooShort() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -617,7 +617,7 @@ public function testAuthControlLoggedInChangePasswordNewPwdNotAlphanumeric() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -698,7 +698,7 @@ public function testResetAPIKey() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down
8 changes: 7 additions & 1 deletion tests/TestOfDAOFactory.php
Expand Up @@ -376,6 +376,12 @@ public function testGetShortLinkDAO() {
$this->assertIsA($dao, 'ShortLinkMySQLDAO');
}

public function testInsightBaselineDAO() {
$dao = DAOFactory::getDAO('InsightBaselineDAO');
$this->assertNotNull($dao);
$this->assertIsA($dao, 'InsightBaselineMySQLDAO');
}

public function testInsightDAO() {
$dao = DAOFactory::getDAO('InsightDAO');
$this->assertNotNull($dao);
Expand All @@ -393,7 +399,7 @@ public function testGetInstallerDAONoConfigFile(){
$this->assertTrue(isset($dao));
$this->assertIsA($dao, 'InstallerMySQLDAO');
$result = $dao->getTables();
$this->assertEqual(sizeof($result), 30);
$this->assertEqual(sizeof($result), 31);
$this->assertEqual($result[0], $cfg_values["table_prefix"].'encoded_locations');
$this->restoreConfigFile();
}
Expand Down
73 changes: 69 additions & 4 deletions tests/TestOfFollowerCountMySQLDAO.php
Expand Up @@ -117,6 +117,74 @@ public function testGetDayHistoryNoGapsMilestoneNotInSight() {
$this->assertNotNull($result['vis_data']);
}

public function testGetDayHistoryFromSpecificStartDate() {
$builders = array();
$format = 'n/j';
$date = date ( $format );

$todays_day_of_the_week = date('w');
$this->debug("It's currently the ".$todays_day_of_the_week." day of the week");
$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-40d', 'count'=>90);
$builders[] = FixtureBuilder::build('follower_count', $follower_count);

$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-41d', 'count'=>70);
$builders[] = FixtureBuilder::build('follower_count', $follower_count);

$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-42d', 'count'=>50);
$builders[] = FixtureBuilder::build('follower_count', $follower_count);

$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-43d', 'count'=>30);
$builders[] = FixtureBuilder::build('follower_count', $follower_count);

$follower_count = array('network_user_id'=>'930061', 'network'=>'twitter', 'date'=>'-44d', 'count'=>10);
$builders[] = FixtureBuilder::build('follower_count', $follower_count);

$dao = new FollowerCountMySQLDAO();
$date_ago = date ($format, strtotime('-40 day'.$date));
$result = $dao->getHistory('930061', 'twitter', 'DAY', 5, $date_ago);
$this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');

$this->debug(Utils::varDumpToString($result));
//check history
$this->assertEqual(sizeof($result['history']), 5);

$format = 'm/d/Y';
if ($todays_day_of_the_week == 0 ) {
$date_ago = date ($format, strtotime('-40 day'.$date));
$this->assertEqual($result['history'][$date_ago], 90);

$date_ago = date ($format, strtotime('-41 day'.$date));
$this->assertEqual($result['history'][$date_ago], 70);

$date_ago = date ($format, strtotime('-42 day'.$date));
$this->assertEqual($result['history'][$date_ago], 50);

$date_ago = date ($format, strtotime('-43 day'.$date));
$this->assertEqual($result['history'][$date_ago], 30);
} else {
$date_ago = date ($format, strtotime('-41 day'.$date));
$this->assertEqual($result['history'][$date_ago], 70);

$date_ago = date ($format, strtotime('-42 day'.$date));
$this->assertEqual($result['history'][$date_ago], 50);

$date_ago = date ($format, strtotime('-43 day'.$date));
$this->assertEqual($result['history'][$date_ago], 30);
}

//check trend
$this->assertEqual($result['trend'], 16);

//check milestone
//latest follower count is 90, next milestone is 100 followers
//with a 20+/day trend, this should take 1 day
$this->debug(Utils::varDumpToString($result['milestone']));
$this->assertEqual($result['milestone']["next_milestone"], 100);
$this->assertEqual($result['milestone']["will_take"], 1);

$this->assertNotNull($result['vis_data']);
}

public function testGetDayHistoryNoGapsMilestoneInSight() {
$format = 'n/j';
$date = date ( $format );
Expand Down Expand Up @@ -249,11 +317,8 @@ public function testGetDayHistoryWeekNoGaps() {
//$this->assertEqual($result['trend'], 3);

//check milestone
//latest follower count is 140, next milestone is 1,000 followers
//with a 7+/day trend, this should take 123 days
//beyond our "don't feel bad about yourself" threshold of 10, so should be null
if ($todays_day_of_the_week != 0) {
$this->assertNull($result['milestone']);
$this->assertEqual($result['milestone']['will_take'], 20);
}
}

Expand Down
11 changes: 10 additions & 1 deletion tests/TestOfGroupMemberMySQLDAO.php
Expand Up @@ -70,7 +70,7 @@ protected function buildData() {

// Jack's in two groups
$builders[] = FixtureBuilder::build('group_members', array('member_user_id'=>'1234567890',
'group_id'=>'18864710', 'is_active' => 1, 'network'=>'twitter', 'last_seen' => '-1h'));
'group_id'=>'18864710', 'is_active' => 1, 'network'=>'twitter', 'last_seen' => '-1h', 'first_seen' => '-1h'));

// one stale
$builders[] = FixtureBuilder::build('group_members', array('member_user_id'=>'1234567890',
Expand Down Expand Up @@ -147,4 +147,13 @@ public function testFindStalestMemberships() {
$stale_group = $this->DAO->findStalestMemberships($user_id = '1234567890', 'twitter');
$this->assertNull($stale_group);
}

public function testGetNewMembershipsByDate() {
$new_groups = $this->DAO->getNewMembershipsByDate('twitter', '1234567890');
$this->assertEqual(count($new_groups), 1);
$this->assertEqual($new_groups[0]->id, 1);
$this->assertEqual($new_groups[0]->group_id, '18864710');
$this->assertEqual($new_groups[0]->group_name, '@someguy/a-list');
$this->assertEqual($new_groups[0]->is_active, 1);
}
}
15 changes: 15 additions & 0 deletions tests/TestOfGroupMySQLDAO.php
Expand Up @@ -113,4 +113,19 @@ public function testInsert() {
$this->assertTrue($this->DAO->updateOrInsertGroup($group));
$this->assertTrue($this->DAO->isGroupInStorage($group = '133333333', 'twitter'));
}

public function testSetMetadata() {
$val['id'] = 101;
$val['group_id'] = 1001;
$val['network'] = 'twitter';
$val['group_name'] = '@mirqamar/fivebyfive';
$val['is_active'] = 1;
$val['first_seen'] = '2012-06-13';
$val['last_seen'] = '2012-06-13';

$group = new Group($val);
$group->setMetadata();
$this->assertEqual($group->url, 'http://twitter.com/mirqamar/fivebyfive');
$this->assertEqual($group->keyword, 'fivebyfive');
}
}

0 comments on commit 894b999

Please sign in to comment.