Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files504 unmodified lines5055065075085095105115125135145155165175185195205215225239 unmodified lines5335345355365375385395405415425435445455465475485495 unmodified lines555556557558559560561504 unmodified lines# Single plot and table section (no placeholders needed)st.markdown("---")# Create a cache key based on all parameters to avoid unnecessary redrawscache_key = f"{speed1}_{angle1}_{height1}_{speed2}_{angle2}_{height2}_{speed3}_{angle3}_{height3}"# Use containers to prevent flickeringplot_container = st.container()table_container = st.container()with plot_container:# Create comparison plotfig, ax = plt.subplots(figsize=(12, 8))max_range = 0for name, motion, color in trajectories:data = motion.trajectory_data(motion.calculate_flight_time())ax.plot(data['x'], data['y'], linewidth=3, label=name, color=color)9 unmodified linesax.grid(True, alpha=0.3)ax.legend(fontsize=12)ax.set_ylim(bottom=0)ax.set_xlim(0, max_range * 1.1)st.pyplot(fig, clear_figure=True)plt.close(fig) # Explicitly close the figurewith table_container:# Comparison tablest.markdown("### ๐ Trajectory Comparison Table")comparison_data = []for name, motion, _ in trajectories:info = motion.get_launch_info()comparison_data.append({"Trajectory": name,5 unmodified lines"Max Height (m)": f"{info['max_height']:.1f}"})st.table(comparison_data)if __name__ == "__main__":main()504 unmodified lines5055065075085095105115125135145155165175185195205215225235249 unmodified lines5345355365375385395405415425435445455465475485495505515525535545 unmodified lines560561562563564565566567568569570571572573574575576504 unmodified lines# Single plot and table section (no placeholders needed)st.markdown("---")# Create comparison plot using st.cache_data to prevent re-rendering@st.cache_datadef create_comparison_plot(speed1, angle1, height1, speed2, angle2, height2, speed3, angle3, height3):# Recreate trajectories inside cached functiontrajectories_cached = [("Trajectory 1", Motion2D(launch_speed=speed1, launch_angle=angle1, launch_height=height1), 'blue'),("Trajectory 2", Motion2D(launch_speed=speed2, launch_angle=angle2, launch_height=height2), 'red'),("Trajectory 3", Motion2D(launch_speed=speed3, launch_angle=angle3, launch_height=height3), 'green')]fig, ax = plt.subplots(figsize=(12, 8))max_range = 0for name, motion, color in trajectories_cached:data = motion.trajectory_data(motion.calculate_flight_time())ax.plot(data['x'], data['y'], linewidth=3, label=name, color=color)9 unmodified linesax.grid(True, alpha=0.3)ax.legend(fontsize=12)ax.set_ylim(bottom=0)ax.set_xlim(0, max_range * 1.1 if max_range > 0 else 10)return fig# Create cached comparison data@st.cache_datadef create_comparison_data(speed1, angle1, height1, speed2, angle2, height2, speed3, angle3, height3):trajectories_data = [("Trajectory 1", Motion2D(launch_speed=speed1, launch_angle=angle1, launch_height=height1)),("Trajectory 2", Motion2D(launch_speed=speed2, launch_angle=angle2, launch_height=height2)),("Trajectory 3", Motion2D(launch_speed=speed3, launch_angle=angle3, launch_height=height3))]comparison_data = []for name, motion in trajectories_data:info = motion.get_launch_info()comparison_data.append({"Trajectory": name,5 unmodified lines"Max Height (m)": f"{info['max_height']:.1f}"})return comparison_data# Display cached plotfig = create_comparison_plot(speed1, angle1, height1, speed2, angle2, height2, speed3, angle3, height3)st.pyplot(fig, clear_figure=True)plt.close(fig)# Display cached comparison tablest.markdown("### ๐ Trajectory Comparison Table")comparison_data = create_comparison_data(speed1, angle1, height1, speed2, angle2, height2, speed3, angle3, height3)st.table(comparison_data)if __name__ == "__main__":main()
src/streamlit_app.py+33-18