partial #1522
This commit is contained in:
parent
07d728fa1e
commit
17799b8c3e
@ -21,8 +21,8 @@ class Crunchbutton_Chart_Churn extends Crunchbutton_Chart {
|
||||
'tags' => array( 'main' ),
|
||||
'charts' => array(
|
||||
'churn-rate-per-active-user-per-day' => array( 'title' => 'Day', 'interval' => 'day', 'type' => 'column', 'method' => 'activeByDay'),
|
||||
'churn-rate-per-active-user-per-week' => array( 'title' => 'Week', 'interval' => 'week', 'type' => 'column', 'method' => 'activeByWeek'),
|
||||
'churn-rate-per-active-user-per-month' => array( 'title' => 'Month', 'interval' => 'month', 'type' => 'column', 'method' => 'activeByMonth'),
|
||||
'churn-rate-per-active-user-per-week' => array( 'title' => 'Week', 'interval' => 'week', 'type' => 'column', 'method' => 'activeByWeek', 'filters' => array( array( 'title' => 'Community', 'type' => 'community', 'method' => 'activeByWeekByCommunity' ) ) ),
|
||||
'churn-rate-per-active-user-per-month' => array( 'title' => 'Month', 'interval' => 'month', 'type' => 'column', 'method' => 'activeByMonth', 'filters' => array( array( 'title' => 'Community', 'type' => 'community', 'method' => 'activeByMonthByCommunity' ) ) ),
|
||||
)
|
||||
),
|
||||
);
|
||||
@ -64,6 +64,61 @@ class Crunchbutton_Chart_Churn extends Crunchbutton_Chart {
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function activeByMonthByCommunity( $render = false ){
|
||||
|
||||
$user = new Crunchbutton_Chart_User();
|
||||
|
||||
$activeUsers = $user->activeByMonthByCommunity();
|
||||
$newUsers = $user->newByMonthByCommunity();
|
||||
|
||||
$communities = $this->allCommunities();
|
||||
|
||||
$_data = [];
|
||||
$_prev = [];
|
||||
|
||||
foreach ( $activeUsers as $active ) {
|
||||
if( !$_data[ $active->Label ] ){
|
||||
$_data[ $active->Label ] = [];
|
||||
}
|
||||
$_data[ $active->Label ][ 'ActiveUser' ][ $active->Type ] = $active->Total;
|
||||
$_data[ $active->Label ][ 'ActiveUserPrev' ][ $active->Type ] = ( $_prev[ $active->Type ] ? $_prev[ $active->Type ] : 0 );
|
||||
$_prev[ $active->Type ] = $active->Total;
|
||||
}
|
||||
|
||||
foreach ( $newUsers as $newUser ) {
|
||||
if( !$_data[ $newUser->Label ] ){
|
||||
$_data[ $newUser->Label ] = [];
|
||||
}
|
||||
$_data[ $newUser->Label ][ 'NewUser' ][ $newUser->Type ] = $newUser->Total;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $_data as $label => $values ) {
|
||||
foreach( $communities as $community ){
|
||||
$active = $values[ 'ActiveUser' ][ $community ];
|
||||
$newUser = $values[ 'NewUser' ][ $community ];
|
||||
$prev = $values[ 'ActiveUserPrev' ][ $community ];
|
||||
|
||||
$lost = ( ( $prev + $newUser ) - $active );
|
||||
$lost = ( $lost < 0 ) ? 0 : $lost;
|
||||
|
||||
// Formula: so, divide the number lost by the previous week's total
|
||||
if( $prev != 0 && $lost != 0 ){
|
||||
$result = $lost / $prev;
|
||||
} else {
|
||||
$result = 0;
|
||||
}
|
||||
|
||||
$data[] = ( object ) array( 'Label' => $label, 'Total' => $result, 'Type' => $community );
|
||||
}
|
||||
}
|
||||
if( $render ){
|
||||
return array( 'data' => $data, 'unit' => $this->unit, 'interval' => 'month' );
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function activeByMonth( $render = false ){
|
||||
|
||||
$user = new Crunchbutton_Chart_User();
|
||||
@ -130,6 +185,61 @@ class Crunchbutton_Chart_Churn extends Crunchbutton_Chart {
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function activeByWeekByCommunity( $render = false ){
|
||||
|
||||
$user = new Crunchbutton_Chart_User();
|
||||
|
||||
$activeUsers = $user->activeByWeekByCommunity();
|
||||
$newUsers = $user->newByWeekByCommunity();
|
||||
|
||||
$communities = $this->allCommunities();
|
||||
|
||||
$_data = [];
|
||||
$_prev = [];
|
||||
|
||||
foreach ( $activeUsers as $active ) {
|
||||
if( !$_data[ $active->Label ] ){
|
||||
$_data[ $active->Label ] = [];
|
||||
}
|
||||
$_data[ $active->Label ][ 'ActiveUser' ][ $active->Type ] = $active->Total;
|
||||
$_data[ $active->Label ][ 'ActiveUserPrev' ][ $active->Type ] = ( $_prev[ $active->Type ] ? $_prev[ $active->Type ] : 0 );
|
||||
$_prev[ $active->Type ] = $active->Total;
|
||||
}
|
||||
|
||||
foreach ( $newUsers as $newUser ) {
|
||||
if( !$_data[ $newUser->Label ] ){
|
||||
$_data[ $newUser->Label ] = [];
|
||||
}
|
||||
$_data[ $newUser->Label ][ 'NewUser' ][ $newUser->Type ] = $newUser->Total;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $_data as $label => $values ) {
|
||||
foreach( $communities as $community ){
|
||||
$active = $values[ 'ActiveUser' ][ $community ];
|
||||
$newUser = $values[ 'NewUser' ][ $community ];
|
||||
$prev = $values[ 'ActiveUserPrev' ][ $community ];
|
||||
|
||||
$lost = ( ( $prev + $newUser ) - $active );
|
||||
$lost = ( $lost < 0 ) ? 0 : $lost;
|
||||
|
||||
// Formula: so, divide the number lost by the previous week's total
|
||||
if( $prev != 0 && $lost != 0 ){
|
||||
$result = $lost / $prev;
|
||||
} else {
|
||||
$result = 0;
|
||||
}
|
||||
|
||||
$data[] = ( object ) array( 'Label' => $label, 'Total' => $result, 'Type' => $community );
|
||||
}
|
||||
}
|
||||
if( $render ){
|
||||
return array( 'data' => $data, 'unit' => $this->unit );
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function byWeek( $render = false ){
|
||||
|
||||
$user = new Crunchbutton_Chart_User();
|
||||
|
||||
@ -1106,6 +1106,7 @@ class Crunchbutton_Chart_Order extends Crunchbutton_Chart {
|
||||
$_data = [];
|
||||
|
||||
$_prev = [];
|
||||
|
||||
foreach ( $activeUsers as $active ) {
|
||||
if( !$_data[ $active->Label ] ){
|
||||
$_data[ $active->Label ] = [];
|
||||
@ -1139,7 +1140,7 @@ class Crunchbutton_Chart_Order extends Crunchbutton_Chart {
|
||||
$order = $values[ 'Order' ][ $community ];
|
||||
|
||||
// Formula (Orders minus New Users) / (Active Users) | Active Users = ( average of the current week and previous week's Active Users )
|
||||
if( $active && $prev ){
|
||||
if( $active || $prev ){
|
||||
$activeUsersAvg = ( $active + $prev ) / 2;
|
||||
} else {
|
||||
$activeUsersAvg = 0;
|
||||
@ -1152,13 +1153,12 @@ class Crunchbutton_Chart_Order extends Crunchbutton_Chart {
|
||||
} else {
|
||||
$result = 0;
|
||||
}
|
||||
|
||||
$data[] = ( object ) array( 'Label' => $label, 'Total' => $repeat, 'Type' => $community );
|
||||
$data[] = ( object ) array( 'Label' => $label, 'Total' => $result, 'Type' => $community );
|
||||
}
|
||||
}
|
||||
|
||||
if( $render ){
|
||||
return array( 'data' => $data, 'unit' => $this->unit );
|
||||
return array( 'data' => $data, 'unit' => $this->unit, 'interval' => 'month' );
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
@ -1176,6 +1176,7 @@ class Crunchbutton_Chart_Order extends Crunchbutton_Chart {
|
||||
$_data = [];
|
||||
|
||||
$_prev = [];
|
||||
|
||||
foreach ( $activeUsers as $active ) {
|
||||
if( !$_data[ $active->Label ] ){
|
||||
$_data[ $active->Label ] = [];
|
||||
@ -1209,7 +1210,7 @@ class Crunchbutton_Chart_Order extends Crunchbutton_Chart {
|
||||
$order = $values[ 'Order' ][ $community ];
|
||||
|
||||
// Formula (Orders minus New Users) / (Active Users) | Active Users = ( average of the current week and previous week's Active Users )
|
||||
if( $active && $prev ){
|
||||
if( $active || $prev ){
|
||||
$activeUsersAvg = ( $active + $prev ) / 2;
|
||||
} else {
|
||||
$activeUsersAvg = 0;
|
||||
@ -1223,7 +1224,7 @@ class Crunchbutton_Chart_Order extends Crunchbutton_Chart {
|
||||
$result = 0;
|
||||
}
|
||||
|
||||
$data[] = ( object ) array( 'Label' => $label, 'Total' => $repeat, 'Type' => $community );
|
||||
$data[] = ( object ) array( 'Label' => $label, 'Total' => $result, 'Type' => $community );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user