Calculate equation-based box score totals
This commit is contained in:
@@ -136,6 +136,8 @@ class SP_Event extends SP_Custom_Post{
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
foreach( $data as $player_id => $player_performance ):
|
foreach( $data as $player_id => $player_performance ):
|
||||||
|
if ( ! $player_id ) continue;
|
||||||
|
|
||||||
foreach( $labels as $key => $label ):
|
foreach( $labels as $key => $label ):
|
||||||
if ( array_key_exists( $key, $totals ) ):
|
if ( array_key_exists( $key, $totals ) ):
|
||||||
$totals[ $key ] += sp_array_value( $player_performance, $key, 0 );
|
$totals[ $key ] += sp_array_value( $player_performance, $key, 0 );
|
||||||
@@ -155,6 +157,7 @@ class SP_Event extends SP_Custom_Post{
|
|||||||
$totals[ $key ] = $manual_total;
|
$totals[ $key ] = $manual_total;
|
||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
$performance[ $team_id ][0] = array_merge( $totals, sp_array_value( sp_array_value( $performance, $team_id, array() ), 0, array() ) );
|
||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
@@ -184,8 +187,6 @@ class SP_Event extends SP_Custom_Post{
|
|||||||
if ( sizeof( $equations ) ):
|
if ( sizeof( $equations ) ):
|
||||||
foreach ( $performance as $team => $players ):
|
foreach ( $performance as $team => $players ):
|
||||||
foreach ( $players as $player => $player_performance ):
|
foreach ( $players as $player => $player_performance ):
|
||||||
if ( ! $player ) continue;
|
|
||||||
|
|
||||||
// Prepare existing values for equation calculation
|
// Prepare existing values for equation calculation
|
||||||
$vars = $player_performance;
|
$vars = $player_performance;
|
||||||
foreach ( $vars as $key => $var ):
|
foreach ( $vars as $key => $var ):
|
||||||
|
|||||||
@@ -174,22 +174,6 @@ if ( ! isset( $subs ) ) $subs = array();
|
|||||||
$i++;
|
$i++;
|
||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
if ( sizeof( $equations ) ):
|
|
||||||
|
|
||||||
// Prepare total values for equation calculation
|
|
||||||
$vars = $totals;
|
|
||||||
foreach ( $vars as $key => $var ):
|
|
||||||
if ( empty( $var ) ) $vars[ $key ] = 0;
|
|
||||||
endforeach;
|
|
||||||
$vars = array_merge( $vars, array( 'eventsplayed' => 1 ) );
|
|
||||||
|
|
||||||
// Calculate equation-based totals
|
|
||||||
foreach ( $equations as $key => $equation ):
|
|
||||||
$totals[ $key ] = sp_solve( $equation['equation'], $vars, $equation['precision'] );
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
endif;
|
|
||||||
?>
|
?>
|
||||||
</tbody>
|
</tbody>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
@@ -77,30 +77,16 @@ if ( is_array( $teams ) ):
|
|||||||
|
|
||||||
$columns = get_posts( $args );
|
$columns = get_posts( $args );
|
||||||
|
|
||||||
// Get formats and equations
|
// Get formats
|
||||||
$formats = array();
|
$formats = array();
|
||||||
$equations = array();
|
|
||||||
|
|
||||||
// Add to formats and equations
|
// Add to formats
|
||||||
foreach ( $columns as $column ) {
|
foreach ( $columns as $column ) {
|
||||||
$format = get_post_meta( $column->ID, 'sp_format', true );
|
$format = get_post_meta( $column->ID, 'sp_format', true );
|
||||||
if ( '' === $format ) {
|
if ( '' === $format ) {
|
||||||
$format = 'number';
|
$format = 'number';
|
||||||
}
|
}
|
||||||
$formats[ $column->post_name ] = $format;
|
$formats[ $column->post_name ] = $format;
|
||||||
|
|
||||||
if ( 'equation' === $format ) {
|
|
||||||
$equation = get_post_meta( $column->ID, 'sp_equation', true );
|
|
||||||
$precision = get_post_meta( $column->ID, 'sp_precision', true );
|
|
||||||
|
|
||||||
if ( empty( $equation ) ) $equation = 0;
|
|
||||||
if ( empty( $precision ) ) $precision = 0;
|
|
||||||
|
|
||||||
$equations[ $column->post_name ] = array(
|
|
||||||
'equation' => $equation,
|
|
||||||
'precision' => $precision,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $is_individual ) {
|
if ( $is_individual ) {
|
||||||
@@ -123,7 +109,6 @@ if ( is_array( $teams ) ):
|
|||||||
'caption' => __( 'Box Score', 'sportspress' ),
|
'caption' => __( 'Box Score', 'sportspress' ),
|
||||||
'labels' => $labels,
|
'labels' => $labels,
|
||||||
'formats' => $formats,
|
'formats' => $formats,
|
||||||
'equations' => $equations,
|
|
||||||
'mode' => $mode,
|
'mode' => $mode,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'event' => $event,
|
'event' => $event,
|
||||||
@@ -234,7 +219,6 @@ if ( is_array( $teams ) ):
|
|||||||
'caption' => 0 == $s && $team_id ? sp_get_team_name( $team_id, $abbreviate_teams ) : null,
|
'caption' => 0 == $s && $team_id ? sp_get_team_name( $team_id, $abbreviate_teams ) : null,
|
||||||
'labels' => $labels[ $section_id ],
|
'labels' => $labels[ $section_id ],
|
||||||
'formats' => $formats,
|
'formats' => $formats,
|
||||||
'equations' => $equations,
|
|
||||||
'mode' => $mode,
|
'mode' => $mode,
|
||||||
'data' => $data[ $section_id ],
|
'data' => $data[ $section_id ],
|
||||||
'event' => $event,
|
'event' => $event,
|
||||||
@@ -271,7 +255,6 @@ if ( is_array( $teams ) ):
|
|||||||
'caption' => $team_id ? sp_get_team_name( $team_id, $abbreviate_teams ) : null,
|
'caption' => $team_id ? sp_get_team_name( $team_id, $abbreviate_teams ) : null,
|
||||||
'labels' => $labels,
|
'labels' => $labels,
|
||||||
'formats' => $formats,
|
'formats' => $formats,
|
||||||
'equations' => $equations,
|
|
||||||
'mode' => $mode,
|
'mode' => $mode,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'event' => $event,
|
'event' => $event,
|
||||||
|
|||||||
Reference in New Issue
Block a user