0.0; $budget_pct = ( $budget_set && $monthly_budget > 0 ) ? min( 100, round( ( $this_month_cost / $monthly_budget ) * 100, 1 ) ) : 0.0; $over_budget = $budget_set && $this_month_cost >= $monthly_budget; // ── Index stats ──────────────────────────────────────────────────────────── $index_status = (array) get_option( 'attendant_index_status', array( 'total_chunks' => 0, 'pending' => 0, 'is_running' => false, 'last_indexed' => null, ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $total_chunks = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$wpdb->prefix}attendant_chunks`" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $failed_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$wpdb->prefix}attendant_queue` WHERE status = 'failed'" ); $last_indexed = $index_status['last_indexed'] ?? null; $last_indexed_human = $last_indexed ? human_time_diff( (int) strtotime( $last_indexed ), time() ) : null; // ── Conversation log stats (only when logging is enabled) ────────────────── $logging_enabled = (bool) Attendant_Plugin::get_setting( 'logging_enabled', false ); $log_stats = array( 'sessions_this_month' => 0, 'messages_this_month' => 0, 'avg_response_ms' => 0, 'total_sessions_ever' => 0, ); if ( $logging_enabled ) { $month_start = gmdate( 'Y-m-01 00:00:00' ); $log_table = $wpdb->prefix . 'attendant_logs'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $log_stats['sessions_this_month'] = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT session_id) FROM `{$log_table}` WHERE created_at >= %s", $month_start ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $log_stats['messages_this_month'] = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM `{$log_table}` WHERE role = 'user' AND created_at >= %s", $month_start ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $log_stats['avg_response_ms'] = (int) $wpdb->get_var( $wpdb->prepare( "SELECT AVG(response_ms) FROM `{$log_table}` WHERE response_ms > 0 AND created_at >= %s", $month_start ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $log_stats['total_sessions_ever'] = (int) $wpdb->get_var( "SELECT COUNT(DISTINCT session_id) FROM `{$log_table}`" ); } ?>

$
0 ) : ?>

$cost ) : $cost = (float) $cost; $bar_pct = ( $max_cost > 0 ) ? round( ( $cost / $max_cost ) * 100, 1 ) : 0; $is_current = ( $month_key === $current_month ); // Parse YYYY-MM into a localised month name. $ts = mktime( 0, 0, 0, (int) substr( $month_key, 5, 2 ), 1, (int) substr( $month_key, 0, 4 ) ); $month_label = date_i18n( 'F Y', $ts ); ?> >
$
$
0 ) : ?>

0 ) : ?>

' . esc_html__( 'Settings → Privacy', 'attendant' ) . '' ); ?>

[attendant]