import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号


def read_csv_columns(csv_file_path, column_names):
    df = pd.read_csv(csv_file_path)
    return df[column_names].values


def plot_comparison(csv_file_path1, csv_file_path2, column_names):
    data1 = read_csv_columns(csv_file_path1, column_names)
    data2 = read_csv_columns(csv_file_path2, column_names)

    plt.figure(figsize=(12, 8))
    plt.plot(data1[:, 0], label=f'Gesture 1 - {column_names[0]}', color='#FF4081')
    plt.plot(data2[:, 0], label=f'Gesture 2 - {column_names[0]}', linestyle='--', color='#FF4081')
    plt.plot(data1[:, 1], label=f'Gesture 1 - {column_names[1]}', color='#1da1e6')
    plt.plot(data2[:, 1], label=f'Gesture 2 - {column_names[1]}', linestyle='--', color='#1da1e6')
    plt.plot(data1[:, 2], label=f'Gesture 1 - {column_names[2]}', color='#000210')
    plt.plot(data2[:, 2], label=f'Gesture 2 - {column_names[2]}', linestyle='--', color='#000210')
    plt.title('同一个人的不同姿势对比')
    plt.xlabel('Time')
    plt.ylabel('Value')
    plt.legend(loc='lower left')
    plt.tight_layout()
    plt.savefig('ComparsionACC_SameP_Diff.png')

    plt.figure(figsize=(12, 8))
    plt.plot(data1[:, 3], label=f'Gesture 1 - {column_names[3]}', color='#FF4081')
    plt.plot(data2[:, 3], label=f'Gesture 2 - {column_names[3]}', linestyle='--', color='#FF4081')
    plt.plot(data1[:, 4], label=f'Gesture 1 - {column_names[4]}', color='#1da1e6')
    plt.plot(data2[:, 4], label=f'Gesture 2 - {column_names[4]}', linestyle='--', color='#1da1e6')
    plt.plot(data1[:, 5], label=f'Gesture 1 - {column_names[5]}', color='#000210')
    plt.plot(data2[:, 5], label=f'Gesture 2 - {column_names[5]}', linestyle='--', color='#000210')
    plt.title('同一个人的不同姿势对比')
    plt.xlabel('Time')
    plt.ylabel('Value')
    plt.legend(loc='lower left')
    plt.tight_layout()
    plt.savefig('ComparsionGyro_SameP_Diff.png')

    plt.figure(figsize=(12, 8))
    plt.plot(data1[:, 6], label=f'Gesture 1 - {column_names[6]}', color='#FF4081')
    plt.plot(data2[:, 6], label=f'Gesture 2 - {column_names[6]}', linestyle='--', color='#FF4081')
    plt.plot(data1[:, 7], label=f'Gesture 1 - {column_names[7]}', color='#1da1e6')
    plt.plot(data2[:, 7], label=f'Gesture 2 - {column_names[7]}', linestyle='--', color='#1da1e6')
    plt.plot(data1[:, 8], label=f'Gesture 1 - {column_names[8]}', color='#000210')
    plt.plot(data2[:, 8], label=f'Gesture 2 - {column_names[8]}', linestyle='--', color='#000210')
    plt.title('同一个人的不同姿势对比')
    plt.xlabel('Time')
    plt.ylabel('Value')
    plt.legend(loc='lower left')
    plt.tight_layout()
    plt.savefig('ComparsionMag_SameP_Diff.png')
    plt.show()


if __name__ == "__main__":
    csv_file1 = r'D:\pycharmProjects\python_server\NormalizeData\4d9fddfe684048ccbbe100bf40a51180_wavelet_denoised_kalman_denoised_normalized.csv'
    csv_file2 = r'D:\pycharmProjects\python_server\NormalizeData\c744b2c8330e41c4980f57fbd1ffa4f8_wavelet_denoised_kalman_denoised_normalized.csv'
    columns_to_compare = ['accX', 'accY', 'accZ', 'gyroX', 'gyroY', 'gyroZ', 'magX', 'magY', 'magZ']

    plot_comparison(csv_file1, csv_file2, columns_to_compare)
