Skip to content

Commit

Permalink
Foursquare dashboard updates
Browse files Browse the repository at this point in the history
* Combine checkins per hour last week and all time charts into a single bar chart ("Checkins Per Hour") that displays both values per hour
* Aligned place types charts next to one another, instead of vertical consecutive
* Rename "The Types Of Places You Visit" to "All-Time Places"
* Rename "The Types Of Places You've Visited This Week" to "This Week's Places"
* Rename "Where You Went This Week" to "This Week's Checkins Map"
* Don't display Response Rates or This Week's Most Replied-To Posts charts for Foursquare users
* Rename "Flashback" posts "Time Machine"
  • Loading branch information
ginatrapani committed Sep 10, 2012
1 parent cc26529 commit 1d57776
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 225 deletions.
4 changes: 2 additions & 2 deletions docs/source/userguide/listings/facebook/dashboard.rst
Expand Up @@ -36,8 +36,8 @@ Friend Count by Day and Week

If there's data, these line charts display your friend count history the past 5 days and 5 weeks.

Flashback: On This Day In Years Past
------------------------------------
Time Machine: On This Day In Years Past
---------------------------------------

Status updates you posted on this day in past years. For example, your posts from 1 year ago, 2 years ago, and 3 years
ago.
35 changes: 10 additions & 25 deletions docs/source/userguide/listings/foursquare/dashboard.rst
Expand Up @@ -9,42 +9,27 @@ Foursquare User name

Name, service name (Foursquare), Foursquare avatar, and last updated time.

Where You Went This Week
This Week's Checkins Map
------------------------

A Google Map of your last 7 days of checkins.

Checkins Per Hour This Week
---------------------------
Checkins Per Hour
-----------------

A bar chart of checkins per hour of the day in the past 7 days.
A bar chart of checkins per hour of the day in the past 7 days compared to all-time.

Checkins Per Hour All Time
--------------------------

A bar chart of all-time checkins per hour of the day.

The Types Of Places You've Visited This Week
--------------------------------------------
This Week's Places
------------------

A pie chart of the types of places you have checked in at in the past 7 days.

The Types Of Places You Visit
-----------------------------
All-Time Places
---------------

A pie chart of the types of places you have ever checked in at.

Response Rates
--------------

A bar chart of comment activity on recent checkins.

This Week's Most Replied-To Posts
---------------------------------

The checkins with the most comments posted in the last 7 days, ordered by number of comments descending.

Flashback: On This Day In Years Past
------------------------------------
Time Machine: On This Day In Years Past
---------------------------------------

Checkins on this day in past years. For example, your checkins from 1 year ago, 2 years ago, and 3 years ago.
4 changes: 2 additions & 2 deletions docs/source/userguide/listings/googleplus/dashboard.rst
Expand Up @@ -37,7 +37,7 @@ This Week's Most Reshared Posts

The posts with the most reshares posted in the last 7 days, ordered by number of reshares descending.

Flashback: On This Day In Years Past
------------------------------------
Time Machine: On This Day In Years Past
---------------------------------------

Posts you published on this day in past years. For example, your posts from 1 year ago, 2 years ago, and 3 years ago.
4 changes: 2 additions & 2 deletions docs/source/userguide/listings/twitter/dashboard.rst
Expand Up @@ -62,7 +62,7 @@ Client Usage

Pie chart of which Twitter clients this user uses over all time.

Flashback: On This Day In Years Past
------------------------------------
Time Machine: On This Day In Years Past
---------------------------------------

Tweets you published on this day in past years. For example, your posts from 1 year ago, 2 years ago, and 3 years ago.
30 changes: 13 additions & 17 deletions tests/TestOfPostMySQLDAO.php
Expand Up @@ -3248,26 +3248,14 @@ public function testCountCheckinsToPlaceTypesLastWeek(){
$this->assertEqual($res, $valid_json);
}

public function testCountCheckinsPerHourAllTime(){
// Query the database for the number of checkins per hour
$post_dao = new PostMySQLDAO();
$res = $post_dao->countCheckinsPerHourAllTime('20', 'foursquare');

$valid_json = '{"rows":[{"c":[{"v":"9"},{"v":1}]}],"cols":[{"type":"string","label":"Hour of Day"},';
$valid_json .= '{"type":"number","label":"Number of Checkins"}]}';

$this->assertEqual($res, $valid_json);
}

