make this code analysis for ABB robot program more useful and insightful import re from collections import defaultdict import matplotlib.pyplot as plt import seaborn as sns import numpy as np from scipy.spatial.distance import euclidean  def analyze_robot_program(program_text):     # Define regex patterns for parsing     robtarget_pattern = re.compile(r'LOCAL CONST robtarget (\w+):=\[\[(.*?)\],\[(.*?)\],\[(.*?)\],\[(.*?)\]\];')     speeddata_pattern = re.compile(r'CONST speeddata (\w+):=\[(.*?)\];')     movement_pattern = re.compile(r'(Move[JL]) (\w+),(\w+),(\w+),(\w+)(?:\\Wobj:=\w+)?;')     dispense_pattern = re.compile(r'DispL\\(On|Off),(\w+),(\w+),(\w+),(\w+)(?:\\Wobj:=\w+)?;')      # Initialize dictionaries to hold parsed data     robtargets = {}     speeddata = {}     movements = []     dispenses = []      # Parse data from program text     for match in robtarget_pattern.findall(program_text):         name, translation, orientation, config, ext_axes = match         robtargets[name] = {             'translation': list(map(float, translation.split(','))),             'orientation': list(map(float, orientation.split(','))),             'config': list(map(float, config.split(','))),             'ext_axes': list(map(float, ext_axes.split(',')))         }      for match in speeddata_pattern.findall(program_text):         name, values = match         speeddata[name] = list(map(float, values.split(',')))      for match in movement_pattern.findall(program_text):         move_type, target, speed, zone, tool = match         movements.append({             'move_type': move_type,             'target': target,             'speed': speed,             'zone': zone,             'tool': tool         })      for match in dispense_pattern.findall(program_text):         action, target, speed, zone, tool = match         dispenses.append({             'action': action,             'target': target,             'speed': speed,             'zone': zone,             'tool': tool         })      # Analyze movements     speed_usage = defaultdict(int)     move_types = defaultdict(int)     movement_durations = []     positions = []      for move in movements:         speed_usage[move['speed']] += 1         move_types[move['move_type']] += 1          # Estimate duration based on speed and distance (assuming constant speed)         if move['move_type'] == 'MoveJ' or move['move_type'] == 'MoveL':             target_pos = robtargets[move['target']]['translation']             positions.append(target_pos)             if len(positions) > 1:                 distance = euclidean(positions[-2], positions[-1])                 speed_value = speeddata.get(move['speed'], [0])[0]  # Handle missing speed values                 if speed_value != 0:                     duration = distance / speed_value                     movement_durations.append(duration)      # Analyze dispenses     dispense_actions = defaultdict(int)     for dispense in dispenses:         dispense_actions[dispense['action']] += 1      # Prepare data for plots     speeds = list(speed_usage.keys())     counts = list(speed_usage.values())     speed_values = [speeddata.get(speed, [0])[0] for speed in speeds]  # Handle missing speed values      # Set up the plotting style     sns.set(style="whitegrid")      # Plot Speed Usage     plt.figure(figsize=(10, 6))     sns.barplot(x=speeds, y=counts, hue=speeds, palette="muted", legend=False)     plt.title("Speed Usage in Robot Movements")     plt.xlabel("Speed Type")     plt.ylabel("Usage Count")     plt.show()      # Plot Move Types     plt.figure(figsize=(10, 6))     sns.barplot(x=list(move_types.keys()), y=list(move_types.values()), hue=list(move_types.keys()), palette="muted", legend=False)     plt.title("Move Types in Robot Movements")     plt.xlabel("Move Type")     plt.ylabel("Count")     plt.show()      # Plot Movement Durations     plt.figure(figsize=(10, 6))     sns.histplot(movement_durations, kde=True, bins=20, color="skyblue")     plt.title("Distribution of Movement Durations")     plt.xlabel("Duration (seconds)")     plt.ylabel("Frequency")     plt.show()      # Plot Positional Analysis     positions_array = np.array(positions)     fig = plt.figure(figsize=(10, 6))     ax = fig.add_subplot(111, projection='3d')     ax.scatter(positions_array[0, 0], positions_array[0, 1], positions_array[0, 2], c='g', marker='o', label='Start Position')     ax.scatter(positions_array[1:, 0], positions_array[1:, 1], positions_array[1:, 2], c='r', marker='o', label='Target Positions')     ax.set_title("3D Scatter Plot of Robot Positions")     ax.set_xlabel("X Position")     ax.set_ylabel("Y Position")     ax.set_zlabel("Z Position")     ax.legend()     plt.show()      # Plot Dispense Actions     plt.figure(figsize=(10, 6))     sns.barplot(x=list(dispense_actions.keys()), y=list(dispense_actions.values()), hue=list(dispense_actions.keys()), palette="muted", legend=False)     plt.title("Dispense Actions in Robot Movements")     plt.xlabel("Dispense Action")     plt.ylabel("Count")     plt.show()      # Perform statistical analysis     counts_array = np.array(counts)     weighted_speeds = np.array([speed * count for speed, count in zip(speed_values, counts)])     average_speed = np.sum(weighted_speeds) / np.sum(counts_array)     std_dev_speed = np.sqrt(np.sum((weighted_speeds - average_speed) ** 2) / np.sum(counts_array))      # Prepare data for statistical analysis plot     data = {'Speed Type': speeds, 'Speed Value': speed_values, 'Count': counts}      # Plot Statistical Analysis     plt.figure(figsize=(10, 6))     sns.barplot(x='Speed Type', y='Speed Value', data=data, hue='Speed Type', palette="muted", legend=False)     plt.title("Speed Values Distribution")     plt.xlabel("Speed Type")     plt.ylabel("Speed Value")     plt.axhline(average_speed, color='r', linestyle='--', label=f'Average Speed: {average_speed:.2f}')     plt.legend()     plt.show()      # Print statistical analysis results     print("\nStatistical Analysis:")     print(f"Average Speed: {average_speed:.2f}")     print(f"Standard Deviation of Speed: {std_dev_speed:.2f}")  # Read the RAPID program file with open(filename2, 'r') as file:     program_text = file.read()  # Analyze the robot program analyze_robot_program(program_text)