Fixed played minutes calculation and player profile stats

This commit is contained in:
Brian Miyaji
2017-03-20 09:33:01 +11:00
parent 2cee6cc8d6
commit 75726fb838
2 changed files with 52 additions and 14 deletions

View File

@@ -406,12 +406,14 @@ class SP_Player_List extends SP_Custom_Post {
// Continue with incrementing values if active in event // Continue with incrementing values if active in event
if ( sp_array_value( $player_performance, 'status' ) != 'sub' || sp_array_value( $player_performance, 'sub', 0 ) ): if ( sp_array_value( $player_performance, 'status' ) != 'sub' || sp_array_value( $player_performance, 'sub', 0 ) ):
$totals[ $player_id ]['eventsplayed'] ++; $totals[ $player_id ]['eventsplayed'] ++;
$totals[ $player_id ]['eventminutes'] += $minutes;
// Adjust for substitution time // Initialize played minutes
$played_minutes = $minutes;
// Adjust for sendoffs and substitution time
if ( sp_array_value( $player_performance, 'status' ) === 'sub' ): if ( sp_array_value( $player_performance, 'status' ) === 'sub' ):
$totals[ $player_id ]['eventminutes'] -= sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $player_id ), 'sub' ), 0, 0 );
// Substituted for another player
$timeline_performance = sp_array_value( sp_array_value( $timeline, $team_id, array() ), $player_id, array() ); $timeline_performance = sp_array_value( sp_array_value( $timeline, $team_id, array() ), $player_id, array() );
if ( empty( $timeline_performance ) ) continue; if ( empty( $timeline_performance ) ) continue;
foreach ( $sendoffs as $sendoff_key ): foreach ( $sendoffs as $sendoff_key ):
@@ -420,9 +422,17 @@ class SP_Player_List extends SP_Custom_Post {
$sendoff_times = array_filter( $sendoff_times ); $sendoff_times = array_filter( $sendoff_times );
$sendoff_time = end( $sendoff_times ); $sendoff_time = end( $sendoff_times );
if ( ! $sendoff_time ) $sendoff_time = 0; if ( ! $sendoff_time ) $sendoff_time = 0;
$totals[ $player_id ]['eventminutes'] += $sendoff_time - $minutes;
// Count minutes until being sent off
$played_minutes = $sendoff_time;
endforeach; endforeach;
// Subtract minutes prior to substitution
$substitution_time = sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $player_id ), 'sub' ), 0, 0 );
$played_minutes -= $substitution_time;
else: else:
// Starting lineup with possible substitution
$subbed_out = false; $subbed_out = false;
foreach ( $timeline as $timeline_team => $timeline_players ): foreach ( $timeline as $timeline_team => $timeline_players ):
if ( ! is_array( $timeline_players ) ) continue; if ( ! is_array( $timeline_players ) ) continue;
@@ -430,26 +440,36 @@ class SP_Player_List extends SP_Custom_Post {
if ( 'sub' === sp_array_value( sp_array_value( $players, $timeline_player, array() ), 'status' ) && $player_id === (int) sp_array_value( sp_array_value( $players, $timeline_player, array() ), 'sub', 0 ) ): if ( 'sub' === sp_array_value( sp_array_value( $players, $timeline_player, array() ), 'status' ) && $player_id === (int) sp_array_value( sp_array_value( $players, $timeline_player, array() ), 'sub', 0 ) ):
$substitution_time = sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $timeline_player ), 'sub' ), 0, 0 ); $substitution_time = sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $timeline_player ), 'sub' ), 0, 0 );
if ( $substitution_time ): if ( $substitution_time ):
$totals[ $player_id ]['eventminutes'] += $substitution_time - $minutes;
// Count minutes until substitution
$played_minutes = $substitution_time;
$subbed_out = true; $subbed_out = true;
endif; endif;
endif; endif;
endforeach; endforeach;
// No need to check for sendoffs if subbed out
if ( $subbed_out ) continue; if ( $subbed_out ) continue;
// Check for sendoffs
$timeline_performance = sp_array_value( $timeline_players, $player_id, array() ); $timeline_performance = sp_array_value( $timeline_players, $player_id, array() );
if ( empty( $timeline_performance ) ) continue; if ( empty( $timeline_performance ) ) continue;
foreach ( $sendoffs as $sendoff_key ): foreach ( $sendoffs as $sendoff_key ):
if ( ! array_key_exists( $sendoff_key, $timeline_performance ) ) continue; if ( ! array_key_exists( $sendoff_key, $timeline_performance ) ) continue;
if ( ! sp_array_value( $player_performance, $sendoff_key, 0 ) ) continue;
$sendoff_times = sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $player_id ), $sendoff_key ); $sendoff_times = sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $player_id ), $sendoff_key );
$sendoff_times = array_filter( $sendoff_times ); $sendoff_times = array_filter( $sendoff_times );
$sendoff_time = end( $sendoff_times ); $sendoff_time = end( $sendoff_times );
if ( ! $sendoff_time ) $sendoff_time = 0; if ( false === $sendoff_time ) continue;
$totals[ $player_id ]['eventminutes'] += $sendoff_time - $minutes;
// Count minutes until being sent off
$played_minutes = $sendoff_time;
endforeach; endforeach;
endforeach; endforeach;
endif; endif;
$totals[ $player_id ]['eventminutes'] += max( 0, $played_minutes );
if ( sp_array_value( $player_performance, 'status' ) == 'lineup' ): if ( sp_array_value( $player_performance, 'status' ) == 'lineup' ):
$totals[ $player_id ]['eventsstarted'] ++; $totals[ $player_id ]['eventsstarted'] ++;
elseif ( sp_array_value( $player_performance, 'status' ) == 'sub' && sp_array_value( $player_performance, 'sub', 0 ) ): elseif ( sp_array_value( $player_performance, 'status' ) == 'sub' && sp_array_value( $player_performance, 'sub', 0 ) ):