public function testCountCheckinsPerHourLastWeek(){
// Build the pub_date string which needs to be a date within the last week
public function testGetPostsPerHourDataVis(){
$pub1 = date(date( 'Y-m-d H:i:s' , strtotime("now")));
$pub2 = date(date( 'Y-m-d H:i:s' , strtotime("now +1 hour")));

$hour1 = date('G', strtotime("now") );
$hour2 = date('G', strtotime("now +1 hour") );

// Add some foursquare checkins (done here due to time dependenacy of test)
// Add some foursquare checkins (done here due to time dependency of test)
$checkin_builder[] = FixtureBuilder::build('posts', array('post_id'=>'998', 'author_user_id'=>'30',
'author_username'=>'user1', 'author_fullname'=>'User 1', 'network'=>'foursquare',
'post_text'=>'I just checked in', 'source'=>'', 'pub_date'=>$pub1, 'location'=>'England',
Expand All @@ -3286,9 +3274,17 @@ public function testCountCheckinsPerHourLastWeek(){

// Query the database for the number of checkins per hour
$post_dao = new PostMySQLDAO();
$res = $post_dao->countCheckinsPerHourLastWeek('30', 'foursquare');
$valid_json = '{"rows":[{"c":[{"v":'.$hour1.'},{"v":1}]},{"c":[{"v":'.$hour2.'},{"v":1}]}],"cols":';
$valid_json .= '[{"type":"string","label":"Hour of Day"},{"type":"number","label":"Number of Checkins"}]}';
$res = $post_dao->getPostsPerHourDataVis('30', 'foursquare');
$valid_json = '{"rows":[{"c":[{"v":0},{"v":0},{"v":0}]},{"c":[{"v":1},{"v":0},{"v":0}]},{"c":[{"v":2},'.
'{"v":0},{"v":0}]},{"c":[{"v":3},{"v":1},{"v":1}]},{"c":[{"v":4},{"v":1},{"v":1}]},{"c":[{"v":5},{"v":0},'.
'{"v":0}]},{"c":[{"v":6},{"v":0},{"v":0}]},{"c":[{"v":7},{"v":0},{"v":0}]},{"c":[{"v":8},{"v":0},{"v":0}]},'.
'{"c":[{"v":9},{"v":0},{"v":0}]},{"c":[{"v":10},{"v":0},{"v":0}]},{"c":[{"v":11},{"v":0},{"v":0}]},'.
'{"c":[{"v":12},{"v":0},{"v":0}]},{"c":[{"v":13},{"v":0},{"v":0}]},{"c":[{"v":14},{"v":0},{"v":0}]},'.
'{"c":[{"v":15},{"v":0},{"v":0}]},{"c":[{"v":16},{"v":0},{"v":0}]},{"c":[{"v":17},{"v":0},{"v":0}]},'.
'{"c":[{"v":18},{"v":0},{"v":0}]},{"c":[{"v":19},{"v":0},{"v":0}]},{"c":[{"v":20},{"v":0},{"v":0}]},'.
'{"c":[{"v":21},{"v":0},{"v":0}]},{"c":[{"v":22},{"v":0},{"v":0}]},{"c":[{"v":23},{"v":0},{"v":0}]}],'.
'"cols":[{"type":"string","label":"Hour of Day"},{"type":"number","label":"Checkins Last Week"},'.
'{"type":"number","label":"Checkins All Time"}]}';

$this->assertEqual($res, $valid_json);
}
Expand Down
19 changes: 5 additions & 14 deletions webapp/_lib/class.DashboardModuleCacher.php
Expand Up @@ -143,23 +143,14 @@ public function cacheDashboardModules() {
$insight_dao->insertInsight("PostMySQLDAO::countCheckinsToPlaceTypes", $this->instance->id,
$simplified_date, '', '', Insight::EMPHASIS_LOW, serialize($checkins_all_time_count));

// Cache PostMySQLDAO::countCheckinsPerHourAllTime
$checkins_per_hour = $post_dao->countCheckinsPerHourAllTime($this->instance->network_user_id,
// Cache PostMySQLDAO::getPostsPerHourDataVis
$hourly_checkin_datavis = $post_dao->getPostsPerHourDataVis($this->instance->network_user_id,
$this->instance->network);
//delete existing
$insight_dao->deleteInsightsBySlug("PostMySQLDAO::countCheckinsPerHourAllTime", $this->instance->id);
$insight_dao->deleteInsightsBySlug("PostMySQLDAO::getPostsPerHourDataVis", $this->instance->id);
//insert new
$insight_dao->insertInsight("PostMySQLDAO::countCheckinsPerHourAllTime", $this->instance->id,
$simplified_date, '', '', Insight::EMPHASIS_LOW, serialize($checkins_per_hour));

// Cache PostMySQLDAO::countCheckinsPerHourLastWeek
$checkins_per_hour_last_week = $post_dao->countCheckinsPerHourLastWeek($this->instance->network_user_id,
$this->instance->network);
//delete existing
$insight_dao->deleteInsightsBySlug("PostMySQLDAO::countCheckinsPerHourLastWeek", $this->instance->id);
//insert new
$insight_dao->insertInsight("PostMySQLDAO::countCheckinsPerHourLastWeek", $this->instance->id,
$simplified_date, '', '', Insight::EMPHASIS_LOW, serialize($checkins_per_hour_last_week));
$insight_dao->insertInsight("PostMySQLDAO::getPostsPerHourDataVis", $this->instance->id,
$simplified_date, '', '', Insight::EMPHASIS_LOW, serialize($hourly_checkin_datavis));

// Cache PostMySQLDAO::getAllCheckinsInLastWeekAsGoogleMap
$checkins_map = $post_dao->getAllCheckinsInLastWeekAsGoogleMap($this->instance->network_user_id,
Expand Down
11 changes: 3 additions & 8 deletions webapp/_lib/controller/class.DashboardController.php
Expand Up @@ -288,15 +288,10 @@ private function loadDefaultDashboard() {

// Foursquare items
if ($this->instance->network == "foursquare") {
// Checkins per hour - all time
// Checkins per hour
$checkins_per_hour = $insight_dao->getPreCachedInsightData(
'PostMySQLDAO::countCheckinsPerHourAllTime', $this->instance->id, date('Y-m-d'));
$this->addToView('checkins_per_hour_all_time', $checkins_per_hour);

// Checkins per hour - last week
$checkins_per_hour_last_week = $insight_dao->getPreCachedInsightData(
'PostMySQLDAO::countCheckinsPerHourLastWeek', $this->instance->id, date('Y-m-d'));
$this->addToView('checkins_per_hour_last_week', $checkins_per_hour_last_week);
'PostMySQLDAO::getPostsPerHourDataVis', $this->instance->id, date('Y-m-d'));
$this->addToView('checkins_per_hour', $checkins_per_hour);

// Checkins by type of place - all time
$place_types = $insight_dao->getPreCachedInsightData(
Expand Down
112 changes: 50 additions & 62 deletions webapp/_lib/dao/class.PostMySQLDAO.php
Expand Up @@ -1822,7 +1822,7 @@ public function countCheckinsToPlaceTypes($author_id, $network) {
// Now encode this data as JSON for the Google Charts API
$visdata = json_encode(array('rows' => $resultset, 'cols' => $metadata));

if(count($all_rows) > 0) {
if (count($all_rows) > 0) {
return $visdata;
} else {
return "";
Expand Down Expand Up @@ -1868,55 +1868,74 @@ public function countCheckinsToPlaceTypesLastWeek($author_id, $network) {
* So we know not to draw this graph on the dashboard.
*/

if(count($all_rows) > 0) {
if (count($all_rows) > 0) {
return $visdata;
} else {
return "";
}
}

public function countCheckinsPerHourAllTime($author_id, $network) {
$q = "SELECT HOUR(pub_date) AS hour, COUNT(HOUR(pub_date)) AS counter FROM #prefix#posts ";
$q .= "WHERE author_user_id=:author ";
$q .= "AND network=:network AND in_reply_to_post_id IS null GROUP BY HOUR(pub_date)";
$vars = array(
'author'=>$author_id,
'network'=>$network
);
if ($this->profiler_enabled) Profiler::setDAOMethod(__METHOD__);
$ps = $this->execute($q, $vars);
$all_rows = $this->getDataRowsAsArrays($ps);
public function getPostsPerHourDataVis($author_id, $network) {
$posts_per_hour_all_time = $this->getCheckinsPerHourAllTime($author_id, $network);
$posts_per_hour_last_week = $this->getCheckinsPerHourLastWeek($author_id, $network);

// Convert the results into Google Charts Format
foreach ($all_rows as $row) {
$i = 0;
while ($i < 24) { // Hour 0 through 23
/* Data needs to be in format
{c:[{v: 'Hour'}, {v: Number of checkins at this hour}]}
e.g. [{c:[{v: '11'}, {v: 5}]}
*/
$resultset[] = array('c' => array(
array('v' => $row['hour']),
array('v' => intval($row['counter']))
{c:[{v: 'Hour'}, {v: Number of checkins at this hour}]}
e.g. [{c:[{v: '11'}, {v: 5}]}
*/
foreach ($posts_per_hour_last_week as $row) {
if ($row['hour'] == $i) {
$last_week_value = intval($row['total']);
break;
}
$last_week_value = 0;
}

foreach ($posts_per_hour_all_time as $row) {
if ($row['hour'] == $i) {
$all_time_value = intval($row['total']);
break;
}
$all_time_value = 0;
}

$post_data[] = array('c' => array(
array('v' => $i),
array('v' => $last_week_value),
array('v' => $all_time_value),
));
$i++;
}

// Set the meta values like titles etc.
$metadata = array(
array('type' => 'string', 'label' => 'Hour of Day'),
array('type' => 'number', 'label' => 'Number of Checkins'),
array('type' => 'number', 'label' => 'Checkins Last Week'),
array('type' => 'number', 'label' => 'Checkins All Time'),
);

// Now encode this data as JSON for the Google Charts API
$visdata = json_encode(array('rows' => $resultset, 'cols' => $metadata));
return json_encode(array('rows' => $post_data, 'cols' => $metadata));
}

if(count($all_rows) > 0) {
return $visdata;
} else {
return "";
}
private function getCheckinsPerHourAllTime($author_id, $network) {
$q = "SELECT HOUR(pub_date) AS hour, COUNT(HOUR(pub_date)) AS total FROM #prefix#posts ";
$q .= "WHERE author_user_id=:author ";
$q .= "AND network=:network AND in_reply_to_post_id IS null GROUP BY HOUR(pub_date)";
$vars = array(
'author'=>$author_id,
'network'=>$network
);
if ($this->profiler_enabled) Profiler::setDAOMethod(__METHOD__);
$ps = $this->execute($q, $vars);
return $this->getDataRowsAsArrays($ps);
}

public function countCheckinsPerHourLastWeek($author_id, $network) {
$q = "SELECT CAST(HOUR(pub_date) AS UNSIGNED) AS hour, COUNT(HOUR(pub_date)) AS counter FROM #prefix#posts ";
private function getCheckinsPerHourLastWeek($author_id, $network) {
$q = "SELECT CAST(HOUR(pub_date) AS UNSIGNED) AS hour, COUNT(HOUR(pub_date)) AS total FROM #prefix#posts ";
$q .= "WHERE author_user_id=:author ";
$q .= "AND network=:network AND YEARWEEK(pub_date) = YEARWEEK(CURRENT_DATE) AND in_reply_to_post_id IS null ";
$q .= "GROUP BY HOUR(pub_date)";
Expand All @@ -1925,38 +1944,7 @@ public function countCheckinsPerHourLastWeek($author_id, $network) {
'network'=>$network);
if ($this->profiler_enabled) Profiler::setDAOMethod(__METHOD__);
$ps = $this->execute($q, $vars);
$all_rows = $this->getDataRowsAsArrays($ps);

// Convert the results into Google Charts Format
foreach ($all_rows as $row) {
/* Data needs to be in format
{c:[{v: 'Hour'}, {v: Number of checkins at this hour}]}
e.g. [{c:[{v: '11'}, {v: 5}]}
*/
$resultset[] = array('c' => array(
array('v' => intval($row['hour'])),
array('v' => intval($row['counter']))
));
}

// Set the meta values like titles etc.
$metadata = array(
array('type' => 'string', 'label' => 'Hour of Day'),
array('type' => 'number', 'label' => 'Number of Checkins'),
);

// Now encode this data as JSON for the Google Charts API
$visdata = json_encode(array('rows' => $resultset, 'cols' => $metadata));

/* As we are getting posts from the last week, we might not have any so return a blank string in that instance
* So we know not to draw this graph on the dashboard.
*/

if(count($all_rows) > 0) {
return $visdata;
} else {
return "";
}
return $this->getDataRowsAsArrays($ps);
}

public function getAllCheckinsInLastWeekAsGoogleMap($author_id, $network) {
Expand All @@ -1979,7 +1967,7 @@ public function getAllCheckinsInLastWeekAsGoogleMap($author_id, $network) {

$url .= '&sensor=false';

if(count($all_rows) > 0) {
if (count($all_rows) > 0) {
return $url;
} else {
return "";
Expand Down
24 changes: 8 additions & 16 deletions webapp/_lib/dao/interface.PostDAO.php
Expand Up @@ -591,27 +591,19 @@ public function getAllCheckins($author_id, $network, $count=15, $page=1);
*/
public function countCheckinsToPlaceTypes($author_id, $network);

/**
* Count the number of checkins per hour,
* @param str $author_id
* @param str $network
* @return array Hour, number of checkins at that hour pairs
*/
public function countCheckinsPerHourAllTime($author_id, $network);

/**
* Count the number of checkins per hour in the last week.
* @param str $author_id
* @param str $network
* @return array Hour, number of checkins at that hour pairs
*/
public function countCheckinsPerHourLastWeek($author_id, $network);

/**
* Generate a map image URL for the checkins in the last week
* @param str $author_id
* @param str $network
* @return string that is a URL to a image of the checkins on a google map
*/
public function getAllCheckinsInLastWeekAsGoogleMap($author_id, $network);

/**
* Get Javascript data table of post rate per hour all time versus last week.
* @param $author_id
* @param $network
* @return str JavaScript data for Google chart
*/
public function getPostsPerHourDataVis($author_id, $network);
}

0 comments on commit 1d57776

Please sign in to comment.