partial #2252 - Historical Churn and Historical Churn Rate - added the months and weeks charts
This commit is contained in:
parent
98977ef951
commit
427951e09d
13
db/migrate/000161_charts.sql
Normal file
13
db/migrate/000161_charts.sql
Normal file
@ -0,0 +1,13 @@
|
||||
/* INSERT THE CHARTS */
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'churn-rate-per-active-user-per-day', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'churn-rate-per-active-user-per-week', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'churn-rate-per-active-user-per-month', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'historial-churn-per-day', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'historial-churn-per-week', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'historial-churn-per-month', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'users-new-per-day-historical', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'users-new-per-week-historical', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'users-new-per-month-historical', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'historial-churn-rate-per-day', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'historial-churn-rate-per-week', '');
|
||||
INSERT INTO `chart` ( `permalink`, `description`) VALUES( 'historial-churn-rate-per-month', '');
|
||||
@ -31,6 +31,8 @@ class Crunchbutton_Chart_Churn extends Crunchbutton_Chart {
|
||||
'tags' => array( 'detailed-analytics' ),
|
||||
'charts' => array(
|
||||
'historial-churn-per-day' => array( 'title' => 'Day', 'interval' => 'day', 'type' => 'column', 'method' => 'historicalChurnByDay'),
|
||||
'historial-churn-per-week' => array( 'title' => 'Week', 'interval' => 'week', 'type' => 'column', 'method' => 'historicalChurnByWeek'),
|
||||
'historial-churn-per-month' => array( 'title' => 'Month', 'interval' => 'month', 'type' => 'column', 'method' => 'historicalChurnByMonth'),
|
||||
)
|
||||
),
|
||||
'group-historical-churn-rate-per-active-user' => array(
|
||||
@ -39,6 +41,8 @@ class Crunchbutton_Chart_Churn extends Crunchbutton_Chart {
|
||||
'tags' => array( 'detailed-analytics' ),
|
||||
'charts' => array(
|
||||
'historial-churn-rate-per-day' => array( 'title' => 'Day', 'interval' => 'day', 'type' => 'column', 'method' => 'historicalChurnRateByDay'),
|
||||
'historial-churn-rate-per-week' => array( 'title' => 'Week', 'interval' => 'week', 'type' => 'column', 'method' => 'historicalChurnRateByWeek'),
|
||||
'historial-churn-rate-per-month' => array( 'title' => 'Month', 'interval' => 'month', 'type' => 'column', 'method' => 'historicalChurnRateByMonth'),
|
||||
)
|
||||
),
|
||||
);
|
||||
@ -47,7 +51,68 @@ class Crunchbutton_Chart_Churn extends Crunchbutton_Chart {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function historicalChurnRateByWeek( $render = false ){
|
||||
$allDays = $this->allDays();
|
||||
$days = [];
|
||||
$weeks = [];
|
||||
$data = [];
|
||||
|
||||
$byDay = $this->historicalChurnRateByDay();
|
||||
|
||||
for( $i = $this->from_day -1 ; $i < $this->to_day; $i++ ){
|
||||
$days[] = $allDays[ $i ];
|
||||
}
|
||||
|
||||
for( $i = 0; $i < count( $byDay ); $i++ ){
|
||||
$week = $this->dateToWeek( $days[ $i ] );
|
||||
if( !$weeks[ $week ] ){
|
||||
$weeks[ $week ] = array( 'Label' => $week, 'Total' => $byDay[ $i ]->Total );
|
||||
} else {
|
||||
$weeks[ $week ][ 'Total' ] = $weeks[ $week ][ 'Total' ] + $byDay[ $i ]->Total;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( $weeks as $week ){
|
||||
$data[] = ( object ) array( 'Label' => $week[ 'Label' ] , 'Total' => $week[ 'Total' ], 'Type' => 'Users' );
|
||||
}
|
||||
|
||||
if( $render ){
|
||||
return array( 'data' => $data, 'unit' => $this->unit );
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function historicalChurnRateByMonth( $render = false ){
|
||||
$allDays = $this->allDays();
|
||||
$days = [];
|
||||
$months = [];
|
||||
$data = [];
|
||||
|
||||
$byDay = $this->historicalChurnRateByDay();
|
||||
|
||||
for( $i = $this->from_day -1 ; $i < $this->to_day; $i++ ){
|
||||
$days[] = $allDays[ $i ];
|
||||
}
|
||||
|
||||
for( $i = 0; $i < count( $byDay ); $i++ ){
|
||||
$month = $this->dateToMonth( $days[ $i ], true );
|
||||
if( !$months[ $month ] ){
|
||||
$months[ $month ] = array( 'Label' => $month, 'Total' => $byDay[ $i ]->Total );
|
||||
} else {
|
||||
$months[ $month ][ 'Total' ] = $months[ $month ][ 'Total' ] + $byDay[ $i ]->Total;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( $months as $month ){
|
||||
$data[] = ( object ) array( 'Label' => $month[ 'Label' ] , 'Total' => $month[ 'Total' ], 'Type' => 'Users' );
|
||||
}
|
||||
|
||||
if( $render ){
|
||||
return array( 'data' => $data, 'unit' => $this->unit );
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function historicalChurnRateByDay( $render = false ){
|
||||
$user = new Crunchbutton_Chart_User();
|
||||
$daysForward = $this->activeUsersInterval;
|
||||
@ -74,6 +139,71 @@ class Crunchbutton_Chart_Churn extends Crunchbutton_Chart {
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function historicalChurnByMonth( $render = false ){
|
||||
$allDays = $this->allDays();
|
||||
$days = [];
|
||||
$months = [];
|
||||
$data = [];
|
||||
|
||||
$byDay = $this->historicalChurnByDay();
|
||||
|
||||
for( $i = $this->from_day -1 ; $i < $this->to_day; $i++ ){
|
||||
$days[] = $allDays[ $i ];
|
||||
}
|
||||
|
||||
for( $i = 0; $i < count( $byDay ); $i++ ){
|
||||
$month = $this->dateToMonth( $days[ $i ], true );
|
||||
if( !$months[ $month ] ){
|
||||
$months[ $month ] = array( 'Label' => $month, 'Total' => $byDay[ $i ]->Total );
|
||||
} else {
|
||||
$months[ $month ][ 'Total' ] = $months[ $month ][ 'Total' ] + $byDay[ $i ]->Total;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( $months as $month ){
|
||||
$data[] = ( object ) array( 'Label' => $month[ 'Label' ] , 'Total' => $month[ 'Total' ], 'Type' => 'Users' );
|
||||
}
|
||||
|
||||
if( $render ){
|
||||
return array( 'data' => $data, 'unit' => $this->unit );
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function historicalChurnByWeek( $render = false ){
|
||||
|
||||
$allDays = $this->allDays();
|
||||
$days = [];
|
||||
$weeks = [];
|
||||
$data = [];
|
||||
|
||||
$byDay = $this->historicalChurnByDay();
|
||||
|
||||
for( $i = $this->from_day -1 ; $i < $this->to_day; $i++ ){
|
||||
$days[] = $allDays[ $i ];
|
||||
}
|
||||
|
||||
for( $i = 0; $i < count( $byDay ); $i++ ){
|
||||
$week = $this->dateToWeek( $days[ $i ] );
|
||||
if( !$weeks[ $week ] ){
|
||||
$weeks[ $week ] = array( 'Label' => $week, 'Total' => $byDay[ $i ]->Total );
|
||||
} else {
|
||||
$weeks[ $week ][ 'Total' ] = $weeks[ $week ][ 'Total' ] + $byDay[ $i ]->Total;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( $weeks as $week ){
|
||||
$data[] = ( object ) array( 'Label' => $week[ 'Label' ] , 'Total' => $week[ 'Total' ], 'Type' => 'Users' );
|
||||
}
|
||||
|
||||
if( $render ){
|
||||
return array( 'data' => $data, 'unit' => $this->unit );
|
||||
}
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
public function historicalChurnByDay( $render = false ){
|
||||
$user = new Crunchbutton_Chart_User();
|
||||
$daysForward = $this->activeUsersInterval;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user