Spaces:
Sleeping
Sleeping
File size: 5,107 Bytes
8124557 a2be408 9ba6b7c a2be408 525dec8 ac5639a a2be408 1e5badb a2be408 525dec8 a2be408 525dec8 a2be408 1e5badb a2be408 1e5badb a2be408 1e5badb a2be408 1e5badb a2be408 1e5badb a2be408 525dec8 a2be408 525dec8 a2be408 525dec8 a2be408 1e5badb a2be408 1e5badb a2be408 1e5badb a2be408 1e5badb a2be408 1e5badb a2be408 8124557 1e5badb a2be408 | 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | import streamlit as st
import pandas as pd
import altair as alt
import os
import sys
import time
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(BASE_DIR)
from inference import TelemetryInferenceEngineLite
DATA_PATH = os.path.join(BASE_DIR, "assets/test.csv")
st.set_page_config(page_title="Race Telemetry", layout="wide")
@st.cache_resource
def load_engine():
return TelemetryInferenceEngineLite()
engine = load_engine()
@st.cache_data
def load_data():
return pd.read_csv(DATA_PATH)
FULL_DATA = load_data()
if "cursor" not in st.session_state:
st.session_state.cursor = 0
if "telemetry" not in st.session_state:
st.session_state.telemetry = pd.DataFrame()
st.markdown("""
<style>
.ml-label {
font-size: 20px;
color: #94a3b8;
margin-bottom: 0px;
}
.ml-value {
font-size: 38px;
font-weight: 500;
line-height: 2;
}
</style>
""", unsafe_allow_html=True)
st.sidebar.title("Pit Wall Controls")
auto_refresh = st.sidebar.toggle("Auto Refresh", value=True)
refresh_interval = st.sidebar.slider("Refresh Interval (seconds)", 1, 5, 1)
batch_size = st.sidebar.selectbox("Rows per fetch", [1, 5, 10], index=0)
def fetch_rows(batch_size):
start = st.session_state.cursor
end = start + batch_size
batch = FULL_DATA.iloc[start:end].copy()
st.session_state.cursor = end
return batch
def run_inference(df_batch):
outputs = []
for _, row in df_batch.iterrows():
prediction = engine.process_row(row)
row_dict = row.to_dict()
row_dict["predicted_lap_time"] = prediction.get("predicted_lap_time")
row_dict["predicted_gear"] = prediction.get("predicted_gear")
row_dict["driving_behavior"] = prediction.get("driving_behavior")
outputs.append(row_dict)
return pd.DataFrame(outputs)
new_data = fetch_rows(batch_size)
if not new_data.empty:
processed = run_inference(new_data)
st.session_state.telemetry = pd.concat(
[st.session_state.telemetry, processed],
ignore_index=True
)
df = st.session_state.telemetry
if df.empty:
st.stop()
df["t"] = range(len(df))
latest = df.iloc[-1]
st.markdown(
"""
<div style="text-align:center; line-height:0;">
<h2>🏁 Race Telemetry</h2>
<h4>Pit Wall Dashboard</h4>
</div>
""",
unsafe_allow_html=True
)
left, right = st.columns([3, 1])
with left:
with st.container(border=True):
c1, c2, c3 = st.columns(3)
with c1:
st.markdown('<div class="ml-label">Predicted Lap</div>', unsafe_allow_html=True)
st.markdown(
f'<div class="ml-value" style="color:#38bdf8;">{latest["predicted_lap_time"]:.2f} s</div>',
unsafe_allow_html=True
)
with c2:
st.markdown('<div class="ml-label">Recommended Gear</div>', unsafe_allow_html=True)
st.markdown(
f'<div class="ml-value" style="color:#22c55e;">{int(latest["predicted_gear"])}</div>',
unsafe_allow_html=True
)
with c3:
st.markdown('<div class="ml-label">Driving Style</div>', unsafe_allow_html=True)
st.markdown(
f'<div class="ml-value" style="color:#facc15;">{latest["driving_behavior"]}</div>',
unsafe_allow_html=True
)
st.markdown("<br>", unsafe_allow_html=True)
r2c1, r2c2 = st.columns(2)
r2c1.metric("Speed (km/h)", f"{latest['speed']:.1f}")
r2c1.altair_chart(
alt.Chart(df).mark_line().encode(x="t:Q", y="speed:Q"),
use_container_width=True
)
r2c2.metric("Engine RPM", int(latest["current_engine_rpm"]))
r2c2.altair_chart(
alt.Chart(df).mark_area(opacity=0.7).encode(x="t:Q", y="current_engine_rpm:Q"),
use_container_width=True
)
with right:
st.markdown("### Track")
st.image(os.path.join(BASE_DIR, "assets/track.png"), use_container_width=True)
p1, p2, p3, p4 = st.columns(4)
df["power_kw"] = df["power"] / 1000
p1.metric("Power (kW)", f"{df['power_kw'].iloc[-1]:.1f}")
p1.altair_chart(alt.Chart(df).mark_area().encode(x="t", y="power_kw"), use_container_width=True)
p2.metric("Torque (Nm)", f"{latest['torque']:.1f}")
p2.altair_chart(alt.Chart(df).mark_line().encode(x="t", y="torque"), use_container_width=True)
p3.metric("Boost (psi)", f"{latest['boost']:.2f}")
p3.altair_chart(alt.Chart(df).mark_line().encode(x="t", y="boost"), use_container_width=True)
p4.metric("Avg Tire Temp (°C)", f"{latest['avg_tire_temp']:.1f}")
p4.altair_chart(alt.Chart(df).mark_line().encode(x="t", y="avg_tire_temp"), use_container_width=True)
attitude_chart = alt.Chart(df).transform_fold(
["yaw", "pitch", "roll"],
as_=["Axis", "Value"]
).mark_line().encode(
x="t:Q",
y="Value:Q",
color="Axis:N"
)
st.metric(
"Yaw / Pitch / Roll (rad)",
f"{latest['yaw']:.2f}, {latest['pitch']:.2f}, {latest['roll']:.2f}"
)
st.altair_chart(attitude_chart, use_container_width=True)
if auto_refresh:
time.sleep(refresh_interval)
st.rerun() |