Add equation-based box score performance values

This commit is contained in:
Brian Miyaji
2016-11-01 13:42:31 +11:00
parent 1d5f3c739a
commit dabedf7d41
13 changed files with 143 additions and 13 deletions

View File

@@ -78,7 +78,7 @@ if ( ! isset( $class ) ) $class = null;
$format = sp_array_value( $formats, $key, 'number' );
$placeholder = sp_get_format_placeholder( $format );
$value = '—';
$value = '-';
if ( $key == 'position' ):
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$positions = array();

View File

@@ -121,7 +121,7 @@ if ( ! isset( $subs ) ) $subs = array();
$format = sp_array_value( $formats, $key, 'number' );
$placeholder = sp_get_format_placeholder( $format );
$value = '—';
$value = '-';
if ( $key == 'position' ):
$positions = array();
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
@@ -151,7 +151,7 @@ if ( ! isset( $subs ) ) $subs = array();
$totals[ $key ] = $placeholder;
endif;
if ( 'text' !== $format ) {
if ( 'number' === $format ) {
$totals[ $key ] += $value;
}
@@ -174,6 +174,22 @@ if ( ! isset( $subs ) ) $subs = array();
$i++;
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>
<?php endif; ?>

View File

@@ -77,16 +77,30 @@ if ( is_array( $teams ) ):
$columns = get_posts( $args );
// Get formats
// Get formats and equations
$formats = array();
$equations = array();
// Add to formats
// Add to formats and equations
foreach ( $columns as $column ) {
$format = get_post_meta( $column->ID, 'sp_format', true );
if ( '' === $format ) {
$format = 'number';
}
$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 ) {
@@ -109,6 +123,7 @@ if ( is_array( $teams ) ):
'caption' => __( 'Box Score', 'sportspress' ),
'labels' => $labels,
'formats' => $formats,
'equations' => $equations,
'mode' => $mode,
'data' => $data,
'event' => $event,
@@ -219,6 +234,7 @@ if ( is_array( $teams ) ):
'caption' => 0 == $s && $team_id ? sp_get_team_name( $team_id, $abbreviate_teams ) : null,
'labels' => $labels[ $section_id ],
'formats' => $formats,
'equations' => $equations,
'mode' => $mode,
'data' => $data[ $section_id ],
'event' => $event,
@@ -255,6 +271,7 @@ if ( is_array( $teams ) ):
'caption' => $team_id ? sp_get_team_name( $team_id, $abbreviate_teams ) : null,
'labels' => $labels,
'formats' => $formats,
'equations' => $equations,
'mode' => $mode,
'data' => $data,
'event' => $event,