File size: 1,455 Bytes
2590409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import plotly.graph_objs as go
import pandas as pd
from sklearn.decomposition import PCA


def create_feature_radar_chart(features):
    categories = ['振幅', '分布范围', '衰减速度', '反射次数']
    values = [features[f'{cat}值'] for cat in categories]

    fig = go.Figure(data=go.Scatterpolar(
        r=values,
        theta=categories,
        fill='toself'
    ))

    fig.update_layout(
        polar=dict(
            radialaxis=dict(visible=True, range=[0, max(values)])
        ),
        showlegend=False
    )

    return fig.to_html(full_html=False)


def create_pca_visualization(reports):
    features = ['振幅值', '分布范围值', '衰减速度值', '反射次数值']
    X = pd.DataFrame([r.features for r in reports])[features]

    pca = PCA(n_components=2)
    pca_result = pca.fit_transform(X)

    df = pd.DataFrame(data=pca_result, columns=['PC1', 'PC2'])
    df['缺陷类型'] = [r.defect_type for r in reports]

    fig = go.Figure(data=go.Scatter(
        x=df['PC1'],
        y=df['PC2'],
        mode='markers',
        marker=dict(
            size=10,
            color=df['缺陷类型'].map({'空洞': 'red', '裂缝': 'blue'}),
            opacity=0.8
        ),
        text=df['缺陷类型']
    ))

    fig.update_layout(
        title='PCA of Radar Features',
        xaxis_title='Principal Component 1',
        yaxis_title='Principal Component 2'
    )

    return fig.to_html(full_html=False)