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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import requests
|
| 5 |
+
import time
|
| 6 |
+
from collections import defaultdict
|
| 7 |
+
|
| 8 |
+
# Set page layout to wide mode and set page title
|
| 9 |
+
st.set_page_config(layout="wide", page_title="影城效率与内容分析工具")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# --- Efficiency Analysis Functions ---
|
| 13 |
+
def clean_movie_title(title):
|
| 14 |
+
if not isinstance(title, str):
|
| 15 |
+
return title
|
| 16 |
+
return title.split(' ', 1)[0]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# --- UPDATED: Styling function for the first two tables ---
|
| 20 |
+
def style_efficiency(row):
|
| 21 |
+
"""Applies row styling based on efficiency metrics for analysis tables."""
|
| 22 |
+
green = 'background-color: #E6F5E6;' # Light Green
|
| 23 |
+
red = 'background-color: #FFE5E5;' # Light Red
|
| 24 |
+
|
| 25 |
+
seat_efficiency = row.get('座次效率', 0)
|
| 26 |
+
session_efficiency = row.get('场次效率', 0)
|
| 27 |
+
|
| 28 |
+
if seat_efficiency > 1.5 or session_efficiency > 1.5:
|
| 29 |
+
return [green] * len(row)
|
| 30 |
+
if seat_efficiency < 0.5 or session_efficiency < 0.5:
|
| 31 |
+
return [red] * len(row)
|
| 32 |
+
|
| 33 |
+
return [''] * len(row)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# --- NEW: Styling function for the summary table ---
|
| 37 |
+
def style_summary_efficiency(row):
|
| 38 |
+
"""Applies row styling based on efficiency metrics for the summary table."""
|
| 39 |
+
green = 'background-color: #E6F5E6;' # Light Green
|
| 40 |
+
red = 'background-color: #FFE5E5;' # Light Red
|
| 41 |
+
|
| 42 |
+
# Check all four efficiency columns in the summary table
|
| 43 |
+
full_day_seat_eff = row.get('全部座次效率', 0)
|
| 44 |
+
full_day_session_eff = row.get('全部场次效率', 0)
|
| 45 |
+
prime_seat_eff = row.get('黄金时段座次效率', 0)
|
| 46 |
+
prime_session_eff = row.get('黄金时段场次效率', 0)
|
| 47 |
+
|
| 48 |
+
# Green condition: if any efficiency is high
|
| 49 |
+
if (full_day_seat_eff > 1.5 or full_day_session_eff > 1.5 or
|
| 50 |
+
prime_seat_eff > 1.5 or prime_session_eff > 1.5):
|
| 51 |
+
return [green] * len(row)
|
| 52 |
+
|
| 53 |
+
# Red condition: if any efficiency is low
|
| 54 |
+
if (full_day_seat_eff < 0.5 or full_day_session_eff < 0.5 or
|
| 55 |
+
prime_seat_eff < 0.5 or prime_session_eff < 0.5):
|
| 56 |
+
return [red] * len(row)
|
| 57 |
+
|
| 58 |
+
return [''] * len(row)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def process_and_analyze_data(df):
|
| 62 |
+
if df.empty:
|
| 63 |
+
return pd.DataFrame()
|
| 64 |
+
analysis_df = df.groupby('影片名称_清理后').agg(
|
| 65 |
+
座位数=('座位数', 'sum'),
|
| 66 |
+
场次=('影片名称_清理后', 'size'),
|
| 67 |
+
票房=('总收入', 'sum'),
|
| 68 |
+
人次=('总人次', 'sum')
|
| 69 |
+
).reset_index()
|
| 70 |
+
analysis_df.rename(columns={'影片名称_清理后': '影片'}, inplace=True)
|
| 71 |
+
analysis_df = analysis_df.sort_values(by='票房', ascending=False).reset_index(drop=True)
|
| 72 |
+
total_seats = analysis_df['座位数'].sum()
|
| 73 |
+
total_sessions = analysis_df['场次'].sum()
|
| 74 |
+
total_revenue = analysis_df['票房'].sum()
|
| 75 |
+
analysis_df['均价'] = np.divide(analysis_df['票房'], analysis_df['人次']).fillna(0)
|
| 76 |
+
analysis_df['座次比'] = np.divide(analysis_df['座位数'], total_seats).fillna(0)
|
| 77 |
+
analysis_df['场次比'] = np.divide(analysis_df['场次'], total_sessions).fillna(0)
|
| 78 |
+
analysis_df['票房比'] = np.divide(analysis_df['票房'], total_revenue).fillna(0)
|
| 79 |
+
analysis_df['座次效率'] = np.divide(analysis_df['票房比'], analysis_df['座次比']).fillna(0)
|
| 80 |
+
analysis_df['场次效率'] = np.divide(analysis_df['票房比'], analysis_df['场次比']).fillna(0)
|
| 81 |
+
final_columns = ['影片', '座位数', '场次', '票房', '人次', '均价', '座次比', '场次比', '票房比', '座次效率',
|
| 82 |
+
'场次效率']
|
| 83 |
+
analysis_df = analysis_df[final_columns]
|
| 84 |
+
return analysis_df
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
# --- New Feature: Server Movie Content Inquiry ---
|
| 88 |
+
# @st.cache_data(show_spinner=False)
|
| 89 |
+
def fetch_and_process_server_movies(priority_movie_titles=None):
|
| 90 |
+
if priority_movie_titles is None:
|
| 91 |
+
priority_movie_titles = []
|
| 92 |
+
|
| 93 |
+
# 1. Get Token
|
| 94 |
+
token_headers = {
|
| 95 |
+
'Host': 'oa.hengdianfilm.com:7080', 'Content-Type': 'application/json',
|
| 96 |
+
'Origin': 'http://115.239.253.233:7080', 'Connection': 'keep-alive',
|
| 97 |
+
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
| 98 |
+
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_5_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/138.0.7204.156 Mobile/15E148 Safari/604.1',
|
| 99 |
+
'Accept-Language': 'zh-CN,zh-Hans;q=0.9',
|
| 100 |
+
}
|
| 101 |
+
token_json_data = {'appId': 'hd', 'appSecret': 'ad761f8578cc6170', 'timeStamp': int(time.time() * 1000)}
|
| 102 |
+
token_url = 'http://oa.hengdianfilm.com:7080/cinema-api/admin/generateToken?token=hd&murl=?token=hd&murl=ticket=-1495916529737643774'
|
| 103 |
+
response = requests.post(token_url, headers=token_headers, json=token_json_data, timeout=10)
|
| 104 |
+
response.raise_for_status()
|
| 105 |
+
token_data = response.json()
|
| 106 |
+
if token_data.get('error_code') != '0000':
|
| 107 |
+
raise Exception(f"获取Token失败: {token_data.get('error_desc')}")
|
| 108 |
+
auth_token = token_data['param']
|
| 109 |
+
|
| 110 |
+
# 2. Fetch movie list (with pagination and delay)
|
| 111 |
+
all_movies = []
|
| 112 |
+
page_index = 1
|
| 113 |
+
while True:
|
| 114 |
+
list_headers = {
|
| 115 |
+
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
| 116 |
+
'Content-Type': 'application/json; charset=UTF-8',
|
| 117 |
+
'Origin': 'http://115.239.253.233:7080', 'Proxy-Connection': 'keep-alive', 'Token': auth_token,
|
| 118 |
+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
|
| 119 |
+
'X-SESSIONID': 'PQ0J3K85GJEDVYIGZE1KEG1K80USDAP4',
|
| 120 |
+
}
|
| 121 |
+
list_params = {'token': 'hd', 'murl': 'ContentMovie'}
|
| 122 |
+
list_json_data = {'THEATER_ID': 38205954, 'SOURCE': 'SERVER', 'ASSERT_TYPE': 2, 'PAGE_CAPACITY': 20,
|
| 123 |
+
'PAGE_INDEX': page_index}
|
| 124 |
+
list_url = 'http://oa.hengdianfilm.com:7080/cinema-api/cinema/server/dcp/list'
|
| 125 |
+
response = requests.post(list_url, params=list_params, headers=list_headers, json=list_json_data, verify=False)
|
| 126 |
+
response.raise_for_status()
|
| 127 |
+
movie_data = response.json()
|
| 128 |
+
if movie_data.get("RSPCD") != "000000":
|
| 129 |
+
raise Exception(f"获取影片列表失败: {movie_data.get('RSPMSG')}")
|
| 130 |
+
body = movie_data.get("BODY", {})
|
| 131 |
+
movies_on_page = body.get("LIST", [])
|
| 132 |
+
if not movies_on_page: break
|
| 133 |
+
all_movies.extend(movies_on_page)
|
| 134 |
+
if len(all_movies) >= body.get("COUNT", 0): break
|
| 135 |
+
page_index += 1
|
| 136 |
+
time.sleep(1) # Add 1-second delay between requests
|
| 137 |
+
|
| 138 |
+
# 3. Process data into a central, detailed structure
|
| 139 |
+
movie_details = {}
|
| 140 |
+
for movie in all_movies:
|
| 141 |
+
content_name = movie.get('CONTENT_NAME')
|
| 142 |
+
if not content_name: continue
|
| 143 |
+
movie_details[content_name] = {
|
| 144 |
+
'assert_name': movie.get('ASSERT_NAME'),
|
| 145 |
+
'halls': sorted([h.get('HALL_NAME') for h in movie.get('HALL_INFO', [])]),
|
| 146 |
+
'play_time': movie.get('PLAY_TIME')
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
# 4. Prepare data for the two display views
|
| 150 |
+
by_hall = defaultdict(list)
|
| 151 |
+
for content_name, details in movie_details.items():
|
| 152 |
+
for hall_name in details['halls']:
|
| 153 |
+
by_hall[hall_name].append({'content_name': content_name, 'details': details})
|
| 154 |
+
|
| 155 |
+
for hall_name in by_hall:
|
| 156 |
+
by_hall[hall_name].sort(key=lambda item: (
|
| 157 |
+
item['details']['assert_name'] is None or item['details']['assert_name'] == '',
|
| 158 |
+
item['details']['assert_name'] or item['content_name']
|
| 159 |
+
))
|
| 160 |
+
|
| 161 |
+
view2_list = []
|
| 162 |
+
for content_name, details in movie_details.items():
|
| 163 |
+
if details.get('assert_name'):
|
| 164 |
+
view2_list.append({
|
| 165 |
+
'assert_name': details['assert_name'],
|
| 166 |
+
'content_name': content_name,
|
| 167 |
+
'halls': details['halls'],
|
| 168 |
+
'play_time': details['play_time']
|
| 169 |
+
})
|
| 170 |
+
|
| 171 |
+
priority_list = [item for item in view2_list if
|
| 172 |
+
any(p_title in item['assert_name'] for p_title in priority_movie_titles)]
|
| 173 |
+
other_list_items = [item for item in view2_list if item not in priority_list]
|
| 174 |
+
|
| 175 |
+
priority_list.sort(key=lambda x: x['assert_name'])
|
| 176 |
+
other_list_items.sort(key=lambda x: x['assert_name'])
|
| 177 |
+
|
| 178 |
+
final_sorted_list = priority_list + other_list_items
|
| 179 |
+
|
| 180 |
+
return dict(sorted(by_hall.items())), final_sorted_list
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def get_circled_number(hall_name):
|
| 184 |
+
mapping = {'1': '①', '2': '②', '3': '③', '4': '④', '5': '⑤', '6': '⑥', '7': '⑦', '8': '⑧', '9': '⑨'}
|
| 185 |
+
num_str = ''.join(filter(str.isdigit, hall_name))
|
| 186 |
+
return mapping.get(num_str, '')
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def format_play_time(time_str):
|
| 190 |
+
if not time_str or not isinstance(time_str, str): return None
|
| 191 |
+
try:
|
| 192 |
+
parts = time_str.split(':');
|
| 193 |
+
hours = int(parts[0]);
|
| 194 |
+
minutes = int(parts[1])
|
| 195 |
+
return hours * 60 + minutes
|
| 196 |
+
except (ValueError, IndexError):
|
| 197 |
+
return None
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
# --- UPDATED Helper function to add TMS location column ---
|
| 201 |
+
def add_tms_locations_to_analysis(analysis_df, tms_movie_list):
|
| 202 |
+
locations = []
|
| 203 |
+
for index, row in analysis_df.iterrows():
|
| 204 |
+
movie_title = row['影片']
|
| 205 |
+
found_versions = []
|
| 206 |
+
for tms_movie in tms_movie_list:
|
| 207 |
+
if tms_movie['assert_name'].startswith(movie_title):
|
| 208 |
+
version_name = tms_movie['assert_name'].replace(movie_title, '').strip()
|
| 209 |
+
circled_halls = " ".join(sorted([get_circled_number(h) for h in tms_movie['halls']]))
|
| 210 |
+
if version_name:
|
| 211 |
+
found_versions.append(f"{version_name}:{circled_halls}")
|
| 212 |
+
else:
|
| 213 |
+
found_versions.append(circled_halls)
|
| 214 |
+
locations.append('|'.join(found_versions))
|
| 215 |
+
analysis_df['影片所在影厅位置'] = locations
|
| 216 |
+
return analysis_df
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
# --- Streamlit Main UI ---
|
| 220 |
+
st.title('影城排片效率与内容分析工具')
|
| 221 |
+
st.write("上传 `影片映出日累计报表.xlsx` 进行效率分析,或点击下方按钮查询 TMS 服务器影片内容。")
|
| 222 |
+
|
| 223 |
+
uploaded_file = st.file_uploader("请在此处上传 Excel 文件", type=['xlsx', 'xls', 'csv'])
|
| 224 |
+
query_tms_for_location = st.checkbox("查询 TMS 找影片所在影厅")
|
| 225 |
+
|
| 226 |
+
if uploaded_file is not None:
|
| 227 |
+
try:
|
| 228 |
+
df = pd.read_excel(uploaded_file, skiprows=3, header=None)
|
| 229 |
+
df.rename(columns={0: '影片名称', 2: '放映时间', 5: '总人次', 6: '总收入', 7: '座位数'}, inplace=True)
|
| 230 |
+
required_cols = ['影片名称', '放映时间', '座位数', '总收入', '总人次']
|
| 231 |
+
df = df[required_cols]
|
| 232 |
+
df.dropna(subset=['影片名称', '放映时间'], inplace=True)
|
| 233 |
+
for col in ['座位数', '总收入', '总人次']:
|
| 234 |
+
df[col] = pd.to_numeric(df[col], errors='coerce').fillna(0)
|
| 235 |
+
df['放映时间'] = pd.to_datetime(df['放映时间'], format='%H:%M:%S', errors='coerce').dt.time
|
| 236 |
+
df.dropna(subset=['放映时间'], inplace=True)
|
| 237 |
+
df['影片名称_清理后'] = df['影片名称'].apply(clean_movie_title)
|
| 238 |
+
st.toast("文件上传成功,效率分析已生成!", icon="🎉")
|
| 239 |
+
format_config = {'座位数': '{:,.0f}', '场次': '{:,.0f}', '人次': '{:,.0f}', '票房': '{:,.2f}', '均价': '{:.2f}',
|
| 240 |
+
'座次比': '{:.2%}', '场次比': '{:.2%}', '票房比': '{:.2%}', '座次效率': '{:.2f}',
|
| 241 |
+
'场次效率': '{:.2f}'}
|
| 242 |
+
|
| 243 |
+
full_day_analysis = process_and_analyze_data(df.copy())
|
| 244 |
+
prime_time_analysis = process_and_analyze_data(
|
| 245 |
+
df[df['放映时间'].between(pd.to_datetime('14:00:00').time(), pd.to_datetime('21:00:00').time())].copy())
|
| 246 |
+
|
| 247 |
+
if query_tms_for_location:
|
| 248 |
+
with st.spinner("正在关联查询 TMS 服务器..."):
|
| 249 |
+
_, tms_movie_list = fetch_and_process_server_movies()
|
| 250 |
+
full_day_analysis = add_tms_locations_to_analysis(full_day_analysis, tms_movie_list)
|
| 251 |
+
prime_time_analysis = add_tms_locations_to_analysis(prime_time_analysis, tms_movie_list)
|
| 252 |
+
if '影片所在影厅位置' in full_day_analysis.columns:
|
| 253 |
+
cols_full = full_day_analysis.columns.tolist()
|
| 254 |
+
cols_full.insert(1, cols_full.pop(cols_full.index('影片所在影厅位置')))
|
| 255 |
+
full_day_analysis = full_day_analysis[cols_full]
|
| 256 |
+
if '影片所在影厅位置' in prime_time_analysis.columns:
|
| 257 |
+
cols_prime = prime_time_analysis.columns.tolist()
|
| 258 |
+
cols_prime.insert(1, cols_prime.pop(cols_prime.index('影片所在影厅位置')))
|
| 259 |
+
prime_time_analysis = prime_time_analysis[cols_prime]
|
| 260 |
+
st.toast("TMS 影片位置关联成功!", icon="🔗")
|
| 261 |
+
|
| 262 |
+
st.markdown("### 全天排片效率分析")
|
| 263 |
+
if not full_day_analysis.empty:
|
| 264 |
+
st.dataframe(
|
| 265 |
+
full_day_analysis.style.format(format_config).apply(style_efficiency, axis=1), # MODIFIED
|
| 266 |
+
use_container_width=True, hide_index=True)
|
| 267 |
+
|
| 268 |
+
st.markdown("#### 黄金时段排片效率分析 (14:00-21:00)")
|
| 269 |
+
if not prime_time_analysis.empty:
|
| 270 |
+
st.dataframe(
|
| 271 |
+
prime_time_analysis.style.format(format_config).apply(style_efficiency, axis=1), # MODIFIED
|
| 272 |
+
use_container_width=True, hide_index=True)
|
| 273 |
+
|
| 274 |
+
# --- Summary Table Creation ---
|
| 275 |
+
if not full_day_analysis.empty:
|
| 276 |
+
st.markdown("### 排片效率汇总")
|
| 277 |
+
# Select and rename columns from full day analysis
|
| 278 |
+
full_day_summary = full_day_analysis.rename(columns={
|
| 279 |
+
'场次': '全部场次',
|
| 280 |
+
'座次效率': '全部座次效率',
|
| 281 |
+
'场次效率': '全部场次效率'
|
| 282 |
+
})
|
| 283 |
+
# Define columns to keep, including the optional TMS location
|
| 284 |
+
full_day_cols_to_keep = ['影片', '票房', '全部场次', '全部座次效率', '全部场次效率']
|
| 285 |
+
if '影片所在影厅位置' in full_day_summary.columns:
|
| 286 |
+
full_day_cols_to_keep.insert(1, '影片所在影厅位置')
|
| 287 |
+
full_day_summary = full_day_summary[full_day_cols_to_keep]
|
| 288 |
+
|
| 289 |
+
# Select and rename columns from prime time analysis
|
| 290 |
+
prime_time_summary = prime_time_analysis.rename(columns={
|
| 291 |
+
'场次': '黄金时段场次',
|
| 292 |
+
'座次效率': '黄金时段座次效率',
|
| 293 |
+
'场次效率': '黄金时段场次效率'
|
| 294 |
+
})[['影片', '黄金时段场次', '黄金时段座次效率', '黄金时段场次效率']]
|
| 295 |
+
|
| 296 |
+
# Merge the two dataframes
|
| 297 |
+
summary_df = pd.merge(full_day_summary, prime_time_summary, on='影片', how='left')
|
| 298 |
+
|
| 299 |
+
# Fill NaN values for movies that have no prime time sessions
|
| 300 |
+
summary_df.fillna(0, inplace=True)
|
| 301 |
+
|
| 302 |
+
# Ensure data types are correct after filling NaNs
|
| 303 |
+
summary_df['黄金时段场次'] = summary_df['黄金时段场次'].astype(int)
|
| 304 |
+
|
| 305 |
+
# Define format for the summary table
|
| 306 |
+
summary_format_config = {
|
| 307 |
+
'票房': '{:,.2f}',
|
| 308 |
+
'全部场次': '{:,.0f}',
|
| 309 |
+
'黄金时段场次': '{:,.0f}',
|
| 310 |
+
'全部座次效率': '{:.2f}',
|
| 311 |
+
'全部场次效率': '{:.2f}',
|
| 312 |
+
'黄金时段座次效率': '{:.2f}',
|
| 313 |
+
'黄金时段场次效率': '{:.2f}'
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
st.dataframe(
|
| 317 |
+
summary_df.style.format(summary_format_config).apply(style_summary_efficiency, axis=1), # MODIFIED
|
| 318 |
+
use_container_width=True,
|
| 319 |
+
hide_index=True
|
| 320 |
+
)
|
| 321 |
+
|
| 322 |
+
if not full_day_analysis.empty:
|
| 323 |
+
st.markdown("##### 复制当日排片列表")
|
| 324 |
+
movie_titles = full_day_analysis['影片'].tolist()
|
| 325 |
+
formatted_titles = ''.join([f'《{title}》' for title in movie_titles])
|
| 326 |
+
st.code(formatted_titles, language='text')
|
| 327 |
+
|
| 328 |
+
except Exception as e:
|
| 329 |
+
st.error(f"处理文件时出错: {e}")
|
| 330 |
+
|
| 331 |
+
st.divider()
|
| 332 |
+
st.markdown("### TMS 服务器影片内容查询")
|
| 333 |
+
if st.button('点击查询 TMS 服务器'):
|
| 334 |
+
with st.spinner("正在从 TMS 服务器获取数据中..."):
|
| 335 |
+
try:
|
| 336 |
+
halls_data, movie_list_sorted = fetch_and_process_server_movies()
|
| 337 |
+
st.toast("TMS 服务器数据获取成功!", icon="🎉")
|
| 338 |
+
|
| 339 |
+
st.markdown("#### 按影片查看所在影厅")
|
| 340 |
+
view2_data = [{'影片名称': item['assert_name'],
|
| 341 |
+
'所在影厅': " ".join(sorted([get_circled_number(h) for h in item['halls']])),
|
| 342 |
+
'文件名': item['content_name'], '时长': format_play_time(item['play_time'])} for item in
|
| 343 |
+
movie_list_sorted]
|
| 344 |
+
df_view2 = pd.DataFrame(view2_data)
|
| 345 |
+
st.dataframe(df_view2, hide_index=True, use_container_width=True)
|
| 346 |
+
|
| 347 |
+
st.markdown("#### 按影厅查看影片内容")
|
| 348 |
+
hall_tabs = st.tabs(halls_data.keys())
|
| 349 |
+
for tab, hall_name in zip(hall_tabs, halls_data.keys()):
|
| 350 |
+
with tab:
|
| 351 |
+
view1_data_for_tab = [{'影片名称': item['details']['assert_name'], '所在影厅': " ".join(
|
| 352 |
+
sorted([get_circled_number(h) for h in item['details']['halls']])),
|
| 353 |
+
'文件名': item['content_name'],
|
| 354 |
+
'时长': format_play_time(item['details']['play_time'])} for item in
|
| 355 |
+
halls_data[hall_name]]
|
| 356 |
+
df_view1_tab = pd.DataFrame(view1_data_for_tab)
|
| 357 |
+
st.dataframe(df_view1_tab, hide_index=True, use_container_width=True)
|
| 358 |
+
|
| 359 |
+
except Exception as e:
|
| 360 |
+
st.error(f"查询服务器时出错: {e}")
|