Ethscriptions commited on
Commit
892d7ed
·
verified ·
1 Parent(s): d99d789

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -6,7 +6,7 @@ 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"
@@ -64,7 +64,7 @@ def process_schedule(file):
64
 
65
  valid_times = (
66
  ((df['time_for_comparison'] >= datetime.combine(base_date, business_start.time())) &
67
- (df['time_for_comparison'] <= datetime.combine(base_date + timedelta(days=1), business_end.time())))
68
  )
69
 
70
  df = df[valid_times]
@@ -127,24 +127,25 @@ 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, hspace=0.1, wspace=0.1, height_ratios=[1] * num_rows + [0.2])
 
 
132
 
133
  # 计算最大字符数
134
  max_char_count = 0
135
  for hall, end_time in data.values:
136
- # 清理LaTeX标记并计算实际显示字符数
137
  clean_hall = re.sub(r'\$.*?\$', '#', hall)
138
  clean_text = f"{clean_hall}{end_time}"
139
  current_count = len(clean_text)
140
  max_char_count = max(max_char_count, current_count)
141
 
142
- # 动态计算基础字号(确保最长文本占90%宽度)
143
  cell_width_inches = 5.83 / 3 # 每列宽度(A5横向)
144
- available_width = cell_width_inches * 0.9 * 72 # 转换为点数(1英寸=72点)
145
- avg_char_width = 0.6 # 经验值(Arial字体字符宽度系数)
146
  base_fontsize = available_width / (max_char_count * avg_char_width)
147
- base_fontsize = min(30, base_fontsize) # 最大不超过30pt
148
 
149
  # 填充数据
150
  data_values = data.values.tolist()
@@ -168,18 +169,22 @@ def create_print_layout(data, title, date_str):
168
 
169
  ax = plt.subplot(gs[row, col])
170
 
 
 
 
 
171
  for spine in ax.spines.values():
172
  spine.set_color(BORDER_COLOR)
173
  spine.set_linewidth(0.5)
174
 
 
175
  ax.text(0.5, 0.5, f"{hall}{end_time}",
176
- fontsize=base_fontsize,
177
  fontweight='bold',
178
  ha='center',
179
- va='center')
 
180
 
181
- ax.set_xlim(-0.02, 1.02)
182
- ax.set_ylim(-0.02, 1.02)
183
  ax.set_xticks([])
184
  ax.set_yticks([])
185
 
 
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"
 
64
 
65
  valid_times = (
66
  ((df['time_for_comparison'] >= datetime.combine(base_date, business_start.time())) &
67
+ (df['time_for_comparison'] <= datetime.combine(base_date + timedelta(days=1), business_end.time()))
68
  )
69
 
70
  df = df[valid_times]
 
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()
 
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
+ # 添加文本(字号缩小5%)
181
  ax.text(0.5, 0.5, f"{hall}{end_time}",
182
+ fontsize=base_fontsize*0.95,
183
  fontweight='bold',
184
  ha='center',
185
+ va='center',
186
+ transform=ax.transAxes)
187
 
 
 
188
  ax.set_xticks([])
189
  ax.set_yticks([])
190