1616 DASHBOARD_USER : DASHBOARD_PASSWORD
1717}
1818
19+
1920# 登录验证函数
2021def authenticate (username , password ):
2122 return username in USER_CREDENTIALS and USER_CREDENTIALS [username ] == password
2223
24+
2325# 获取数据函数
24- def get_data (service_func , authors = None , updated_at_gte = None , updated_at_lte = None , columns = None ):
25- df = service_func (authors = authors , updated_at_gte = updated_at_gte , updated_at_lte = updated_at_lte )
26+ def get_data (service_func , authors = None , project_names = None , updated_at_gte = None , updated_at_lte = None , columns = None ):
27+ df = service_func (authors = authors , project_names = project_names , updated_at_gte = updated_at_gte , updated_at_lte = updated_at_lte )
2628
2729 if df .empty :
2830 return pd .DataFrame (columns = columns )
@@ -36,9 +38,11 @@ def get_data(service_func, authors=None, updated_at_gte=None, updated_at_lte=Non
3638 data = df [columns ]
3739 return data
3840
41+
3942# Streamlit 配置
4043st .set_page_config (layout = "wide" )
4144
45+
4246# 登录界面
4347def login_page ():
4448 # 使用 st.columns 创建居中布局
@@ -83,10 +87,9 @@ def main_page():
8387 else :
8488 mr_tab = st .container ()
8589
86-
8790 def display_data (tab , service_func , columns , column_config ):
8891 with tab :
89- col1 , col2 , col3 = st .columns (3 )
92+ col1 , col2 , col3 , col4 = st .columns (4 )
9093 with col1 :
9194 start_date = st .date_input ("开始日期" , start_date_default , key = f"{ tab } _start_date" )
9295 with col2 :
@@ -100,10 +103,13 @@ def display_data(tab, service_func, columns, column_config):
100103 df = pd .DataFrame (data )
101104
102105 unique_authors = sorted (df ["author" ].dropna ().unique ().tolist ()) if not df .empty else []
106+ unique_projects = sorted (df ["project_name" ].dropna ().unique ().tolist ()) if not df .empty else []
103107 with col3 :
104108 authors = st .multiselect ("用户名" , unique_authors , default = [], key = f"{ tab } _authors" )
109+ with col4 :
110+ project_names = st .multiselect ("项目名" , unique_projects , default = [], key = f"{ tab } _projects" )
105111
106- data = get_data (service_func , authors = authors , updated_at_gte = int (start_datetime .timestamp ()),
112+ data = get_data (service_func , authors = authors ,project_names = project_names , updated_at_gte = int (start_datetime .timestamp ()),
107113 updated_at_lte = int (end_datetime .timestamp ()), columns = columns )
108114 df = pd .DataFrame (data )
109115
@@ -117,7 +123,6 @@ def display_data(tab, service_func, columns, column_config):
117123 average_score = df ["score" ].mean () if not df .empty else 0
118124 st .markdown (f"**总记录数:** { total_records } ,**平均分:** { average_score :.2f} " )
119125
120-
121126 # Merge Request 数据展示
122127 mr_columns = ["project_name" , "author" , "source_branch" , "target_branch" , "updated_at" , "commit_messages" , "score" ,
123128 "url" ]
@@ -149,11 +154,13 @@ def display_data(tab, service_func, columns, column_config):
149154 }
150155
151156 display_data (push_tab , ReviewService ().get_push_review_logs , push_columns , push_column_config )
157+
158+
152159# 应用入口
153160if "authenticated" not in st .session_state :
154161 st .session_state ["authenticated" ] = False
155162
156163if st .session_state ["authenticated" ]:
157164 main_page ()
158165else :
159- login_page ()
166+ login_page ()
0 commit comments