plugin_name . '-metrics'; $aicfab_screen_url = admin_url( 'admin.php?page=' . $aicfab_page ); $aicfab_available = AI_Chat_Bedrock_Metrics::available( 'analytics' ); $aicfab_dimensions = AI_Chat_Bedrock_Metrics::dimensions(); // A read-only view: the query in the address only chooses which figure is shown. $aicfab_args = AI_Chat_Bedrock_Admin::metrics_query_args( wp_unslash( $_GET ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $aicfab_asked = isset( $_GET['aicfab_asked'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $aicfab_ask_error = isset( $_GET['aicfab_ask_error'] ) ? sanitize_key( wp_unslash( $_GET['aicfab_ask_error'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $aicfab_dropped = ''; // The form lists every dimension; one the chosen metric lacks is dropped here rather than refused. if ( isset( $aicfab_args['metric'], $aicfab_args['dimension'], $aicfab_available[ $aicfab_args['metric'] ] ) && 'none' !== $aicfab_args['dimension'] && ! in_array( $aicfab_args['dimension'], $aicfab_available[ $aicfab_args['metric'] ]['dimensions'], true ) ) { $aicfab_dropped = isset( $aicfab_dimensions[ $aicfab_args['dimension'] ] ) ? $aicfab_dimensions[ $aicfab_args['dimension'] ] : $aicfab_args['dimension']; unset( $aicfab_args['dimension'] ); } $aicfab_result = null; if ( ! empty( $aicfab_args['metric'] ) ) { $aicfab_result = AI_Chat_Bedrock_Metrics::query( $aicfab_args, 'analytics' ); } $aicfab_query = is_array( $aicfab_result ) ? $aicfab_result['query'] : array_merge( array( 'metric' => '', 'period' => 'last_30_days', 'after' => '', 'before' => '', 'compare' => 'previous_period', 'interval' => 'none', 'dimension' => 'none', 'limit' => AI_Chat_Bedrock_Metrics::DEFAULT_LIMIT, ), $aicfab_args ); $aicfab_ask_errors = array( 'aicfab_not_a_metric' => __( 'That question is not one these metrics can answer. Ask about one of the figures listed on this screen.', 'ai-chat-for-amazon-bedrock' ), 'aicfab_bad_plan' => __( 'The question could not be turned into a query. Please rephrase it.', 'ai-chat-for-amazon-bedrock' ), 'aicfab_bad_value' => __( 'The question could not be turned into a query. Please rephrase it.', 'ai-chat-for-amazon-bedrock' ), 'aicfab_bad_dates' => __( 'The dates in the question could not be used. A period can cover at most 366 days and cannot start in the future.', 'ai-chat-for-amazon-bedrock' ), 'aicfab_missing_question' => __( 'Type a question first.', 'ai-chat-for-amazon-bedrock' ), 'aicfab_rate_limited' => __( 'Too many requests. Please wait a moment.', 'ai-chat-for-amazon-bedrock' ), 'aicfab_forbidden' => __( 'You are not allowed to see this metric.', 'ai-chat-for-amazon-bedrock' ), ); /** * One figure, its earlier period and the change, as a card. * * @param array $result Result from query(). * @param string $link Address of the detail view, or empty. */ $aicfab_card = static function ( $result, $link = '' ) { $currency = isset( $result['currency'] ) ? $result['currency'] : ''; echo '
'; echo '

'; if ( '' !== $link ) { echo '' . esc_html( $result['label'] ) . ''; } else { echo esc_html( $result['label'] ); } echo '

'; echo '

' . esc_html( AI_Chat_Bedrock_Metrics::format_value( $result['value'], $result['unit'], $currency ) ) . '

'; if ( $result['hidden'] ) { echo '

' . esc_html__( 'Withheld, so that no one can be picked out.', 'ai-chat-for-amazon-bedrock' ) . '

'; } if ( isset( $result['compare'] ) ) { $compare = $result['compare']; echo '

'; if ( null !== $compare['change_percent'] ) { $class = $compare['change_percent'] > 0 ? 'up' : ( $compare['change_percent'] < 0 ? 'down' : 'flat' ); $arrow = 'up' === $class ? '▲' : ( 'down' === $class ? '▼' : '' ); echo ' '; echo esc_html( ( $compare['change_percent'] > 0 ? '+' : '' ) . number_format_i18n( $compare['change_percent'], 1 ) . '%' ) . ' '; } elseif ( null !== $compare['change'] && 0 !== $compare['change'] && 0.0 !== $compare['change'] ) { echo esc_html( ( $compare['change'] > 0 ? '+' : '' ) . AI_Chat_Bedrock_Metrics::format_value( $compare['change'], $result['unit'], $currency ) ) . ' '; } printf( /* translators: 1: earlier value, 2: first day, 3: last day. */ esc_html__( 'against %1$s (%2$s – %3$s)', 'ai-chat-for-amazon-bedrock' ), esc_html( AI_Chat_Bedrock_Metrics::format_value( $compare['value'], $result['unit'], $currency ) ), esc_html( $compare['after'] ), esc_html( $compare['before'] ) ); echo '

'; } echo '
'; }; ?>

getName() ) ); ?>

' . esc_html( AI_Chat_Bedrock_Metrics::summarize( $aicfab_result['query'] ) ) . '' ); ?>

$aicfab_item ) : $aicfab_x = $aicfab_index * $aicfab_bar; $aicfab_text = $aicfab_item['start'] . ( $aicfab_item['start'] !== $aicfab_item['end'] ? ' – ' . $aicfab_item['end'] : '' ) . ': '; $aicfab_text .= $aicfab_item['hidden'] ? __( 'withheld', 'ai-chat-for-amazon-bedrock' ) : AI_Chat_Bedrock_Metrics::format_value( $aicfab_item['value'], $aicfab_result['unit'], $aicfab_currency ); if ( $aicfab_item['hidden'] ) : ?> 0 && null !== $aicfab_item['value'] ? max( 1, ( $aicfab_item['value'] / $aicfab_max ) * ( $aicfab_height - 4 ) ) : 1; ?>

$aicfab_id, 'period' => 'last_30_days', 'compare' => 'previous_period', ), 'analytics' ); if ( is_wp_error( $aicfab_overview ) ) { $aicfab_skipped[ $aicfab_overview->get_error_message() ] = true; continue; } $aicfab_card( $aicfab_overview, add_query_arg( array( 'metric' => $aicfab_id, 'period' => 'last_30_days', 'compare' => 'previous_period', 'interval' => 'day', ), $aicfab_screen_url ) ); } ?>