1+ """Common utilities and constants for VAI demo"""
2+
3+ import subprocess
4+
5+ GRAPH_SAMPLE_WINDOW_SIZE_s = 31
6+ HW_SAMPLING_PERIOD_ms = 250
7+ GRAPH_DRAW_PERIOD_ms = 30
8+ AUTOMATIC_DEMO_SWITCH_s = 60
9+ QUIT_CLEANUP_DELAY_ms = 1000
10+
11+ GRAPH_SAMPLE_SIZE = int (GRAPH_SAMPLE_WINDOW_SIZE_s * 1000 / GRAPH_DRAW_PERIOD_ms )
12+
13+ TIME_KEY = "time"
14+ CPU_UTIL_KEY = "cpu %"
15+ MEM_UTIL_KEY = "lpddr5 %"
16+ GPU_UTIL_KEY = "gpu %"
17+ DSP_UTIL_KEY = "dsp %"
18+ CPU_THERMAL_KEY = "cpu temp (°c)"
19+ MEM_THERMAL_KEY = "lpddr5 temp (°c)"
20+ GPU_THERMAL_KEY = "gpu temp (°c)"
21+
22+ # Triadic colors, indexed on Tria pink
23+ TRIA_PINK_RGBH = (0xFE , 0x00 , 0xA2 )
24+ TRIA_BLUE_RGBH = (0x00 , 0xA2 , 0xFE )
25+ TRIA_YELLOW_RGBH = (0xFE , 0xDB , 0x00 )
26+ TRIA_GREEN_RGBH = (0x22 , 0xB1 , 0x4C )
27+
28+ APP_NAME = f"GTK GUI Node"
29+
30+ TRIA = r"""
31+ ████████╗██████╗ ██╗ █████╗
32+ ╚══██╔══╝██╔══██╗██║██╔══██╗
33+ ██║ ██████╔╝██║███████║
34+ ██║ ██╔══██╗██║██╔══██║
35+ ██║ ██║ ██║██║██║ ██║
36+ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝
37+ """
38+
39+
40+ def lerp (a , b , t ):
41+ """Linear interpolation between two values"""
42+ return a + t * (b - a )
43+
44+
45+ def inverse_lerp (a , b , v ):
46+ """Inverse linear interpolation between two values"""
47+ return (v - a ) / (b - a ) if a != b else 0.0
48+
49+
50+ def get_ema (x_cur , x_last , alpha = 0.75 ):
51+ """
52+ Exponential moving average
53+
54+ Args:
55+ x_cur: Current value
56+ x_last: Last value
57+ alpha: Smoothing factor
58+
59+ Note:
60+ alpha is a misnomer. alpha = 1.0 is equivalent to no smoothing
61+
62+ Ref:
63+ https://en.wikipedia.org/wiki/Exponential_smoothing
64+
65+ """
66+ return alpha * x_cur + (1 - alpha ) * x_last
67+
68+
69+ def app_version ():
70+ """Get the latest tag or commit hash if possible, unknown otherwise"""
71+
72+ try :
73+ version = subprocess .check_output (
74+ ["git" , "describe" , "--tags" , "--always" ], text = True
75+ ).strip ()
76+ date = subprocess .check_output (
77+ ["git" , "log" , "-1" , "--format=%cd" , "--date=short" ], text = True
78+ ).strip ()
79+
80+ return f"{ version } { date } "
81+ except subprocess .CalledProcessError :
82+ # Handle errors, such as not being in a Git repository
83+ return "unknown"
84+
85+
86+ APP_HEADER = f"{ APP_NAME } v({ app_version ()} )"
0 commit comments