Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
List membership insights [ci skip]
  • Loading branch information
ginatrapani committed Jun 16, 2012
1 parent 81113a7 commit 20296b1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
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);
}
}
24 changes: 24 additions & 0 deletions webapp/_lib/model/class.GroupMemberMySQLDAO.php
Expand Up @@ -146,4 +146,28 @@ public function findStalestMemberships($user_id, $network) {

return $this->getDataRowAsObject($ps, "Group");
}

public function getNewMembershipsByDate($network, $member_user_id, $from_date=null) {
$vars = array(
':member_user_id'=> $member_user_id,
':network'=>$network
);
if (!isset($from_date)) {
$from_date = 'CURRENT_DATE()';
} else {
$vars[':from_date'] = $from_date;
$from_date = ':from_date';
}

$q = "SELECT g.* FROM #prefix#group_members gm INNER JOIN #prefix#groups g on g.group_id = gm.group_id ";
$q .= "WHERE gm.member_user_id=:member_user_id AND g.network=:network AND gm.is_active=1 ";
$q .= "AND (YEAR(gm.first_seen)=YEAR($from_date)) ";
$q .= "AND (DAYOFMONTH(gm.first_seen)=DAYOFMONTH($from_date)) AND (MONTH(gm.first_seen)=MONTH($from_date)) ";
$q .= "ORDER BY gm.first_seen DESC;";

if ($this->profiler_enabled) Profiler::setDAOMethod(__METHOD__);
$ps = $this->execute($q, $vars);

return $this->getDataRowsAsObjects($ps, "Group");
}
}
9 changes: 9 additions & 0 deletions webapp/_lib/model/interface.GroupMemberDAO.php
Expand Up @@ -79,4 +79,13 @@ public function getTotalGroups($user_id, $network, $active=true);
* @return array - numbered keys, with arrays - named keys
*/
public function getFormerGroups($user_id, $network, $count = 20, $page = 1);

/**
* Get a list of group memberships first seen on a given date.
* @param str $network
* @param str $user_id
* @param str $from_date Defaults to null (today)
* @return arr Group objects
*/
public function getNewMembershipsByDate($network, $user_id, $from_date=null);
}
27 changes: 25 additions & 2 deletions webapp/plugins/twitter/model/class.TwitterCrawler.php
Expand Up @@ -1941,8 +1941,8 @@ private function generateInsightFeedItems($number_days=3) {
$options = $plugin_option_dao->getOptionsHash('geoencoder', true);
if (isset($options['gmaps_api_key']->option_value) && $post->is_geo_encoded == 1) {
$insight_dao->insertInsight('geoencoded_replies', $this->instance->id, $simplified_post_date,
"Going global! Your post got replies and retweets from all over the map.", Insight::EMPHASIS_LOW,
serialize($post));
"Going global! Your post got replies and retweets from locations all over the map.",
Insight::EMPHASIS_LOW, serialize($post));
}
}
}
Expand Down Expand Up @@ -1982,6 +1982,29 @@ private function generateInsightFeedItems($number_days=3) {
$days_ago++;
}

//Generate new list membership insights
$group_membership_dao = DAOFactory::getDAO('GroupMemberDAO');
$days_ago = 0;
while ($days_ago < $number_days) {
$insight_date = new DateTime();
$insight_date->modify('-'.$days_ago.' day');
$insight_date = $insight_date->format('Y-m-d');
//get new group memberships per day
$new_groups = $group_membership_dao->getNewMembershipsByDate($this->instance->network_user_id,
'twitter', $insight_date);
if (sizeof($new_groups) > 0 ) { //if not null, store insight
if (sizeof($new_groups) > 1) {
$insight_dao->insertInsight('new_group_memberships', $this->instance->id, $insight_date,
"Filed: You got added to ".sizeof($new_groups)." lists.", Insight::EMPHASIS_LOW,
serialize($new_groups));
} else {
$insight_dao->insertInsight('new_group_memberships', $this->instance->id, $insight_date,
"You're on a new list.", Insight::EMPHASIS_LOW, serialize($new_groups));
}
}
$days_ago++;
}

//Follower count history milestone
$days_ago = $number_days;
while ($days_ago > -1) {
Expand Down

0 comments on commit 20296b1

Please sign in to comment.