Add event results to equation builder

This commit is contained in:
Brian Miyaji
2015-09-17 12:36:01 +10:00
parent 922866f521
commit ecbac64351
3 changed files with 148 additions and 99 deletions

View File

@@ -23,7 +23,7 @@ class SP_Meta_Box_Statistic_Equation extends SP_Meta_Box_Equation {
*/
public static function output( $post ) {
$equation = get_post_meta( $post->ID, 'sp_equation', true );
$groups = array( 'player_event', 'outcome', 'performance', 'metric' );
$groups = array( 'player_event', 'outcome', 'result', 'performance', 'metric' );
self::builder( $post->post_title, $equation, $groups );
}
}

View File

@@ -51,6 +51,9 @@ class SP_Player_List extends SP_Custom_Post {
// Get labels from outcome variables
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
// Get labels from result variables
$result_labels = (array)sp_get_var_labels( 'sp_result' );
// Get players automatically if set to auto
if ( 'auto' == $select ) {
$player_ids = array();
@@ -148,13 +151,17 @@ class SP_Player_List extends SP_Custom_Post {
foreach ( $performance_labels as $key => $value ):
$totals[ $player_id ][ $key ] = 0;
$totals[ $player_id ][ $key ] = 0;
endforeach;
foreach ( $outcome_labels as $key => $value ):
$totals[ $player_id ][ $key ] = 0;
endforeach;
foreach ( $result_labels as $key => $value ):
$totals[ $player_id ][ $key . 'for' ] = 0;
$totals[ $player_id ][ $key . 'against' ] = 0;
endforeach;
// Get metrics
$metrics = (array) get_post_meta( $player_id, 'sp_metrics', true );
foreach ( $metrics as $key => $value ):
@@ -274,9 +281,11 @@ class SP_Player_List extends SP_Custom_Post {
endforeach;
$team_results = sp_array_value( $results, $team_id, array() );
unset( $results[ $team_id ] );
// Find the outcome
if ( array_key_exists( 'outcome', $team_results ) ):
// Loop through home team
foreach ( $team_results as $result_slug => $team_result ):
if ( 'outcome' == $result_slug ):
// Increment events attended
$totals[ $player_id ]['eventsattended'] ++;
@@ -292,7 +301,7 @@ class SP_Player_List extends SP_Custom_Post {
$totals[ $player_id ]['eventssubbed'] ++;
endif;
$value = $team_results['outcome'];
$value = $team_result;
// Convert to array
if ( ! is_array( $value ) ):
@@ -328,6 +337,23 @@ class SP_Player_List extends SP_Custom_Post {
endif;
endforeach;
endif;
else:
$value = sp_array_value( $totals[ $player_id ], $result_slug . 'for', 0 );
$value += $team_result;
$totals[ $player_id ][ $result_slug . 'for' ] = $value;
endif;
endforeach;
// Loop through away teams
if ( sizeof( $results ) ):
foreach ( $results as $team_results ):
unset( $team_results['outcome'] );
foreach ( $team_results as $result_slug => $team_result ):
$value = sp_array_value( $totals[ $player_id ], $result_slug . 'against', 0 );
$value += $team_result;
$totals[ $player_id ][ $result_slug . 'against' ] = $value;
endforeach;
endforeach;
endif;
endif;
endforeach; endif;
@@ -347,7 +373,9 @@ class SP_Player_List extends SP_Custom_Post {
if ( $outcomes ):
$outcome = reset( $outcomes );
$totals[ $player_id ]['streak'] = $outcome->post_title . $streak['count'];
$abbreviation = sp_get_abbreviation( $outcome->ID );
if ( empty( $abbreviation ) ) $abbreviation = strtoupper( substr( $outcome->post_title, 0, 1 ) );
$totals[ $player_id ]['streak'] = $abbreviation . $streak['count'];
else:
$totals[ $player_id ]['streak'] = null;
endif;

View File

@@ -244,9 +244,11 @@ class SP_Player extends SP_Custom_Post {
endforeach;
$team_results = sp_array_value( $results, $team_id, array() );
unset( $results[ $team_id ] );
// Find the outcome
if ( array_key_exists( 'outcome', $team_results ) ):
// Loop through home team
foreach ( $team_results as $result_slug => $team_result ):
if ( 'outcome' == $result_slug ):
// Increment events attended
$totals['eventsattended'] ++;
@@ -262,7 +264,7 @@ class SP_Player extends SP_Custom_Post {
$totals['eventssubbed'] ++;
endif;
$value = $team_results['outcome'];
$value = $team_result;
// Convert to array
if ( ! is_array( $value ) ):
@@ -297,6 +299,23 @@ class SP_Player extends SP_Custom_Post {
endif;
endforeach;
endif;
else:
$value = sp_array_value( $totals, $result_slug . 'for', 0 );
$value += $team_result;
$totals[ $result_slug . 'for' ] = $value;
endif;
endforeach;
// Loop through away teams
if ( sizeof( $results ) ):
foreach ( $results as $team_results ):
unset( $team_results['outcome'] );
foreach ( $team_results as $result_slug => $team_result ):
$val = sp_array_value( $totals, $result_slug . 'against', 0 );
$val += $team_result;
$totals[ $result_slug . 'against' ] = $val;
endforeach;
endforeach;
endif;
endif;
endforeach;
@@ -313,7 +332,9 @@ class SP_Player extends SP_Custom_Post {
if ( $outcomes ):
$outcome = reset( $outcomes );
$totals['streak'] = $outcome->post_title . $streak['count'];
$abbreviation = sp_get_abbreviation( $outcome->ID );
if ( empty( $abbreviation ) ) $abbreviation = strtoupper( substr( $outcome->post_title, 0, 1 ) );
$totals['streak'] = $abbreviation . $streak['count'];
endif;
// Add last counters to totals