File size: 1,276 Bytes
718b812
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import matplotlib.pyplot as plt
import numpy as np


def plot_tachometer(quality):
    fig, ax = plt.subplots(figsize=(6, 3), subplot_kw={'projection': 'polar'})

    # Create the base for the tachometer (semi-circle) correctly oriented (0 on the left, 100 on the right)
    theta = np.linspace(np.pi, 0, 100)  # Flip the range from pi to 0
    ax.plot(theta, np.ones_like(theta), lw=10, color="lightgrey")

    # Plot the current value as a red needle
    theta_value = np.pi - (quality / 100.0) * np.pi  # Subtract to flip needle direction
    ax.plot([theta_value, theta_value], [0, 1], lw=3, color="red")

    # Add labels and customize the plot
    ax.set_xticks(np.linspace(np.pi, 0, 5))  # Correctly set the ticks from left (0) to right (100)
    ax.set_xticklabels(['0', '25', '50', '75', '100'])  # Labels
    ax.set_yticks([])  # No radial ticks
    ax.spines['polar'].set_visible(False)

    # Add a title for clarity
    ax.set_title(f"Running Quality: {quality:.1f}/100", va='bottom')

    # Use tight layout to avoid cropping and ensure all elements fit well
    plt.tight_layout(pad=2.0)

    return fig


# Emoticon for Model 2
def get_emoticon(mental_health):
    if mental_health == 0:
        return "😎"
    elif mental_health == 1:
        return "🤯"