Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1948 unfollowers analysis #2074

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
32fca9b
Changed mail setting
May 29, 2014
453d706
Added gender field. Gender field prosessing in DAO classes.
May 29, 2014
3359c46
Changes for gender field in Crawler
Jun 1, 2014
a56bc6f
Gender field tests in TestOfFacebookCrawler
Jun 4, 2014
a4eded9
Getting data from DB for gender analysis
Jun 8, 2014
99232ff
Created template for gender analysis
Jun 8, 2014
f1351dc
finish gender analysis tpl and php
Jun 15, 2014
6106e3c
sql changes for birthday field
Jun 15, 2014
2025b6c
TestOfUserMySQLDAO changes for birthday field
Jun 15, 2014
ac7f15a
changed testdata and TestOfFacebookCrawler for birthday field
Jun 15, 2014
6f6494d
getAgeOfFavoriters and getAgeOfCommenters functions added
Jun 16, 2014
d292ab0
chenged domentation
Jun 17, 2014
d5cf196
call gender analysis every day
Jun 17, 2014
2c01870
corrections
Jun 17, 2014
2023935
Tests for gender analysis
Jun 18, 2014
30b3f3d
fixed merge conflict
Jun 18, 2014
6a480bc
fixed merge conflict2
Jun 18, 2014
e629250
fixed merge conflict2
Jun 18, 2014
bb3ea85
Age analysis insight php and tpl
Jun 19, 2014
6b40046
Tests for age analysis, php and tpl corrections after tests
Jun 19, 2014
e739d01
Some corrections for age analysis in php, tpl and tests
Jun 19, 2014
703cf36
corrections
Jun 19, 2014
a9b422a
first fersion of php and tpl for geo analysis
Jun 20, 2014
6245693
finished php and tpl for geo analysis
Jul 8, 2014
dc6a1bb
tests and query changes
Jul 13, 2014
2968cb6
add TestOfGeoAnalysisFacebookInsight
Jul 13, 2014
16b0073
corrections
Jul 22, 2014
67766b1
added shares_count_cache field and its processing
Jul 22, 2014
45bb638
added function getting most shared posts, php and tpl for top of post…
Jul 22, 2014
271b8c8
updated top of posts insight
Jul 28, 2014
e65c8a0
sql for shares_count_cache field
Jul 28, 2014
ecfc95b
top of posts added shares count into insight view
Jul 28, 2014
3c277f6
added tests for top of posts insight
Aug 8, 2014
60b9b7e
bug fix
Aug 8, 2014
a705d86
description
Aug 8, 2014
b8bdf15
bug fix
Aug 8, 2014
acd23df
bug fix 2
Aug 8, 2014
21366ca
bug fix
Aug 8, 2014
7ed40d1
commit
Aug 8, 2014
f4a389a
merge age analysis
Aug 8, 2014
1d43559
Merge branch '1945-geo-analysis-facebook'
Aug 8, 2014
7f06543
merge geo analysis facebook
Aug 8, 2014
c659244
added php and tpl for geo analysis twitter insight
Aug 12, 2014
090a908
tests for geo analysis twitter
Aug 13, 2014
f766302
twitter crawler, sql, php and tpl changed and added for unfollowers a…
Aug 18, 2014
8b2944e
tests fr unfollowers analysis
Aug 18, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Age analysis insight php and tpl
  • Loading branch information
anna committed Jun 19, 2014
commit bb3ea85eed82413d90af39e2acc4dd15c1bd1849
119 changes: 119 additions & 0 deletions webapp/plugins/insightsgenerator/insights/ageanalysis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
/*
Plugin Name: Age Analysis
Description: Age of people who have made your post the most popular today.
*/
/**
*
* ThinkUp/webapp/plugins/insightsgenerator/insights/ageanalysis.php
*
* LICENSE:
*
* This file is part of ThinkUp (http://thinkup.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/>.
*
*
* AgeAnalysis (name of file)
*
* Description of what this class does
*
* Copyright (c) 2014 Anna Shkerina
*
* @author Anna Shkerina blond00792@gmail.com
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2014 Anna Shkerina
*/

