2222
2323import os
2424import pathlib
25- import starplot
26- import streamlit as st
2725from datetime import datetime , date
2826from zoneinfo import ZoneInfo
2927
28+ import streamlit as st
29+
30+ import starplot
3031import starplot .data .constellations as condata
3132import starplot .data .stars as stardata
3233
4445try :
4546 condata .table ()
4647 stardata .table ()
47- except Exception as e :
48+ except Exception as e : # pylint: disable=broad-exception-caught
4849 print ("Warning: preload failed:" , e )
4950
5051# ───────────────────────────────────────────────
6162
6263# Extra option: fast vs HD
6364quality = st .sidebar .radio ("Quality" , ["Fast (preview)" , "HD (slower)" ])
64- resolution = 1200 if quality == "Fast (preview)" else 2400
65+ RESOLUTION = 1200 if quality == "Fast (preview)" else 2400
6566
6667# Session state
6768if "chart_bytes" not in st .session_state :
7273# Cached chart generator
7374# ───────────────────────────────────────────────
7475@st .cache_data
75- def generate_chart (plot_type , dt , mag_limit , resolution ):
76- if plot_type == "Horizon" :
77- return make_horizon_plot (dt = dt , mag_limit = mag_limit , resolution = resolution )
78- else :
79- return make_zenith_plot (dt = dt , mag_limit = mag_limit , resolution = resolution )
76+ def generate_chart (plt_type : str ,
77+ date_time : datetime ,
78+ mag_lim : int ,
79+ res : int ) -> bytes :
80+ """
81+ Generate chart and cache for performance
82+
83+ Args:
84+ - plt_type: Either Horizon or Zenith
85+ - date_time: Datetime for the star plot
86+ - mag_lim: The maximum magnitude for stars in the plot
87+ - res: Resolution of the image
88+
89+ Returns:
90+ - The image in bytes
91+ """
92+ if plt_type == "Horizon" :
93+ return make_horizon_plot (dt = date_time , mag_limit = mag_lim , resolution = res )
94+
95+ return make_zenith_plot (dt = date_time , mag_limit = mag_lim , resolution = res )
8096
8197
8298# ───────────────────────────────────────────────
@@ -87,7 +103,7 @@ def generate_chart(plot_type, dt, mag_limit, resolution):
87103 dt = datetime .combine (obs_date , obs_time ).replace (tzinfo = tz )
88104
89105 with st .spinner ("Generating chart, please wait..." ):
90- img_bytes = generate_chart (plot_type , dt , mag_limit , resolution )
106+ img_bytes = generate_chart (plot_type , dt , mag_limit , RESOLUTION )
91107
92108 st .session_state .chart_bytes = img_bytes
93109 st .success ("✅ Chart generated!" )
0 commit comments