View File

@@ -359,12 +359,12 @@ class SP_Player extends SP_Custom_Post {
// Continue with incrementing values if active in event // Continue with incrementing values if active in event
if ( sp_array_value( $player_performance, 'status' ) != 'sub' || sp_array_value( $player_performance, 'sub', 0 ) ): if ( sp_array_value( $player_performance, 'status' ) != 'sub' || sp_array_value( $player_performance, 'sub', 0 ) ):
$totals['eventsplayed'] ++; $totals['eventsplayed'] ++;
$totals['eventminutes'] += $minutes; $played_minutes = $minutes;
// Adjust for substitution time // Adjust for substitution time
if ( sp_array_value( $player_performance, 'status' ) === 'sub' ): if ( sp_array_value( $player_performance, 'status' ) === 'sub' ):
$totals['eventminutes'] -= sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $this->ID ), 'sub' ), 0, 0 );
// Substituted for another player
$timeline_performance = sp_array_value( sp_array_value( $timeline, $team_id, array() ), $this->ID, array() ); $timeline_performance = sp_array_value( sp_array_value( $timeline, $team_id, array() ), $this->ID, array() );
if ( empty( $timeline_performance ) ) continue; if ( empty( $timeline_performance ) ) continue;
foreach ( $sendoffs as $sendoff_key ): foreach ( $sendoffs as $sendoff_key ):
@@ -373,9 +373,17 @@ class SP_Player extends SP_Custom_Post {
$sendoff_times = array_filter( $sendoff_times ); $sendoff_times = array_filter( $sendoff_times );
$sendoff_time = end( $sendoff_times ); $sendoff_time = end( $sendoff_times );
if ( ! $sendoff_time ) $sendoff_time = 0; if ( ! $sendoff_time ) $sendoff_time = 0;
$totals['eventminutes'] += $sendoff_time - $minutes;
// Count minutes until being sent off
$played_minutes = $sendoff_time;
endforeach; endforeach;
// Subtract minutes prior to substitution
$substitution_time = sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $this->ID ), 'sub' ), 0, 0 );
$played_minutes -= $substitution_time;
else: else:
// Starting lineup with possible substitution
$subbed_out = false; $subbed_out = false;
foreach ( $timeline as $timeline_team => $timeline_players ): foreach ( $timeline as $timeline_team => $timeline_players ):
if ( ! is_array( $timeline_players ) ) continue; if ( ! is_array( $timeline_players ) ) continue;
@@ -383,13 +391,18 @@ class SP_Player extends SP_Custom_Post {
if ( 'sub' === sp_array_value( sp_array_value( $players, $timeline_player, array() ), 'status' ) && $this->ID === (int) sp_array_value( sp_array_value( $players, $timeline_player, array() ), 'sub', 0 ) ): if ( 'sub' === sp_array_value( sp_array_value( $players, $timeline_player, array() ), 'status' ) && $this->ID === (int) sp_array_value( sp_array_value( $players, $timeline_player, array() ), 'sub', 0 ) ):
$substitution_time = sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $timeline_player ), 'sub' ), 0, 0 ); $substitution_time = sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $timeline_player ), 'sub' ), 0, 0 );
if ( $substitution_time ): if ( $substitution_time ):
$totals['eventminutes'] += $substitution_time - $minutes;
// Count minutes until substitution
$played_minutes = $substitution_time;
$subbed_out = true; $subbed_out = true;
endif; endif;
endif; endif;
endforeach; endforeach;
// No need to check for sendoffs if subbed out
if ( $subbed_out ) continue; if ( $subbed_out ) continue;
// Check for sendoffs
$timeline_performance = sp_array_value( $timeline_players, $this->ID, array() ); $timeline_performance = sp_array_value( $timeline_players, $this->ID, array() );
if ( empty( $timeline_performance ) ) continue; if ( empty( $timeline_performance ) ) continue;
foreach ( $sendoffs as $sendoff_key ): foreach ( $sendoffs as $sendoff_key ):
@@ -397,12 +410,16 @@ class SP_Player extends SP_Custom_Post {
$sendoff_times = sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $this->ID ), $sendoff_key ); $sendoff_times = sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $this->ID ), $sendoff_key );
$sendoff_times = array_filter( $sendoff_times ); $sendoff_times = array_filter( $sendoff_times );
$sendoff_time = end( $sendoff_times ); $sendoff_time = end( $sendoff_times );
if ( ! $sendoff_time ) $sendoff_time = 0; if ( false === $sendoff_time ) continue;
$totals['eventminutes'] += $sendoff_time - $minutes;
// Count minutes until being sent off
$played_minutes = $sendoff_time;
endforeach; endforeach;
endforeach; endforeach;
endif; endif;
$totals['eventminutes'] += max( 0, $played_minutes );
if ( sp_array_value( $player_performance, 'status' ) == 'lineup' ): if ( sp_array_value( $player_performance, 'status' ) == 'lineup' ):
$totals['eventsstarted'] ++; $totals['eventsstarted'] ++;
elseif ( sp_array_value( $player_performance, 'status' ) == 'sub' && sp_array_value( $player_performance, 'sub', 0 ) ): elseif ( sp_array_value( $player_performance, 'status' ) == 'sub' && sp_array_value( $player_performance, 'sub', 0 ) ):
@@ -686,6 +703,7 @@ class SP_Player extends SP_Custom_Post {
// Get totals as entered directly and filter out the empty values // Get totals as entered directly and filter out the empty values
$total_data = sp_array_value( $data, 0, array() ); $total_data = sp_array_value( $data, 0, array() );
$total_data = array_filter( $total_data, 'sp_filter_non_empty' );
// Get totals of all seasons as entered manually // Get totals of all seasons as entered manually
$totals = array(); $totals = array();