class AgeAnalysisInsight extends InsightPluginParent implements InsightPlugin {

public function generateInsight(Instance $instance, $last_week_of_posts, $number_days) {
parent::generateInsight ( $instance, $last_week_of_posts, $number_days );
$this->logger->logInfo ( "Begin generating insight", __METHOD__ . ',' . __LINE__ );

$insight_baseline_dao = DAOFactory::getDAO ( 'InsightBaselineDAO' );
$filename = basename ( __FILE__, ".php" );

$post_dao = DAOFactory::getDAO ( 'PostDAO' );
$fpost_dao = DAOFactory::getDAO ( 'FavoritePostDAO' );
$posts = $post_dao->getMostFavCommentPostsByUserId ( $instance->network_user_id, $instance->network );
foreach ( $posts as $post ) {
$birthdays_fav = $fpost_dao->getBirthdayOfFavoriters ( $post->post_id );
$birthdays_comm = $fpost_dao->getBirthdayOfCommenters ( $post->post_id );
$age_data = array(
'18'=>0,
'18_25'=>0,
'25_35'=>0,
'35_45'=>0,
'45'=>0
);

foreach ($birthdays_comm as $birthday_comm){
$birthday = strtotime($birthday_comm);
if($birthday === false){
return false;
}

$age = date('Y') - date('Y', $birthday);
if (date('md') < date('md', $birthday)) {
$age--;
}

if ($age<18){
$age_data['18']++;
} elseif ($age>=18 & $age<25){
$age_data['18_25']++;
} elseif ($age>=25 & $age<35){
$age_data['25_35']++;
} elseif ($age>=35 & $age<45){
$age_data['35_45']++;
} else $age_data['45']++;
}

foreach ($birthdays_fav as $birthday_fav){
$birthday = strtotime($birthday_fav);
if($birthday === false){
return false;
}
$age = date('Y') - date('Y', $birthday);
if (date('md') < date('md', $birthday)) {
$age--;
}

if ($age<18){
$age_data['18']++;
} elseif ($age>=18 & $age<25){
$age_data['18_25']++;
} elseif ($age>=25 & $age<35){
$age_data['25_35']++;
} elseif ($age>=35 & $age<45){
$age_data['35_45']++;
} else $age_data['45']++;

}

echo "age_data=".Utils::varDumpToString($age_data)."<br />";

$simplified_post_date = date('Y-m-d', strtotime($post->pub_date));

$this->insight_dao->insertInsightDeprecated ( 'age_analysis', $instance->id,
$simplified_post_date, "Age analysis", "Here is the distribution of ages for ".
$instance->network_username . "'s post", $filename, Insight::EMPHASIS_HIGH,
serialize ( array ($post, $age_data) ) );
}
$this->logger->logInfo("Done generating insight", __METHOD__.','.__LINE__);
}
}

$insights_plugin_registrar = PluginRegistrarInsights::getInstance();
$insights_plugin_registrar->registerInsightPlugin('AgeAnalysisInsight');

69 changes: 69 additions & 0 deletions webapp/plugins/insightsgenerator/view/ageanalysis.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{include file=$tpl_path|cat:'_header.tpl'}

{if !$expand}
<div class="pull-right detail-btn"><button class="btn btn-info btn-mini" data-toggle="collapse" data-target="#chart-{$i->id}"><i class="icon-signal icon-white"></i></button></div>
{/if}

<span class="label label-{if $i->emphasis eq '1'}info{elseif $i->emphasis eq '2'}success{elseif $i->emphasis eq '3'}error{else}info{/if}"><i class="icon-white icon-gift"></i> <a href="?u={$i->instance->network_username}&n={$i->instance->network}&d={$i->date|date_format:'%Y-%m-%d'}&s={$i->slug}">{$i->headline}</a></span>

<i class="icon-{$i->instance->network}{if $i->instance->network eq 'google+'} icon-google-plus{/if} icon-muted"></i>
{$i->text|link_usernames_to_twitter}

<div class="insight-attachment-detail post">
{include file=$tpl_path|cat:"_post.tpl" post=$i->related_data[0] hide_insight_header=true}
</div>

{if !$expand}
<div class="collapse in" id="chart-{$i->id}">
{/if}

<div id="age_analysis_{$i->id}">&nbsp;</div>
<script type="text/javascript">
// Load the Visualization API and the standard charts
google.load('visualization', '1');
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart{$i->id} );

{literal}
function drawChart{/literal}{$i->id}{literal}() {
{/literal}
var age_analysis_data_{$i->id} = new google.visualization.arrayToDataTable([
['Ages','<18', '18-25', '25-35', '35-45', '>45'],
['Number', {$i->related_data[1].18+5}, {$i->related_data[1].18_25}, {$i->related_data[1].25_35+7}, {$i->related_data[1].35_45+10}, {$i->related_data[1].45+1}]
]);
{literal}
var age_analysis_chart_{/literal}{$i->id}{literal} = new google.visualization.ChartWrapper({
containerId: 'age_analysis_{/literal}{$i->id}{literal}',
chartType: 'ColumnChart',
dataTable: age_analysis_data_{/literal}{$i->id}{literal},
'options': {
colors: ['#3EA5CF', '#E4BF28', '#5FAC1C', '#DA6070', '#24B98F'],
isStacked: false,
width: 650,
height: 250,
chartArea:{left: 100, height:"80%"},
legend: { position: 'bottom'},

hAxis: {
textStyle: { color: '#fff', fontSize: 1 }
},

vAxis: {
minValue: 0,
baselineColor: '#ccc',
textStyle: { color: '#999' },
gridlines: { color: '#eee' }
},
}

});
age_analysis_chart_{/literal}{$i->id}{literal}.draw();
}
{/literal}
</script>

{if !$expand}
</div>
{/if}

{include file=$tpl_path|cat:'_footer.tpl'}