def update_graph(n): infos = get_infos() device_info = infos["devices"] fig = tools.make_subplots( rows=2, cols=2, subplot_titles=( "Memory Utilization", "Free Memory (MB)", "Temperature", "Fan Speed", ), shared_xaxes=False, print_grid=False, ) x = [f"{d.name} {d.id}" for d in device_info] free = [d.free / (1024.0**2) for d in device_info] used = [d.used / (1024.0**2) for d in device_info] total = [d.total / (1024.0**2) for d in device_info] used_ratio = [100 * u / t for u, t in zip(used, total)] temp = [d.temperature for d in device_info] speed = [d.fan_speed for d in device_info] hover_text = [ f"used={u:.0f}<br>total={t:.0f}" for u, t in zip(used, total) ] trace_used_ratio = go.Bar( x=x, y=used_ratio, text=hover_text, marker=dict(color=bar_colors[0]), name="used ratio", ) trace_free = go.Bar(x=x, y=free, marker=dict(color=bar_colors[1]), name="free") trace_temp = go.Bar(x=x, y=temp, marker=dict(color=bar_colors[2]), name="temperature") trace_speed = go.Bar(x=x, y=speed, marker=dict(color=bar_colors[3]), name="fan speed") fig.append_trace(trace_used_ratio, 1, 1) fig.append_trace(trace_free, 1, 2) fig.append_trace(trace_temp, 2, 1) fig.append_trace(trace_speed, 2, 2) margin = go.layout.Margin(l=100, r=100, b=50, t=25, pad=4) fig["layout"].update(yaxis=dict(range=[0, 100]), margin=margin, showlegend=False) return fig
def update_table(n): infos = get_infos() result = convert_to_df(infos) return result.to_dict(orient="rows")