Ethscriptions commited on
Commit
01ac828
·
verified ·
1 Parent(s): 15c01f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -3,7 +3,7 @@ import pandas as pd
3
  import numpy as np
4
 
5
  # 设置页面布局为宽屏模式,并设置页面标题
6
- st.set_page_config(layout="wide", page_title="影城效率分析 - 最终版")
7
 
8
 
9
  def clean_movie_title(title):
@@ -20,16 +20,27 @@ def clean_movie_title(title):
20
  def style_efficiency(row):
21
  """
22
  根据效率值高亮特定行。
23
- 如果座次效率或场次效率 < 0.5 > 1.5,则高亮为淡黄色。
24
  """
25
- highlight = 'background-color: #FFFFE0;'
 
 
26
  default = ''
 
 
 
 
 
27
  seat_efficiency = row.get('座次效率', 0)
28
  session_efficiency = row.get('场次效率', 0)
29
- if (seat_efficiency < 0.5 or seat_efficiency > 1.5 or
30
- session_efficiency < 0.5 or session_efficiency > 1.5):
31
- return [highlight] * len(row)
32
- return [default] * len(row)
 
 
 
 
33
 
34
 
35
  def process_and_analyze_data(df):
@@ -71,7 +82,7 @@ def process_and_analyze_data(df):
71
 
72
  # --- Streamlit 用户界面 ---
73
 
74
- st.title('排片效率分析工具')
75
  st.write("上传 `影片映出日累计报表.xlsx` 文件。")
76
 
77
  uploaded_file = st.file_uploader("请在此处上传 Excel 文件", type=['xlsx', 'xls', 'csv'])
@@ -114,13 +125,14 @@ if uploaded_file is not None:
114
  st.dataframe(
115
  full_day_analysis.style.format(format_config).apply(style_efficiency, axis=1).hide(axis="index"),
116
  height=table_height,
117
- use_container_width=True
 
118
  )
119
  else:
120
  st.warning("全天数据不足,无法生成分析报告。")
121
 
122
  # --- 2. 黄金时段数据分析 ---
123
- st.header("黄金时段排片效率分析")
124
 
125
  start_time = pd.to_datetime('14:00:00').time()
126
  end_time = pd.to_datetime('21:00:00').time()
@@ -133,7 +145,8 @@ if uploaded_file is not None:
133
  st.dataframe(
134
  prime_time_analysis.style.format(format_config).apply(style_efficiency, axis=1).hide(axis="index"),
135
  height=table_height_prime,
136
- use_container_width=True
 
137
  )
138
  else:
139
  st.warning("黄金时段内没有有效场次数据,无法生成分析报告。")
 
3
  import numpy as np
4
 
5
  # 设置页面布局为宽屏模式,并设置页面标题
6
+ st.set_page_config(layout="wide", page_title="影城排片效率分析")
7
 
8
 
9
  def clean_movie_title(title):
 
20
  def style_efficiency(row):
21
  """
22
  根据效率值高亮特定行。
23
+ 高于 1.5 的淡绿色,低于 0.5 的淡红色。
24
  """
25
+ # 定义颜色
26
+ green = 'background-color: #E6F5E6;' # 淡绿色
27
+ red = 'background-color: #FFE5E5;' # 淡红色
28
  default = ''
29
+
30
+ # 初始化样式列表,长度与行内元素数量一致
31
+ styles = [default] * len(row)
32
+
33
+ # 获取效率值
34
  seat_efficiency = row.get('座次效率', 0)
35
  session_efficiency = row.get('场次效率', 0)
36
+
37
+ # 判断并应用样式
38
+ if seat_efficiency > 1.5 or session_efficiency > 1.5:
39
+ styles = [green] * len(row)
40
+ elif seat_efficiency < 0.5 or session_efficiency < 0.5:
41
+ styles = [red] * len(row)
42
+
43
+ return styles
44
 
45
 
46
  def process_and_analyze_data(df):
 
82
 
83
  # --- Streamlit 用户界面 ---
84
 
85
+ st.title('影城排片效率分析工具')
86
  st.write("上传 `影片映出日累计报表.xlsx` 文件。")
87
 
88
  uploaded_file = st.file_uploader("请在此处上传 Excel 文件", type=['xlsx', 'xls', 'csv'])
 
125
  st.dataframe(
126
  full_day_analysis.style.format(format_config).apply(style_efficiency, axis=1).hide(axis="index"),
127
  height=table_height,
128
+ use_container_width=True,
129
+ hide_index=True
130
  )
131
  else:
132
  st.warning("全天数据不足,无法生成分析报告。")
133
 
134
  # --- 2. 黄金时段数据分析 ---
135
+ st.header("黄金时段排片效率分析 (14:00-21:00)")
136
 
137
  start_time = pd.to_datetime('14:00:00').time()
138
  end_time = pd.to_datetime('21:00:00').time()
 
145
  st.dataframe(
146
  prime_time_analysis.style.format(format_config).apply(style_efficiency, axis=1).hide(axis="index"),
147
  height=table_height_prime,
148
+ use_container_width=True,
149
+ hide_index = True
150
  )
151
  else:
152
  st.warning("黄金时段内没有有效场次数据,无法生成分析报告。")