File size: 3,699 Bytes
e3551a8
 
9cec98e
e3551a8
 
 
9cec98e
e3551a8
 
 
 
9cec98e
e3551a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import plotly.graph_objects as go
from plotly.subplots import make_subplots

def create_charts(results):
    charts = {}
    explanations = {}

    # Loop through each detected speaker in the results
    for speaker_id, speaker_data in results['speakers'].items():
        speaker_charts = {}
        speaker_explanations = {}

        # Attachment Styles for each speaker
        attachment_data = speaker_data['attachments']
        fig_attachment = go.Figure(go.Bar(
            x=['Secured', 'Anxious-Preoccupied', 'Dismissive-Avoidant', 'Fearful-Avoidant'],
            y=[attachment_data.secured, attachment_data.anxious_preoccupied,
               attachment_data.dismissive_avoidant, attachment_data.fearful_avoidant],
            marker_color=['blue', 'orange', 'green', 'red']
        ))
        fig_attachment.update_layout(title_text=f"Attachment Styles - Speaker {speaker_id}", showlegend=False)
        speaker_charts["attachment"] = fig_attachment
        speaker_explanations["attachment"] = attachment_data.explanation

        # Attachment Dimensions (Radar Chart) for each speaker
        fig_dimensions = go.Figure(go.Scatterpolar(
            r=[attachment_data.avoidance, attachment_data.anxiety, attachment_data.self_rating, attachment_data.others_rating],
            theta=['Avoidance', 'Anxiety', 'Self', 'Others'],
            fill='toself'
        ))
        fig_dimensions.update_layout(title_text=f"Attachment Dimensions - Speaker {speaker_id}", showlegend=False)
        speaker_charts["dimensions"] = fig_dimensions

        # Big Five Traits for each speaker
        bigfive_data = speaker_data['bigfive']
        fig_bigfive = go.Figure(go.Bar(
            x=['Extraversion', 'Agreeableness', 'Conscientiousness', 'Neuroticism', 'Openness'],
            y=[bigfive_data.extraversion, bigfive_data.agreeableness,
               bigfive_data.conscientiousness, bigfive_data.neuroticism, bigfive_data.openness],
            marker_color=['blue', 'green', 'red', 'purple', 'orange']
        ))
        fig_bigfive.update_layout(title_text=f"Big Five Traits - Speaker {speaker_id}", showlegend=False)
        speaker_charts["bigfive"] = fig_bigfive
        speaker_explanations["bigfive"] = bigfive_data.explanation

        # Personality Disorders for each speaker
        personality_data = speaker_data['personalities']
        fig_personality = go.Figure(go.Bar(
            x=['Antisocial', 'Narcissistic', 'Depressed', 'Anxious-Avoidant',
               'Obsessive', 'Paranoid', 'Borderline', 'Dependent', 'Schizoid-Schizotypal'],
            y=[personality_data.antisocial_psychopathic, personality_data.narcissistic,
               personality_data.depressed, personality_data.anxious_avoidant,
               personality_data.obsessional, personality_data.paranoid,
               personality_data.borderline_dysregulated, personality_data.dependent_victimized,
               personality_data.schizoid_schizotypal],
            marker_color=['black', 'orange', 'gray', 'green', 'brown', 'purple', 'red', 'cyan', 'magenta']
        ))
        fig_personality.update_layout(title_text=f"Personality Disorders - Speaker {speaker_id}", showlegend=False)
        speaker_charts["personality"] = fig_personality
        speaker_explanations["personality"] = personality_data.explanation

        # Update all charts to take full width
        for fig in speaker_charts.values():
            fig.update_layout(height=400, width=None, margin=dict(l=50, r=50, t=100, b=50))

        # Store the charts and explanations for each speaker
        charts[speaker_id] = speaker_charts
        explanations[speaker_id] = speaker_explanations

    return charts, explanations