Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -114,7 +114,8 @@ def fetch_and_process_server_movies(priority_movie_titles=None):
|
|
114 |
if not content_name: continue
|
115 |
movie_details[content_name] = {
|
116 |
'assert_name': movie.get('ASSERT_NAME'),
|
117 |
-
'halls': sorted([h.get('HALL_NAME') for h in movie.get('HALL_INFO', [])])
|
|
|
118 |
}
|
119 |
|
120 |
# 4. Prepare data for the two display views
|
@@ -137,7 +138,8 @@ def fetch_and_process_server_movies(priority_movie_titles=None):
|
|
137 |
view2_list.append({
|
138 |
'assert_name': details['assert_name'],
|
139 |
'content_name': content_name,
|
140 |
-
'halls': details['halls']
|
|
|
141 |
})
|
142 |
|
143 |
priority_list = [item for item in view2_list if
|
@@ -158,6 +160,19 @@ def get_circled_number(hall_name):
|
|
158 |
return mapping.get(num_str, '')
|
159 |
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
# --- Streamlit Main UI ---
|
162 |
st.title('影城排片效率与内容分析工具')
|
163 |
st.write("上传 `影片映出日累计报表.xlsx` 进行效率分析,或点击下方按钮查询 TMS 服务器影片内容。")
|
@@ -167,7 +182,6 @@ full_day_analysis = pd.DataFrame()
|
|
167 |
|
168 |
if uploaded_file is not None:
|
169 |
try:
|
170 |
-
# Efficiency analysis part
|
171 |
df = pd.read_excel(uploaded_file, skiprows=3, header=None)
|
172 |
df.rename(columns={0: '影片名称', 2: '放映时间', 5: '总人次', 6: '总收入', 7: '座位数'}, inplace=True)
|
173 |
required_cols = ['影片名称', '放映时间', '座位数', '总收入', '总人次']
|
@@ -189,7 +203,7 @@ if uploaded_file is not None:
|
|
189 |
table_height = (len(full_day_analysis) + 1) * 35 + 3
|
190 |
st.dataframe(
|
191 |
full_day_analysis.style.format(format_config).apply(style_efficiency, axis=1).hide(axis="index"),
|
192 |
-
height=table_height, use_container_width=True)
|
193 |
|
194 |
st.markdown("#### 黄金时段排片效率分析 (14:00-21:00)")
|
195 |
start_time, end_time = pd.to_datetime('14:00:00').time(), pd.to_datetime('21:00:00').time()
|
@@ -199,7 +213,7 @@ if uploaded_file is not None:
|
|
199 |
table_height_prime = (len(prime_time_analysis) + 1) * 35 + 3
|
200 |
st.dataframe(
|
201 |
prime_time_analysis.style.format(format_config).apply(style_efficiency, axis=1).hide(axis="index"),
|
202 |
-
height=table_height_prime, use_container_width=True)
|
203 |
|
204 |
if not full_day_analysis.empty:
|
205 |
st.markdown("##### 复制当日排片列表")
|
@@ -211,36 +225,41 @@ if uploaded_file is not None:
|
|
211 |
st.error(f"处理文件时出错: {e}")
|
212 |
|
213 |
|
214 |
-
# --- New Feature Module ---
|
215 |
st.markdown("### TMS 服务器影片内容查询")
|
216 |
if st.button('点击查询 TMS 服务器'):
|
217 |
-
with st.spinner("正在从 TMS
|
218 |
try:
|
219 |
priority_titles = full_day_analysis['影片'].tolist() if not full_day_analysis.empty else []
|
220 |
halls_data, movie_list_sorted = fetch_and_process_server_movies(priority_titles)
|
221 |
st.toast("TMS 服务器数据获取成功!", icon="🎉")
|
222 |
|
223 |
-
# --- View by Movie (
|
224 |
st.markdown("#### 按影片查看所在影厅")
|
225 |
-
with st.expander("点击展开 / 折叠影片列表", expanded = True):
|
226 |
-
for item in movie_list_sorted:
|
227 |
-
circled_halls = " ".join(sorted([get_circled_number(h) for h in item['halls']]))
|
228 |
-
st.markdown(f"**{item['assert_name']}** - {circled_halls} - `{item['content_name']}`")
|
229 |
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
st.markdown("#### 按影厅查看影片内容")
|
232 |
hall_tabs = st.tabs(halls_data.keys())
|
233 |
for tab, hall_name in zip(hall_tabs, halls_data.keys()):
|
234 |
with tab:
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
st.markdown(f"- **{display_name}** - {circled_halls} - `{content_name}`")
|
244 |
|
245 |
except Exception as e:
|
246 |
-
st.error(f"查询服务器时出错: {e}")
|
|
|
|
|
|
114 |
if not content_name: continue
|
115 |
movie_details[content_name] = {
|
116 |
'assert_name': movie.get('ASSERT_NAME'),
|
117 |
+
'halls': sorted([h.get('HALL_NAME') for h in movie.get('HALL_INFO', [])]),
|
118 |
+
'play_time': movie.get('PLAY_TIME')
|
119 |
}
|
120 |
|
121 |
# 4. Prepare data for the two display views
|
|
|
138 |
view2_list.append({
|
139 |
'assert_name': details['assert_name'],
|
140 |
'content_name': content_name,
|
141 |
+
'halls': details['halls'],
|
142 |
+
'play_time': details['play_time']
|
143 |
})
|
144 |
|
145 |
priority_list = [item for item in view2_list if
|
|
|
160 |
return mapping.get(num_str, '')
|
161 |
|
162 |
|
163 |
+
def format_play_time(time_str):
|
164 |
+
"""Converts HH:MM:SS to total minutes (integer)."""
|
165 |
+
if not time_str or not isinstance(time_str, str):
|
166 |
+
return None
|
167 |
+
try:
|
168 |
+
parts = time_str.split(':')
|
169 |
+
hours = int(parts[0])
|
170 |
+
minutes = int(parts[1])
|
171 |
+
return hours * 60 + minutes
|
172 |
+
except (ValueError, IndexError):
|
173 |
+
return None
|
174 |
+
|
175 |
+
|
176 |
# --- Streamlit Main UI ---
|
177 |
st.title('影城排片效率与内容分析工具')
|
178 |
st.write("上传 `影片映出日累计报表.xlsx` 进行效率分析,或点击下方按钮查询 TMS 服务器影片内容。")
|
|
|
182 |
|
183 |
if uploaded_file is not None:
|
184 |
try:
|
|
|
185 |
df = pd.read_excel(uploaded_file, skiprows=3, header=None)
|
186 |
df.rename(columns={0: '影片名称', 2: '放映时间', 5: '总人次', 6: '总收入', 7: '座位数'}, inplace=True)
|
187 |
required_cols = ['影片名称', '放映时间', '座位数', '总收入', '总人次']
|
|
|
203 |
table_height = (len(full_day_analysis) + 1) * 35 + 3
|
204 |
st.dataframe(
|
205 |
full_day_analysis.style.format(format_config).apply(style_efficiency, axis=1).hide(axis="index"),
|
206 |
+
height=table_height, use_container_width=True, hide_index = True)
|
207 |
|
208 |
st.markdown("#### 黄金时段排片效率分析 (14:00-21:00)")
|
209 |
start_time, end_time = pd.to_datetime('14:00:00').time(), pd.to_datetime('21:00:00').time()
|
|
|
213 |
table_height_prime = (len(prime_time_analysis) + 1) * 35 + 3
|
214 |
st.dataframe(
|
215 |
prime_time_analysis.style.format(format_config).apply(style_efficiency, axis=1).hide(axis="index"),
|
216 |
+
height=table_height_prime, use_container_width=True, hide_index = True)
|
217 |
|
218 |
if not full_day_analysis.empty:
|
219 |
st.markdown("##### 复制当日排片列表")
|
|
|
225 |
st.error(f"处理文件时出错: {e}")
|
226 |
|
227 |
|
|
|
228 |
st.markdown("### TMS 服务器影片内容查询")
|
229 |
if st.button('点击查询 TMS 服务器'):
|
230 |
+
with st.spinner("正在从 TMS 服务器获取数据中..."):
|
231 |
try:
|
232 |
priority_titles = full_day_analysis['影片'].tolist() if not full_day_analysis.empty else []
|
233 |
halls_data, movie_list_sorted = fetch_and_process_server_movies(priority_titles)
|
234 |
st.toast("TMS 服务器数据获取成功!", icon="🎉")
|
235 |
|
236 |
+
# --- View by Movie (Table Format) ---
|
237 |
st.markdown("#### 按影片查看所在影厅")
|
|
|
|
|
|
|
|
|
238 |
|
239 |
+
view2_data = [{
|
240 |
+
'影片名称': item['assert_name'],
|
241 |
+
'所在影厅': " ".join(sorted([get_circled_number(h) for h in item['halls']])),
|
242 |
+
'文件名': item['content_name'],
|
243 |
+
'时长': format_play_time(item['play_time'])
|
244 |
+
} for item in movie_list_sorted]
|
245 |
+
df_view2 = pd.DataFrame(view2_data)
|
246 |
+
st.dataframe(df_view2, hide_index=True, use_container_width=True)
|
247 |
+
|
248 |
+
# --- View by Hall (Table Format) ---
|
249 |
st.markdown("#### 按影厅查看影片内容")
|
250 |
hall_tabs = st.tabs(halls_data.keys())
|
251 |
for tab, hall_name in zip(hall_tabs, halls_data.keys()):
|
252 |
with tab:
|
253 |
+
view1_data_for_tab = [{
|
254 |
+
'影片名称': item['details']['assert_name'],
|
255 |
+
'所在影厅': " ".join(sorted([get_circled_number(h) for h in item['details']['halls']])),
|
256 |
+
'文件名': item['content_name'],
|
257 |
+
'时长': format_play_time(item['details']['play_time'])
|
258 |
+
} for item in halls_data[hall_name]]
|
259 |
+
df_view1_tab = pd.DataFrame(view1_data_for_tab)
|
260 |
+
st.dataframe(df_view1_tab, hide_index=True, use_container_width=True)
|
|
|
261 |
|
262 |
except Exception as e:
|
263 |
+
st.error(f"查询服务器时出错: {e}")
|
264 |
+
|
265 |
+
|