Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,6 @@ import io
|
|
6 |
import base64
|
7 |
import matplotlib.gridspec as gridspec
|
8 |
import math
|
9 |
-
import re
|
10 |
|
11 |
SPLIT_TIME = "17:30"
|
12 |
BUSINESS_START = "09:30"
|
@@ -27,8 +26,8 @@ def process_schedule(file):
|
|
27 |
# 清理数据
|
28 |
df = df.dropna(subset=['Hall', 'StartTime', 'EndTime'])
|
29 |
|
30 |
-
#
|
31 |
-
df['Hall'] = df['Hall'].str.extract(r'(\d+)号').astype(str) +
|
32 |
|
33 |
# 保存原始时间字符串用于诊断
|
34 |
df['original_end'] = df['EndTime']
|
@@ -64,7 +63,7 @@ def process_schedule(file):
|
|
64 |
|
65 |
valid_times = (
|
66 |
((df['time_for_comparison'] >= datetime.combine(base_date, business_start.time())) &
|
67 |
-
|
68 |
)
|
69 |
|
70 |
df = df[valid_times]
|
@@ -85,17 +84,18 @@ def process_schedule(file):
|
|
85 |
for part in [part1, part2]:
|
86 |
part['EndTime'] = part['EndTime'].dt.strftime('%-I:%M')
|
87 |
|
88 |
-
#
|
89 |
date_df = pd.read_excel(
|
90 |
file,
|
91 |
-
skiprows=5,
|
92 |
-
nrows=1,
|
93 |
-
usecols=[2],
|
94 |
-
header=None
|
95 |
)
|
96 |
date_cell = date_df.iloc[0, 0]
|
97 |
|
98 |
try:
|
|
|
99 |
if isinstance(date_cell, str):
|
100 |
date_str = datetime.strptime(date_cell, '%Y-%m-%d').strftime('%Y-%m-%d')
|
101 |
else:
|
@@ -114,7 +114,7 @@ def create_print_layout(data, title, date_str):
|
|
114 |
if data.empty:
|
115 |
return None
|
116 |
|
117 |
-
# 设置 A5
|
118 |
fig = plt.figure(figsize=(5.83, 8.27), dpi=300)
|
119 |
plt.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
|
120 |
|
@@ -127,37 +127,24 @@ def create_print_layout(data, title, date_str):
|
|
127 |
num_cols = 3
|
128 |
num_rows = math.ceil(total_items / num_cols)
|
129 |
|
130 |
-
#
|
131 |
-
gs = gridspec.GridSpec(num_rows + 1, num_cols,
|
132 |
-
hspace=0.2, wspace=0.2, # 增加行列间距
|
133 |
-
height_ratios=[1.2] * num_rows + [0.2])
|
134 |
|
135 |
-
|
136 |
-
max_char_count = 0
|
137 |
-
for hall, end_time in data.values:
|
138 |
-
clean_hall = re.sub(r'\$.*?\$', '#', hall)
|
139 |
-
clean_text = f"{clean_hall}{end_time}"
|
140 |
-
current_count = len(clean_text)
|
141 |
-
max_char_count = max(max_char_count, current_count)
|
142 |
|
143 |
-
# 动态计算基础字号(优化计算参数)
|
144 |
-
cell_width_inches = 5.83 / 3 # 每列宽度(A5横向)
|
145 |
-
available_width = cell_width_inches * 0.65 * 72 # 可用宽度减少到65%
|
146 |
-
avg_char_width = 0.8 # 加粗字体宽度系数
|
147 |
-
base_fontsize = available_width / (max_char_count * avg_char_width)
|
148 |
-
base_fontsize = min(26, base_fontsize) # 设置最大字号限制
|
149 |
-
|
150 |
-
# 填充数据
|
151 |
data_values = data.values.tolist()
|
|
|
152 |
while len(data_values) % 3 != 0:
|
153 |
data_values.append(['', ''])
|
154 |
|
|
|
|
|
155 |
sorted_data = [['', '']] * len(data_values)
|
156 |
|
157 |
for i, item in enumerate(data_values):
|
158 |
if item[0] and item[1]:
|
159 |
-
row = i %
|
160 |
-
col = i //
|
161 |
new_index = row * 3 + col
|
162 |
if new_index < len(sorted_data):
|
163 |
sorted_data[new_index] = item
|
@@ -169,21 +156,19 @@ def create_print_layout(data, title, date_str):
|
|
169 |
|
170 |
ax = plt.subplot(gs[row, col])
|
171 |
|
172 |
-
# 设置单元格边界范围(增加内边距)
|
173 |
-
ax.set_xlim(0.1, 0.9) # 左右各留10%边距
|
174 |
-
ax.set_ylim(0.1, 0.9) # 上下各留10%边距
|
175 |
-
|
176 |
for spine in ax.spines.values():
|
177 |
spine.set_color(BORDER_COLOR)
|
178 |
spine.set_linewidth(0.5)
|
179 |
|
180 |
-
|
181 |
-
ax.text(0.5, 0.5,
|
182 |
-
fontsize=base_fontsize
|
183 |
fontweight='bold',
|
184 |
ha='center',
|
185 |
-
va='center'
|
186 |
-
|
|
|
|
|
187 |
|
188 |
ax.set_xticks([])
|
189 |
ax.set_yticks([])
|
@@ -239,4 +224,3 @@ if uploaded_file:
|
|
239 |
st.image(part2_image)
|
240 |
else:
|
241 |
st.info("夜班部分没有数据")
|
242 |
-
|
|
|
6 |
import base64
|
7 |
import matplotlib.gridspec as gridspec
|
8 |
import math
|
|
|
9 |
|
10 |
SPLIT_TIME = "17:30"
|
11 |
BUSINESS_START = "09:30"
|
|
|
26 |
# 清理数据
|
27 |
df = df.dropna(subset=['Hall', 'StartTime', 'EndTime'])
|
28 |
|
29 |
+
# 转换影厅格式为 "#号" 格式
|
30 |
+
df['Hall'] = df['Hall'].str.extract(r'(\d+)号').astype(str) + ' '
|
31 |
|
32 |
# 保存原始时间字符串用于诊断
|
33 |
df['original_end'] = df['EndTime']
|
|
|
63 |
|
64 |
valid_times = (
|
65 |
((df['time_for_comparison'] >= datetime.combine(base_date, business_start.time())) &
|
66 |
+
(df['time_for_comparison'] <= datetime.combine(base_date + timedelta(days=1), business_end.time())))
|
67 |
)
|
68 |
|
69 |
df = df[valid_times]
|
|
|
84 |
for part in [part1, part2]:
|
85 |
part['EndTime'] = part['EndTime'].dt.strftime('%-I:%M')
|
86 |
|
87 |
+
# 关键修改:精确读取C6单元格
|
88 |
date_df = pd.read_excel(
|
89 |
file,
|
90 |
+
skiprows=5, # 跳过前5行(0-4)
|
91 |
+
nrows=1, # 只读1行
|
92 |
+
usecols=[2], # 第三列(C列)
|
93 |
+
header=None # 无表头
|
94 |
)
|
95 |
date_cell = date_df.iloc[0, 0]
|
96 |
|
97 |
try:
|
98 |
+
# 处理不同日期格式
|
99 |
if isinstance(date_cell, str):
|
100 |
date_str = datetime.strptime(date_cell, '%Y-%m-%d').strftime('%Y-%m-%d')
|
101 |
else:
|
|
|
114 |
if data.empty:
|
115 |
return None
|
116 |
|
117 |
+
# 设置 A5 纸张竖向尺寸
|
118 |
fig = plt.figure(figsize=(5.83, 8.27), dpi=300)
|
119 |
plt.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
|
120 |
|
|
|
127 |
num_cols = 3
|
128 |
num_rows = math.ceil(total_items / num_cols)
|
129 |
|
130 |
+
# 创建网格
|
131 |
+
gs = gridspec.GridSpec(num_rows + 1, num_cols, hspace=0.1, wspace=0.1, height_ratios=[1] * num_rows + [0.2])
|
|
|
|
|
132 |
|
133 |
+
base_fontsize = min(30, 265 / num_rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
data_values = data.values.tolist()
|
136 |
+
|
137 |
while len(data_values) % 3 != 0:
|
138 |
data_values.append(['', ''])
|
139 |
|
140 |
+
rows_per_col = math.ceil(len(data_values) / 3)
|
141 |
+
|
142 |
sorted_data = [['', '']] * len(data_values)
|
143 |
|
144 |
for i, item in enumerate(data_values):
|
145 |
if item[0] and item[1]:
|
146 |
+
row = i % rows_per_col
|
147 |
+
col = i // rows_per_col
|
148 |
new_index = row * 3 + col
|
149 |
if new_index < len(sorted_data):
|
150 |
sorted_data[new_index] = item
|
|
|
156 |
|
157 |
ax = plt.subplot(gs[row, col])
|
158 |
|
|
|
|
|
|
|
|
|
159 |
for spine in ax.spines.values():
|
160 |
spine.set_color(BORDER_COLOR)
|
161 |
spine.set_linewidth(0.5)
|
162 |
|
163 |
+
display_text = f"{hall}{end_time}"
|
164 |
+
ax.text(0.5, 0.5, display_text,
|
165 |
+
fontsize=base_fontsize,
|
166 |
fontweight='bold',
|
167 |
ha='center',
|
168 |
+
va='center')
|
169 |
+
|
170 |
+
ax.set_xlim(-0.02, 1.02)
|
171 |
+
ax.set_ylim(-0.02, 1.02)
|
172 |
|
173 |
ax.set_xticks([])
|
174 |
ax.set_yticks([])
|
|
|
224 |
st.image(part2_image)
|
225 |
else:
|
226 |
st.info("夜班部分没有数据")
|
|