Spaces:
Running
Running
Commit ·
d2773cd
1
Parent(s): f353d8a
替换为《装修前总控问卷》可打印网页版(静态页面),保留 zhuangxiu.md 备份
Browse files- Alibaba-PuHuiTi-Bold.ttf +0 -3
- Alibaba-PuHuiTi.ttf +0 -3
- AlibabaPuHuiTi-Bold.otf +0 -3
- AlibabaPuHuiTi-Heavy.otf +0 -3
- GenShinGothic-Monospace-Bold.ttf +0 -3
- PingFangSC-Medium.otf +0 -3
- PingFangSC-Semibold.otf +0 -3
- PingFangSC-Ultralight.otf +0 -3
- README.md +14 -8
- SimHei.ttf +0 -3
- SourceHanSansCN-Bold.otf +0 -3
- SourceHanSansCN-Normal.otf +0 -3
- SourceHanSansCN-Regular.otf +0 -3
- SourceHanSansOLD-Bold-2.otf +0 -3
- SourceHanSansOLD-Heavy-2.otf +0 -3
- app.py +0 -0
- app3.py +0 -281
- app4.py +0 -429
- app5.py +0 -459
- index.html +0 -0
- requirements.txt +0 -7
Alibaba-PuHuiTi-Bold.ttf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:8a6cbceb875e00504071b353b35925cc8cb405963e67dc2da4b8ea4f9209d434
|
| 3 |
-
size 9312212
|
|
|
|
|
|
|
|
|
|
|
|
Alibaba-PuHuiTi.ttf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:fb633db41cedc5abc292157a9a78ed97ae58d2e6c056151c50498483042cbb81
|
| 3 |
-
size 9724448
|
|
|
|
|
|
|
|
|
|
|
|
AlibabaPuHuiTi-Bold.otf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:ad6d653f0da8f5da3b04e1ea22e8f28c071573bd4f0ebbf37771d8efb75988fe
|
| 3 |
-
size 6517436
|
|
|
|
|
|
|
|
|
|
|
|
AlibabaPuHuiTi-Heavy.otf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:fef3f9123d7b75e28ff4d7390c59b248d203868091de98c712318d2fd873c56a
|
| 3 |
-
size 1656252
|
|
|
|
|
|
|
|
|
|
|
|
GenShinGothic-Monospace-Bold.ttf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:6c2e1490357ab477c7e9663244689dd365b2aaaffb9ef88a01c6bdaa99cc9250
|
| 3 |
-
size 4952384
|
|
|
|
|
|
|
|
|
|
|
|
PingFangSC-Medium.otf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:8e6a0b3fba3aa759bf84e51f6d52558aa869c7aa9b74e159891175235ede9f63
|
| 3 |
-
size 13089512
|
|
|
|
|
|
|
|
|
|
|
|
PingFangSC-Semibold.otf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:488a6b6e8684ac9ebe7eb915c9bbf39e275a5e8f5348f992c952324fc57cf792
|
| 3 |
-
size 13042764
|
|
|
|
|
|
|
|
|
|
|
|
PingFangSC-Ultralight.otf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:589d68ec2b10a01ed73ce310961141c5bc5c2240f6711038813a8d06d529d36c
|
| 3 |
-
size 13509300
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -1,12 +1,18 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
-
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: 装修前总控问卷
|
| 3 |
+
emoji: 🏠
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: static
|
| 7 |
+
app_file: index.html
|
|
|
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# 装修前总控问卷|广东化州 · 约107㎡ · 18层 · 三房两卫
|
| 12 |
+
|
| 13 |
+
可勾选、可填写、实时自动保存、适合 A4 打印的装修前问题库网页版。
|
| 14 |
+
|
| 15 |
+
- 70 道题、501 个选项,每个选项附「是什么 / 优点 / 缺点 / 参考价格 / 注意事项 / 选择建议」详细解释
|
| 16 |
+
- 填写内容实时保存在浏览器本地,可导出 / 导入答案文件
|
| 17 |
+
- 打印三种版本:完整版、我的选择版、精简版(A4 纵向)
|
| 18 |
+
- 原始问卷备份:`zhuangxiu.md`
|
SimHei.ttf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:c582099366b2d28e578a831887c5b3a5746b849dbbfb4dbf01d35f2911871162
|
| 3 |
-
size 10050868
|
|
|
|
|
|
|
|
|
|
|
|
SourceHanSansCN-Bold.otf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:97e5eff6dd208ccb814726458c8c7ab4b59327c62b9ee8df3440e7e835209ab9
|
| 3 |
-
size 8608184
|
|
|
|
|
|
|
|
|
|
|
|
SourceHanSansCN-Normal.otf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:14ec9d09dad83098938370be17170a747d63084022b05710e3d34b4ddb359091
|
| 3 |
-
size 8364840
|
|
|
|
|
|
|
|
|
|
|
|
SourceHanSansCN-Regular.otf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:14ec9d09dad83098938370be17170a747d63084022b05710e3d34b4ddb359091
|
| 3 |
-
size 8364840
|
|
|
|
|
|
|
|
|
|
|
|
SourceHanSansOLD-Bold-2.otf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:316853e0207394060130020e9b66330e376de10bffdf5ac040f39a84505badc7
|
| 3 |
-
size 18426000
|
|
|
|
|
|
|
|
|
|
|
|
SourceHanSansOLD-Heavy-2.otf
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:271561468709b0e6a66e1d56731cca9f8c2e7c2c8bc9cab9e8c58bf4ffabb4c2
|
| 3 |
-
size 19681272
|
|
|
|
|
|
|
|
|
|
|
|
app.py
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app3.py
DELETED
|
@@ -1,281 +0,0 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import streamlit as st
|
| 3 |
-
from datetime import datetime, timedelta
|
| 4 |
-
import matplotlib.pyplot as plt
|
| 5 |
-
import io
|
| 6 |
-
import base64
|
| 7 |
-
import matplotlib.gridspec as gridspec
|
| 8 |
-
import math
|
| 9 |
-
from matplotlib.backends.backend_pdf import PdfPages
|
| 10 |
-
from matplotlib.patches import Rectangle # Replaced FancyBboxPatch
|
| 11 |
-
|
| 12 |
-
# --- Constants ---
|
| 13 |
-
SPLIT_TIME = "17:30"
|
| 14 |
-
BUSINESS_START = "09:30"
|
| 15 |
-
BUSINESS_END = "01:30"
|
| 16 |
-
BORDER_COLOR = '#A9A9A9'
|
| 17 |
-
DATE_COLOR = '#A9A9A9'
|
| 18 |
-
SEQ_COLOR = '#A9A9A9' # Color for the new serial number
|
| 19 |
-
|
| 20 |
-
def process_schedule(file):
|
| 21 |
-
"""处理上传的 Excel 文件,生成排序和分组后的打印内容"""
|
| 22 |
-
try:
|
| 23 |
-
# 读取 Excel,跳过前 8 行
|
| 24 |
-
df = pd.read_excel(file, skiprows=8)
|
| 25 |
-
|
| 26 |
-
# 提取所需列 (G9, H9, J9)
|
| 27 |
-
df = df.iloc[:, [6, 7, 9]] # G, H, J 列
|
| 28 |
-
df.columns = ['Hall', 'StartTime', 'EndTime']
|
| 29 |
-
|
| 30 |
-
# 清理数据
|
| 31 |
-
df = df.dropna(subset=['Hall', 'StartTime', 'EndTime'])
|
| 32 |
-
|
| 33 |
-
# 转换影厅格式为 "#号" 格式
|
| 34 |
-
df['Hall'] = df['Hall'].str.extract(r'(\d+)号').astype(str) + ' '
|
| 35 |
-
|
| 36 |
-
# 保存原始时间字符串用于诊断
|
| 37 |
-
df['original_end'] = df['EndTime']
|
| 38 |
-
|
| 39 |
-
# 转换时间为 datetime 对象
|
| 40 |
-
base_date = datetime.today().date()
|
| 41 |
-
# Using errors='coerce' will turn unparseable times into NaT (Not a Time)
|
| 42 |
-
df['StartTime'] = pd.to_datetime(df['StartTime'], errors='coerce')
|
| 43 |
-
df['EndTime'] = pd.to_datetime(df['EndTime'], errors='coerce')
|
| 44 |
-
df = df.dropna(subset=['StartTime', 'EndTime']) # Drop rows where time conversion failed
|
| 45 |
-
|
| 46 |
-
# 设置基准时间
|
| 47 |
-
business_start_time = datetime.strptime(BUSINESS_START, "%H:%M").time()
|
| 48 |
-
business_end_time = datetime.strptime(BUSINESS_END, "%H:%M").time()
|
| 49 |
-
|
| 50 |
-
# 处理跨天情况:结束时间小于开始时间,则结束时间加一天
|
| 51 |
-
# This logic handles cases like 9:30 AM to 1:30 AM (next day)
|
| 52 |
-
df['EndTime_adjusted'] = df.apply(
|
| 53 |
-
lambda row: row['EndTime'] + timedelta(days=1) if row['EndTime'].time() < row['StartTime'].time() else row['EndTime'],
|
| 54 |
-
axis=1
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
# 按散场时间排序 (using the adjusted time)
|
| 58 |
-
df = df.sort_values('EndTime_adjusted')
|
| 59 |
-
|
| 60 |
-
# 分割数据
|
| 61 |
-
split_dt = datetime.strptime(SPLIT_TIME, "%H:%M").time()
|
| 62 |
-
|
| 63 |
-
part1 = df[df['EndTime_adjusted'].dt.time <= split_dt].copy()
|
| 64 |
-
part2 = df[df['EndTime_adjusted'].dt.time > split_dt].copy()
|
| 65 |
-
|
| 66 |
-
# 格式化时间显示 (use original EndTime for display)
|
| 67 |
-
for part in [part1, part2]:
|
| 68 |
-
part['EndTime_formatted'] = part['EndTime'].dt.strftime('%-I:%M')
|
| 69 |
-
|
| 70 |
-
# 读取日期单元格 C6
|
| 71 |
-
date_df = pd.read_excel(file, skiprows=5, nrows=1, usecols=[2], header=None)
|
| 72 |
-
date_cell = date_df.iloc[0, 0]
|
| 73 |
-
|
| 74 |
-
try:
|
| 75 |
-
if isinstance(date_cell, str):
|
| 76 |
-
# Assuming format like '2023-10-27'
|
| 77 |
-
date_str = datetime.strptime(date_cell, '%Y-%m-%d').strftime('%Y-%m-%d')
|
| 78 |
-
else:
|
| 79 |
-
# Assuming it's a datetime object
|
| 80 |
-
date_str = pd.to_datetime(date_cell).strftime('%Y-%m-%d')
|
| 81 |
-
except:
|
| 82 |
-
date_str = datetime.today().strftime('%Y-%m-%d')
|
| 83 |
-
|
| 84 |
-
return part1[['Hall', 'EndTime_formatted']], part2[['Hall', 'EndTime_formatted']], date_str
|
| 85 |
-
|
| 86 |
-
except Exception as e:
|
| 87 |
-
st.error(f"处理文件时出错: {str(e)}")
|
| 88 |
-
return None, None, None
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
def create_print_layout(data, title, date_str):
|
| 92 |
-
"""
|
| 93 |
-
创建符合新要求的打印布局 (PNG 和 PDF)。
|
| 94 |
-
1. 动态计算边距。
|
| 95 |
-
2. 使用灰色虚线圆点作为单元格边框。
|
| 96 |
-
3. 单元格内容区域为单元格的90%。
|
| 97 |
-
4. 在左上角添加灰色序号。
|
| 98 |
-
"""
|
| 99 |
-
if data.empty:
|
| 100 |
-
return None
|
| 101 |
-
|
| 102 |
-
# --- Constants ---
|
| 103 |
-
A5_WIDTH_IN = 5.83
|
| 104 |
-
A5_HEIGHT_IN = 8.27
|
| 105 |
-
DPI = 300
|
| 106 |
-
NUM_COLS = 3
|
| 107 |
-
|
| 108 |
-
# --- Setup Figure ---
|
| 109 |
-
fig = plt.figure(figsize=(A5_WIDTH_IN, A5_HEIGHT_IN), dpi=DPI)
|
| 110 |
-
|
| 111 |
-
# --- Font Setup ---
|
| 112 |
-
plt.rcParams['font.family'] = 'sans-serif'
|
| 113 |
-
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS', 'Heiti TC', 'sans-serif']
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
# --- Data Preparation ---
|
| 117 |
-
total_items = len(data)
|
| 118 |
-
# Augment data with an original index for numbering
|
| 119 |
-
data_values_with_index = [(i, row) for i, row in enumerate(data.values.tolist())]
|
| 120 |
-
|
| 121 |
-
# Pad data to be a multiple of NUM_COLS
|
| 122 |
-
padded_total = math.ceil(total_items / NUM_COLS) * NUM_COLS
|
| 123 |
-
while len(data_values_with_index) < padded_total:
|
| 124 |
-
data_values_with_index.append((None, ['', '']))
|
| 125 |
-
|
| 126 |
-
num_rows = padded_total // NUM_COLS
|
| 127 |
-
|
| 128 |
-
# --- Layout Calculation (Request 1) ---
|
| 129 |
-
if num_rows > 0:
|
| 130 |
-
# "A5 paper height / num_rows / 4 is the padding for all sides"
|
| 131 |
-
padding_in = (A5_HEIGHT_IN / num_rows / 4)
|
| 132 |
-
# Cap padding to prevent it from being excessively large
|
| 133 |
-
padding_in = min(padding_in, 0.5)
|
| 134 |
-
else:
|
| 135 |
-
padding_in = 0.25 # Default padding if no rows
|
| 136 |
-
|
| 137 |
-
# Convert padding to relative figure coordinates for subplots_adjust
|
| 138 |
-
left_margin = padding_in / A5_WIDTH_IN
|
| 139 |
-
right_margin = 1 - left_margin
|
| 140 |
-
bottom_margin = padding_in / A5_HEIGHT_IN
|
| 141 |
-
top_margin = 1 - bottom_margin
|
| 142 |
-
|
| 143 |
-
# Adjust overall figure margins
|
| 144 |
-
fig.subplots_adjust(left=left_margin, right=right_margin, top=top_margin, bottom=bottom_margin, hspace=0.4, wspace=0.4)
|
| 145 |
-
|
| 146 |
-
# --- Grid & Font Size ---
|
| 147 |
-
gs = gridspec.GridSpec(num_rows + 1, NUM_COLS, height_ratios=[0.2] + [1] * num_rows, figure=fig)
|
| 148 |
-
|
| 149 |
-
if num_rows > 0:
|
| 150 |
-
content_area_height_in = A5_HEIGHT_IN * (top_margin - bottom_margin)
|
| 151 |
-
cell_height_in = content_area_height_in / num_rows * (1 - fig.subplotpars.hspace)
|
| 152 |
-
base_fontsize = min(40, max(10, cell_height_in * 72 * 0.4)) # 72 pt/inch, 40% of cell height
|
| 153 |
-
else:
|
| 154 |
-
base_fontsize = 20
|
| 155 |
-
|
| 156 |
-
# --- Z-Sort (Column-major) Data for Layout ---
|
| 157 |
-
rows_per_col_layout = num_rows
|
| 158 |
-
sorted_data = [(None, ['',''])] * padded_total
|
| 159 |
-
for i, item_tuple in enumerate(data_values_with_index):
|
| 160 |
-
if item_tuple[0] is not None:
|
| 161 |
-
original_data_index = i # Index from the time-sorted list
|
| 162 |
-
row_in_col = original_data_index % rows_per_col_layout
|
| 163 |
-
col_idx = original_data_index // rows_per_col_layout
|
| 164 |
-
new_grid_index = row_in_col * NUM_COLS + col_idx
|
| 165 |
-
if new_grid_index < len(sorted_data):
|
| 166 |
-
sorted_data[new_grid_index] = item_tuple
|
| 167 |
-
|
| 168 |
-
# --- Drawing Logic ---
|
| 169 |
-
for grid_idx, item_tuple in enumerate(sorted_data):
|
| 170 |
-
original_index, (hall, end_time) = item_tuple
|
| 171 |
-
|
| 172 |
-
if original_index is not None:
|
| 173 |
-
row_grid = grid_idx // NUM_COLS + 1 # +1 because date is in row 0
|
| 174 |
-
col_grid = grid_idx % NUM_COLS
|
| 175 |
-
|
| 176 |
-
ax = fig.add_subplot(gs[row_grid, col_grid])
|
| 177 |
-
ax.set_axis_off()
|
| 178 |
-
|
| 179 |
-
# --- Cell Border (Request 2) & Content Area (Request 3) ---
|
| 180 |
-
# Draw a dotted rectangle. Content will be placed inside this.
|
| 181 |
-
# Making the rect slightly smaller creates a visual 90% area.
|
| 182 |
-
cell_border = Rectangle((0.05, 0.05), 0.9, 0.9,
|
| 183 |
-
edgecolor=BORDER_COLOR,
|
| 184 |
-
facecolor='none',
|
| 185 |
-
linestyle=(0, (1, 1.5)), # Dotted line with round caps
|
| 186 |
-
linewidth=1,
|
| 187 |
-
transform=ax.transAxes,
|
| 188 |
-
clip_on=False)
|
| 189 |
-
ax.add_patch(cell_border)
|
| 190 |
-
|
| 191 |
-
# --- Cell Content ---
|
| 192 |
-
display_text = f"{hall}{end_time}"
|
| 193 |
-
ax.text(0.5, 0.5, display_text,
|
| 194 |
-
fontsize=base_fontsize,
|
| 195 |
-
fontweight='bold',
|
| 196 |
-
ha='center', va='center',
|
| 197 |
-
transform=ax.transAxes)
|
| 198 |
-
|
| 199 |
-
# --- Cell Numbering (Request 4) ---
|
| 200 |
-
# Serial number is original_index + 1
|
| 201 |
-
ax.text(0.12, 0.82, str(original_index + 1),
|
| 202 |
-
fontsize=base_fontsize * 0.5,
|
| 203 |
-
color=SEQ_COLOR,
|
| 204 |
-
fontweight='normal',
|
| 205 |
-
ha='center', va='center',
|
| 206 |
-
transform=ax.transAxes)
|
| 207 |
-
|
| 208 |
-
# --- Date Header ---
|
| 209 |
-
ax_date = fig.add_subplot(gs[0, :])
|
| 210 |
-
ax_date.set_axis_off()
|
| 211 |
-
ax_date.text(0, 0.5, f"{date_str} {title}",
|
| 212 |
-
fontsize=base_fontsize * 0.6,
|
| 213 |
-
color=DATE_COLOR,
|
| 214 |
-
fontweight='bold',
|
| 215 |
-
ha='left', va='center',
|
| 216 |
-
transform=ax_date.transAxes)
|
| 217 |
-
|
| 218 |
-
# --- Save to Buffers ---
|
| 219 |
-
# Save PNG
|
| 220 |
-
png_buffer = io.BytesIO()
|
| 221 |
-
fig.savefig(png_buffer, format='png', bbox_inches='tight', pad_inches=0.02)
|
| 222 |
-
png_buffer.seek(0)
|
| 223 |
-
png_base64 = base64.b64encode(png_buffer.getvalue()).decode()
|
| 224 |
-
|
| 225 |
-
# Save PDF
|
| 226 |
-
pdf_buffer = io.BytesIO()
|
| 227 |
-
fig.savefig(pdf_buffer, format='pdf', bbox_inches='tight', pad_inches=0.02)
|
| 228 |
-
pdf_buffer.seek(0)
|
| 229 |
-
pdf_base64 = base64.b64encode(pdf_buffer.getvalue()).decode()
|
| 230 |
-
|
| 231 |
-
plt.close(fig)
|
| 232 |
-
|
| 233 |
-
return {
|
| 234 |
-
'png': f'data:image/png;base64,{png_base64}',
|
| 235 |
-
'pdf': f'data:application/pdf;base64,{pdf_base64}'
|
| 236 |
-
}
|
| 237 |
-
|
| 238 |
-
def display_pdf(base64_pdf):
|
| 239 |
-
"""在Streamlit中嵌入显示PDF"""
|
| 240 |
-
pdf_display = f'<iframe src="{base64_pdf}" width="100%" height="800" type="application/pdf"></iframe>'
|
| 241 |
-
return pdf_display
|
| 242 |
-
|
| 243 |
-
# --- Streamlit UI ---
|
| 244 |
-
st.set_page_config(page_title="散厅时间快捷打印", layout="wide")
|
| 245 |
-
st.title("散厅时间快捷打印")
|
| 246 |
-
|
| 247 |
-
uploaded_file = st.file_uploader("上传【放映场次核对表.xls】文件", type=["xls", "xlsx"])
|
| 248 |
-
|
| 249 |
-
if uploaded_file:
|
| 250 |
-
# Use new column name 'EndTime_formatted' for display
|
| 251 |
-
part1, part2, date_str = process_schedule(uploaded_file)
|
| 252 |
-
if part1 is not None and part2 is not None:
|
| 253 |
-
part1_data_for_layout = part1[['Hall', 'EndTime_formatted']]
|
| 254 |
-
part2_data_for_layout = part2[['Hall', 'EndTime_formatted']]
|
| 255 |
-
|
| 256 |
-
part1_output = create_print_layout(part1_data_for_layout, "A", date_str)
|
| 257 |
-
part2_output = create_print_layout(part2_data_for_layout, "C", date_str)
|
| 258 |
-
|
| 259 |
-
col1, col2 = st.columns(2)
|
| 260 |
-
|
| 261 |
-
with col1:
|
| 262 |
-
st.subheader("白班散场预览(散场时间 ≤ 17:30)")
|
| 263 |
-
if part1_output:
|
| 264 |
-
tab1_1, tab1_2 = st.tabs(["PDF 预览", "PNG 预览"])
|
| 265 |
-
with tab1_1:
|
| 266 |
-
st.markdown(display_pdf(part1_output['pdf']), unsafe_allow_html=True)
|
| 267 |
-
with tab1_2:
|
| 268 |
-
st.image(part1_output['png'])
|
| 269 |
-
else:
|
| 270 |
-
st.info("白班部分没有数据")
|
| 271 |
-
|
| 272 |
-
with col2:
|
| 273 |
-
st.subheader("夜班散场预览(散场时间 > 17:30)")
|
| 274 |
-
if part2_output:
|
| 275 |
-
tab2_1, tab2_2 = st.tabs(["PDF 预览", "PNG 预览"])
|
| 276 |
-
with tab2_1:
|
| 277 |
-
st.markdown(display_pdf(part2_output['pdf']), unsafe_allow_html=True)
|
| 278 |
-
with tab2_2:
|
| 279 |
-
st.image(part2_output['png'])
|
| 280 |
-
else:
|
| 281 |
-
st.info("夜班部分没有数据")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app4.py
DELETED
|
@@ -1,429 +0,0 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import streamlit as st
|
| 3 |
-
import matplotlib.pyplot as plt
|
| 4 |
-
import matplotlib.font_manager as font_manager
|
| 5 |
-
from matplotlib.lines import Line2D
|
| 6 |
-
import io
|
| 7 |
-
import base64
|
| 8 |
-
import os
|
| 9 |
-
from datetime import datetime, timedelta
|
| 10 |
-
from pypinyin import lazy_pinyin, Style
|
| 11 |
-
from matplotlib.backends.backend_pdf import PdfPages
|
| 12 |
-
import matplotlib.gridspec as gridspec
|
| 13 |
-
import math
|
| 14 |
-
|
| 15 |
-
# --- 常量定义 ---
|
| 16 |
-
SPLIT_TIME = "17:00"
|
| 17 |
-
BUSINESS_START = "09:30"
|
| 18 |
-
BUSINESS_END = "01:30"
|
| 19 |
-
BORDER_COLOR = 'grey'
|
| 20 |
-
DATE_COLOR = '#A9A9A9'
|
| 21 |
-
A5_WIDTH_IN = 5.83
|
| 22 |
-
A5_HEIGHT_IN = 8.27
|
| 23 |
-
NUM_COLS = 3
|
| 24 |
-
|
| 25 |
-
# --- 字体加载与文本处理函数 ---
|
| 26 |
-
|
| 27 |
-
def get_font_regular(size=14):
|
| 28 |
-
"""加载思源黑体-常规 (SimHei.ttf)"""
|
| 29 |
-
font_path = "SimHei.ttf"
|
| 30 |
-
if os.path.exists(font_path):
|
| 31 |
-
return font_manager.FontProperties(fname=font_path, size=size)
|
| 32 |
-
else:
|
| 33 |
-
st.warning("警告:未找到字体文件 'SimHei.ttf',LED屏排片表显示可能不正确。")
|
| 34 |
-
return font_manager.FontProperties(family='sans-serif', size=size)
|
| 35 |
-
|
| 36 |
-
def get_font_bold(size=14):
|
| 37 |
-
"""加载思源黑体-粗体 (SourceHanSansOLD-Heavy-2.otf)"""
|
| 38 |
-
font_path = "SourceHanSansOLD-Heavy-2.otf"
|
| 39 |
-
if os.path.exists(font_path):
|
| 40 |
-
return font_manager.FontProperties(fname=font_path, size=size)
|
| 41 |
-
else:
|
| 42 |
-
st.warning("警告:未找到字体文件 'SourceHanSansOLD-Heavy-2.otf',散场时间表显示可能不正确。")
|
| 43 |
-
return font_manager.FontProperties(family='sans-serif', size=size, weight='bold')
|
| 44 |
-
|
| 45 |
-
def get_pinyin_abbr(text):
|
| 46 |
-
"""获取中文文本前两个字的拼音首字母"""
|
| 47 |
-
if not text:
|
| 48 |
-
return ""
|
| 49 |
-
chars = [c for c in text if '\u4e00' <= c <= '\u9fff'][:2]
|
| 50 |
-
if not chars:
|
| 51 |
-
return ""
|
| 52 |
-
pinyin_list = lazy_pinyin(chars, style=Style.FIRST_LETTER)
|
| 53 |
-
return ''.join(pinyin_list).upper()
|
| 54 |
-
|
| 55 |
-
def format_seq(n):
|
| 56 |
-
"""将数字转换为带圈序号 (①, ②, ③...)"""
|
| 57 |
-
if not isinstance(n, int) or n <= 0:
|
| 58 |
-
return str(n)
|
| 59 |
-
circled_chars = "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳" \
|
| 60 |
-
"㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟" \
|
| 61 |
-
"㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
|
| 62 |
-
if 1 <= n <= 50:
|
| 63 |
-
return circled_chars[n - 1]
|
| 64 |
-
return f'({n})'
|
| 65 |
-
|
| 66 |
-
# --- '放映时间核对表' 处理函数 ---
|
| 67 |
-
def process_schedule_led(file):
|
| 68 |
-
"""处理 '放映时间核对表.xls' 文件"""
|
| 69 |
-
try:
|
| 70 |
-
date_df = pd.read_excel(file, header=None, skiprows=7, nrows=1, usecols=[3])
|
| 71 |
-
date_str = pd.to_datetime(date_df.iloc[0, 0]).strftime('%Y-%m-%d')
|
| 72 |
-
base_date = pd.to_datetime(date_str).date()
|
| 73 |
-
except Exception:
|
| 74 |
-
date_str = datetime.today().strftime('%Y-%m-%d')
|
| 75 |
-
base_date = datetime.today().date()
|
| 76 |
-
|
| 77 |
-
try:
|
| 78 |
-
df = pd.read_excel(file, header=9, usecols=[1, 2, 4, 5])
|
| 79 |
-
df.columns = ['Hall', 'StartTime', 'EndTime', 'Movie']
|
| 80 |
-
df['Hall'] = df['Hall'].ffill()
|
| 81 |
-
df.dropna(subset=['StartTime', 'EndTime', 'Movie'], inplace=True)
|
| 82 |
-
df['Hall'] = df['Hall'].astype(str).str.extract(r'(\d+号)')
|
| 83 |
-
df['StartTime_dt'] = pd.to_datetime(df['StartTime'], format='%H:%M', errors='coerce').apply(
|
| 84 |
-
lambda t: t.replace(year=base_date.year, month=base_date.month, day=base_date.day) if pd.notnull(t) else t)
|
| 85 |
-
df['EndTime_dt'] = pd.to_datetime(df['EndTime'], format='%H:%M', errors='coerce').apply(
|
| 86 |
-
lambda t: t.replace(year=base_date.year, month=base_date.month, day=base_date.day) if pd.notnull(t) else t)
|
| 87 |
-
df.loc[df['EndTime_dt'] < df['StartTime_dt'], 'EndTime_dt'] += timedelta(days=1)
|
| 88 |
-
df = df.sort_values(['Hall', 'StartTime_dt'])
|
| 89 |
-
merged_rows = []
|
| 90 |
-
for _, group in df.groupby('Hall'):
|
| 91 |
-
current = None
|
| 92 |
-
for _, row in group.sort_values('StartTime_dt').iterrows():
|
| 93 |
-
if current is None:
|
| 94 |
-
current = row.copy()
|
| 95 |
-
elif row['Movie'] == current['Movie']:
|
| 96 |
-
current['EndTime_dt'] = row['EndTime_dt']
|
| 97 |
-
else:
|
| 98 |
-
merged_rows.append(current)
|
| 99 |
-
current = row.copy()
|
| 100 |
-
if current is not None:
|
| 101 |
-
merged_rows.append(current)
|
| 102 |
-
merged_df = pd.DataFrame(merged_rows)
|
| 103 |
-
merged_df['StartTime_dt'] -= timedelta(minutes=10)
|
| 104 |
-
merged_df['EndTime_dt'] -= timedelta(minutes=5)
|
| 105 |
-
merged_df['Seq'] = merged_df.groupby('Hall').cumcount() + 1
|
| 106 |
-
merged_df['StartTime_str'] = merged_df['StartTime_dt'].dt.strftime('%H:%M')
|
| 107 |
-
merged_df['EndTime_str'] = merged_df['EndTime_dt'].dt.strftime('%H:%M')
|
| 108 |
-
return merged_df[['Hall', 'Seq', 'Movie', 'StartTime_str', 'EndTime_str']], date_str
|
| 109 |
-
except Exception as e:
|
| 110 |
-
st.error(f"处理数据出错: {e}。请检查文件格式是否正确。")
|
| 111 |
-
return None, date_str
|
| 112 |
-
|
| 113 |
-
def create_print_layout_led(data, date_str):
|
| 114 |
-
"""为 '放映时间核对表' 生成打印布局 (使用 Regular 字体)"""
|
| 115 |
-
if data is None or data.empty:
|
| 116 |
-
return None
|
| 117 |
-
A4_width_in, A4_height_in = 8.27, 11.69
|
| 118 |
-
dpi = 300
|
| 119 |
-
total_content_rows = len(data)
|
| 120 |
-
|
| 121 |
-
# --- 已修改部分:如果数据条数小于25条,则按25条计算行高以防止字体过大 ---
|
| 122 |
-
layout_rows = max(total_content_rows, 25)
|
| 123 |
-
totalA = layout_rows + 2
|
| 124 |
-
# --- 修改结束 ---
|
| 125 |
-
|
| 126 |
-
row_height = A4_height_in / totalA
|
| 127 |
-
data = data.reset_index(drop=True)
|
| 128 |
-
data['hall_str'] = '$' + data['Hall'].str.replace('号', '') + '^{\#}$'
|
| 129 |
-
data['seq_str'] = data['Seq'].apply(format_seq)
|
| 130 |
-
data['pinyin_abbr'] = data['Movie'].apply(get_pinyin_abbr)
|
| 131 |
-
data['time_str'] = data['StartTime_str'] + ' - ' + data['EndTime_str']
|
| 132 |
-
|
| 133 |
-
temp_fig = plt.figure(figsize=(A4_width_in, A4_height_in), dpi=dpi)
|
| 134 |
-
renderer = temp_fig.canvas.get_renderer()
|
| 135 |
-
base_font_size_pt = (row_height * 0.9) * 72
|
| 136 |
-
seq_font_size_pt = (row_height * 0.5) * 72
|
| 137 |
-
|
| 138 |
-
def get_col_width_in(series, font_size_pt, is_math=False):
|
| 139 |
-
if series.empty: return 0
|
| 140 |
-
font_prop = get_font_regular(font_size_pt) # 使用 Regular 字体
|
| 141 |
-
longest_str_idx = series.astype(str).str.len().idxmax()
|
| 142 |
-
max_content = str(series.loc[longest_str_idx])
|
| 143 |
-
text_width_px, _, _ = renderer.get_text_width_height_descent(max_content, font_prop, ismath=is_math)
|
| 144 |
-
return (text_width_px / dpi) * 1.1
|
| 145 |
-
|
| 146 |
-
margin_col_width = row_height
|
| 147 |
-
hall_col_width = get_col_width_in(data['hall_str'], base_font_size_pt, is_math=True)
|
| 148 |
-
seq_col_width = get_col_width_in(data['seq_str'], seq_font_size_pt)
|
| 149 |
-
pinyin_col_width = get_col_width_in(data['pinyin_abbr'], base_font_size_pt)
|
| 150 |
-
time_col_width = get_col_width_in(data['time_str'], base_font_size_pt)
|
| 151 |
-
movie_col_width = A4_width_in - (
|
| 152 |
-
margin_col_width * 2 + hall_col_width + seq_col_width + pinyin_col_width + time_col_width)
|
| 153 |
-
plt.close(temp_fig)
|
| 154 |
-
|
| 155 |
-
col_widths = {'hall': hall_col_width, 'seq': seq_col_width, 'movie': movie_col_width, 'pinyin': pinyin_col_width,
|
| 156 |
-
'time': time_col_width}
|
| 157 |
-
col_x_starts = {}
|
| 158 |
-
current_x = margin_col_width
|
| 159 |
-
for col_name in ['hall', 'seq', 'movie', 'pinyin', 'time']:
|
| 160 |
-
col_x_starts[col_name] = current_x
|
| 161 |
-
current_x += col_widths[col_name]
|
| 162 |
-
|
| 163 |
-
def draw_figure(fig, ax):
|
| 164 |
-
renderer = fig.canvas.get_renderer()
|
| 165 |
-
for col_name in ['hall', 'seq', 'movie', 'pinyin']:
|
| 166 |
-
x_line = col_x_starts[col_name] + col_widths[col_name]
|
| 167 |
-
line_top_y, line_bottom_y = A4_height_in - row_height, row_height
|
| 168 |
-
ax.add_line(Line2D([x_line, x_line], [line_bottom_y, line_top_y], color='gray', linestyle=':', linewidth=0.5))
|
| 169 |
-
|
| 170 |
-
last_hall_drawn = None
|
| 171 |
-
for i, row in data.iterrows():
|
| 172 |
-
y_bottom = A4_height_in - (i + 2) * row_height
|
| 173 |
-
y_center = y_bottom + row_height / 2
|
| 174 |
-
|
| 175 |
-
if row['Hall'] != last_hall_drawn:
|
| 176 |
-
ax.text(col_x_starts['hall'] + col_widths['hall'] / 2, y_center, row['hall_str'],
|
| 177 |
-
fontproperties=get_font_regular(base_font_size_pt), ha='center', va='center')
|
| 178 |
-
last_hall_drawn = row['Hall']
|
| 179 |
-
|
| 180 |
-
ax.text(col_x_starts['seq'] + col_widths['seq'] / 2, y_center, row['seq_str'],
|
| 181 |
-
fontproperties=get_font_regular(seq_font_size_pt), ha='center', va='center')
|
| 182 |
-
ax.text(col_x_starts['pinyin'] + col_widths['pinyin'] / 2, y_center, row['pinyin_abbr'],
|
| 183 |
-
fontproperties=get_font_regular(base_font_size_pt), ha='center', va='center')
|
| 184 |
-
ax.text(col_x_starts['time'] + col_widths['time'] / 2, y_center, row['time_str'],
|
| 185 |
-
fontproperties=get_font_regular(base_font_size_pt), ha='center', va='center')
|
| 186 |
-
|
| 187 |
-
movie_font_size = base_font_size_pt
|
| 188 |
-
movie_font_prop = get_font_regular(movie_font_size)
|
| 189 |
-
text_w_px, _, _ = renderer.get_text_width_height_descent(row['Movie'], movie_font_prop, ismath=False)
|
| 190 |
-
text_w_in = text_w_px / dpi
|
| 191 |
-
max_width_in = col_widths['movie'] * 0.9
|
| 192 |
-
|
| 193 |
-
if text_w_in > max_width_in:
|
| 194 |
-
movie_font_size *= (max_width_in / text_w_in)
|
| 195 |
-
movie_font_prop = get_font_regular(movie_font_size)
|
| 196 |
-
|
| 197 |
-
ax.text(col_x_starts['movie'] + 0.05, y_center, row['Movie'], fontproperties=movie_font_prop, ha='left', va='center')
|
| 198 |
-
|
| 199 |
-
is_last_in_hall = (i == len(data) - 1) or (row['Hall'] != data.loc[i + 1, 'Hall'])
|
| 200 |
-
line_start_x = margin_col_width
|
| 201 |
-
line_end_x = A4_width_in - margin_col_width
|
| 202 |
-
if is_last_in_hall:
|
| 203 |
-
ax.add_line(Line2D([line_start_x, line_end_x], [y_bottom, y_bottom], color='black', linestyle='-', linewidth=0.8))
|
| 204 |
-
else:
|
| 205 |
-
ax.add_line(Line2D([line_start_x, line_end_x], [y_bottom, y_bottom], color='gray', linestyle=':', linewidth=0.5))
|
| 206 |
-
|
| 207 |
-
outputs = {}
|
| 208 |
-
for format_type in ['png', 'pdf']:
|
| 209 |
-
fig = plt.figure(figsize=(A4_width_in, A4_height_in), dpi=dpi)
|
| 210 |
-
ax = fig.add_axes([0, 0, 1, 1])
|
| 211 |
-
ax.set_axis_off()
|
| 212 |
-
ax.set_xlim(0, A4_width_in)
|
| 213 |
-
ax.set_ylim(0, A4_height_in)
|
| 214 |
-
ax.text(margin_col_width, A4_height_in - (row_height / 2), date_str,
|
| 215 |
-
fontproperties=get_font_regular(10), color='#A9A9A9', ha='left', va='center')
|
| 216 |
-
|
| 217 |
-
draw_figure(fig, ax)
|
| 218 |
-
|
| 219 |
-
buf = io.BytesIO()
|
| 220 |
-
fig.savefig(buf, format=format_type, dpi=dpi, bbox_inches='tight', pad_inches=0)
|
| 221 |
-
buf.seek(0)
|
| 222 |
-
data_uri = base64.b64encode(buf.getvalue()).decode()
|
| 223 |
-
mime_type = 'image/png' if format_type == 'png' else 'application/pdf'
|
| 224 |
-
outputs[format_type] = f"data:{mime_type};base64,{data_uri}"
|
| 225 |
-
plt.close(fig)
|
| 226 |
-
|
| 227 |
-
return outputs
|
| 228 |
-
|
| 229 |
-
# --- '放映场次核对表' 处理函数 ---
|
| 230 |
-
def process_schedule_times(file):
|
| 231 |
-
"""处理 '放映场次核对表.xls' 文件"""
|
| 232 |
-
try:
|
| 233 |
-
df = pd.read_excel(file, skiprows=8)
|
| 234 |
-
df = df.iloc[:, [6, 7, 9]]
|
| 235 |
-
df.columns = ['Hall', 'StartTime', 'EndTime']
|
| 236 |
-
df = df.dropna(subset=['Hall', 'StartTime', 'EndTime'])
|
| 237 |
-
df['Hall'] = df['Hall'].str.extract(r'(\d+)号').astype(str) + ' '
|
| 238 |
-
base_date = datetime.today().date()
|
| 239 |
-
df['StartTime'] = pd.to_datetime(df['StartTime'])
|
| 240 |
-
df['EndTime'] = pd.to_datetime(df['EndTime'])
|
| 241 |
-
|
| 242 |
-
business_start = datetime.strptime(f"{base_date} {BUSINESS_START}", "%Y-%m-%d %H:%M")
|
| 243 |
-
business_end = datetime.strptime(f"{base_date} {BUSINESS_END}", "%Y-%m-%d %H:%M")
|
| 244 |
-
if business_end < business_start:
|
| 245 |
-
business_end += timedelta(days=1)
|
| 246 |
-
|
| 247 |
-
for idx, row in df.iterrows():
|
| 248 |
-
end_time = row['EndTime']
|
| 249 |
-
if end_time.hour < 9:
|
| 250 |
-
df.at[idx, 'EndTime'] = end_time + timedelta(days=1)
|
| 251 |
-
if row['StartTime'].hour >= 21 and end_time.hour < 9:
|
| 252 |
-
df.at[idx, 'EndTime'] = end_time + timedelta(days=1)
|
| 253 |
-
|
| 254 |
-
df['time_for_comparison'] = df['EndTime'].apply(lambda x: datetime.combine(base_date, x.time()))
|
| 255 |
-
df.loc[df['time_for_comparison'].dt.hour < 9, 'time_for_comparison'] += timedelta(days=1)
|
| 256 |
-
|
| 257 |
-
valid_times = (((df['time_for_comparison'] >= datetime.combine(base_date, business_start.time())) &
|
| 258 |
-
(df['time_for_comparison'] <= datetime.combine(base_date + timedelta(days=1), business_end.time()))))
|
| 259 |
-
df = df[valid_times]
|
| 260 |
-
|
| 261 |
-
df = df.sort_values('EndTime')
|
| 262 |
-
split_time = datetime.strptime(f"{base_date} {SPLIT_TIME}", "%Y-%m-%d %H:%M")
|
| 263 |
-
split_time_for_comparison = df['time_for_comparison'].apply(lambda x: datetime.combine(base_date, split_time.time()))
|
| 264 |
-
|
| 265 |
-
part1 = df[df['time_for_comparison'] <= split_time_for_comparison].copy()
|
| 266 |
-
part2 = df[df['time_for_comparison'] > split_time_for_comparison].copy()
|
| 267 |
-
|
| 268 |
-
for part in [part1, part2]:
|
| 269 |
-
part['EndTime'] = part['EndTime'].dt.strftime('%-H:%M')
|
| 270 |
-
|
| 271 |
-
date_df = pd.read_excel(file, skiprows=5, nrows=1, usecols=[2], header=None)
|
| 272 |
-
date_cell = date_df.iloc[0, 0]
|
| 273 |
-
try:
|
| 274 |
-
if isinstance(date_cell, str):
|
| 275 |
-
date_str = datetime.strptime(date_cell, '%Y-%m-%d').strftime('%Y-%m-%d')
|
| 276 |
-
else:
|
| 277 |
-
date_str = pd.to_datetime(date_cell).strftime('%Y-%m-%d')
|
| 278 |
-
except:
|
| 279 |
-
date_str = datetime.today().strftime('%Y-%m-%d')
|
| 280 |
-
|
| 281 |
-
return part1[['Hall', 'EndTime']], part2[['Hall', 'EndTime']], date_str
|
| 282 |
-
except Exception as e:
|
| 283 |
-
st.error(f"处理文件出错: {str(e)}")
|
| 284 |
-
return None, None, None
|
| 285 |
-
|
| 286 |
-
def create_print_layout_times(data, title, date_str):
|
| 287 |
-
"""为 '放映场次核对表' 生成打印布局 (使用 Bold 字体)"""
|
| 288 |
-
if data.empty:
|
| 289 |
-
return None
|
| 290 |
-
|
| 291 |
-
def generate_figure():
|
| 292 |
-
total_items = len(data)
|
| 293 |
-
num_rows = math.ceil(total_items / NUM_COLS) if total_items > 0 else 1
|
| 294 |
-
date_header_height_in = 0.3
|
| 295 |
-
data_area_height_in = A5_HEIGHT_IN - date_header_height_in
|
| 296 |
-
cell_width_in = A5_WIDTH_IN / NUM_COLS
|
| 297 |
-
cell_height_in = data_area_height_in / num_rows
|
| 298 |
-
cell_width_pt = cell_width_in * 72
|
| 299 |
-
cell_height_pt = cell_height_in * 72
|
| 300 |
-
target_text_width_pt = cell_width_pt * 0.9
|
| 301 |
-
fontsize_from_width = target_text_width_pt / (8 * 0.6)
|
| 302 |
-
fontsize_from_height = cell_height_pt * 0.8
|
| 303 |
-
base_fontsize = min(fontsize_from_width, fontsize_from_height)
|
| 304 |
-
|
| 305 |
-
fig = plt.figure(figsize=(A5_WIDTH_IN, A5_HEIGHT_IN), dpi=300)
|
| 306 |
-
fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
|
| 307 |
-
|
| 308 |
-
gs = gridspec.GridSpec(
|
| 309 |
-
num_rows + 1, NUM_COLS,
|
| 310 |
-
hspace=0, wspace=0,
|
| 311 |
-
height_ratios=[date_header_height_in] + [cell_height_in] * num_rows,
|
| 312 |
-
figure=fig)
|
| 313 |
-
|
| 314 |
-
data_values = data.values.tolist()
|
| 315 |
-
while len(data_values) % NUM_COLS != 0:
|
| 316 |
-
data_values.append(['', ''])
|
| 317 |
-
|
| 318 |
-
rows_per_col_layout = math.ceil(len(data_values) / NUM_COLS)
|
| 319 |
-
sorted_data = [['', '']] * len(data_values)
|
| 320 |
-
for i, item in enumerate(data_values):
|
| 321 |
-
if item[0] and item[1]:
|
| 322 |
-
row_in_col = i % rows_per_col_layout
|
| 323 |
-
col_idx = i // rows_per_col_layout
|
| 324 |
-
new_index = row_in_col * NUM_COLS + col_idx
|
| 325 |
-
if new_index < len(sorted_data):
|
| 326 |
-
sorted_data[new_index] = item
|
| 327 |
-
|
| 328 |
-
for idx, (hall, end_time) in enumerate(sorted_data):
|
| 329 |
-
if hall and end_time:
|
| 330 |
-
row_grid = idx // NUM_COLS + 1
|
| 331 |
-
col_grid = idx % NUM_COLS
|
| 332 |
-
ax = fig.add_subplot(gs[row_grid, col_grid])
|
| 333 |
-
for spine in ax.spines.values():
|
| 334 |
-
spine.set_visible(True)
|
| 335 |
-
spine.set_linestyle((0, (1, 2)))
|
| 336 |
-
spine.set_color(BORDER_COLOR)
|
| 337 |
-
spine.set_linewidth(0.75)
|
| 338 |
-
|
| 339 |
-
display_text = f"{hall}{end_time}"
|
| 340 |
-
ax.text(0.5, 0.5, display_text,
|
| 341 |
-
fontproperties=get_font_bold(base_fontsize), # 使用 Bold 字体
|
| 342 |
-
ha='center', va='center',
|
| 343 |
-
transform=ax.transAxes)
|
| 344 |
-
ax.set_xticks([])
|
| 345 |
-
ax.set_yticks([])
|
| 346 |
-
ax.set_facecolor('none')
|
| 347 |
-
|
| 348 |
-
ax_date = fig.add_subplot(gs[0, :])
|
| 349 |
-
ax_date.text(0.01, 0.5, f"{date_str} {title}",
|
| 350 |
-
fontproperties=get_font_bold(base_fontsize * 0.5), # 使用 Bold 字体
|
| 351 |
-
color=DATE_COLOR,
|
| 352 |
-
ha='left', va='center',
|
| 353 |
-
transform=ax_date.transAxes)
|
| 354 |
-
ax_date.set_axis_off()
|
| 355 |
-
ax_date.set_facecolor('none')
|
| 356 |
-
|
| 357 |
-
return fig
|
| 358 |
-
|
| 359 |
-
fig_for_output = generate_figure()
|
| 360 |
-
png_buffer = io.BytesIO()
|
| 361 |
-
fig_for_output.savefig(png_buffer, format='png')
|
| 362 |
-
png_buffer.seek(0)
|
| 363 |
-
png_base64 = base64.b64encode(png_buffer.getvalue()).decode()
|
| 364 |
-
|
| 365 |
-
pdf_buffer = io.BytesIO()
|
| 366 |
-
with PdfPages(pdf_buffer) as pdf:
|
| 367 |
-
pdf.savefig(fig_for_output)
|
| 368 |
-
pdf_buffer.seek(0)
|
| 369 |
-
pdf_base64 = base64.b64encode(pdf_buffer.getvalue()).decode()
|
| 370 |
-
|
| 371 |
-
plt.close(fig_for_output)
|
| 372 |
-
return {'png': f'data:image/png;base64,{png_base64}', 'pdf': f'data:application/pdf;base64,{pdf_base64}'}
|
| 373 |
-
|
| 374 |
-
def display_pdf(base64_pdf):
|
| 375 |
-
"""在Streamlit中嵌入显示PDF"""
|
| 376 |
-
return f'<iframe src="{base64_pdf}" width="100%" height="800" type="application/pdf"></iframe>'
|
| 377 |
-
|
| 378 |
-
# --- Streamlit 主程序 ---
|
| 379 |
-
st.set_page_config(page_title="影院排期打印工具", layout="wide")
|
| 380 |
-
st.title("影院排期打印工具")
|
| 381 |
-
|
| 382 |
-
uploaded_file = st.file_uploader("请上传 '放映时间核对表.xls' 或 '放映场次核对表.xls'",
|
| 383 |
-
type=["xls", "xlsx"])
|
| 384 |
-
|
| 385 |
-
if uploaded_file:
|
| 386 |
-
# 根据文件名中的关键字判断使用哪个处理流程
|
| 387 |
-
if "时间" in uploaded_file.name:
|
| 388 |
-
st.header("LED屏排片表")
|
| 389 |
-
with st.spinner("正在处理文件,请稍候..."):
|
| 390 |
-
schedule, date_str = process_schedule_led(uploaded_file)
|
| 391 |
-
if schedule is not None and not schedule.empty:
|
| 392 |
-
output = create_print_layout_led(schedule, date_str)
|
| 393 |
-
tab1, tab2 = st.tabs(["PDF 预览", "图片预览 (PNG)"])
|
| 394 |
-
with tab1:
|
| 395 |
-
st.markdown(display_pdf(output['pdf']), unsafe_allow_html=True)
|
| 396 |
-
with tab2:
|
| 397 |
-
st.image(output['png'], use_container_width=True)
|
| 398 |
-
else:
|
| 399 |
-
st.error("无法处理文件。请检查文件内容和格式是否正确。")
|
| 400 |
-
|
| 401 |
-
elif "场次" in uploaded_file.name:
|
| 402 |
-
st.header("散场时间快捷打印")
|
| 403 |
-
part1, part2, date_str = process_schedule_times(uploaded_file)
|
| 404 |
-
if part1 is not None and part2 is not None:
|
| 405 |
-
part1_output = create_print_layout_times(part1, "A", date_str)
|
| 406 |
-
part2_output = create_print_layout_times(part2, "C", date_str)
|
| 407 |
-
|
| 408 |
-
col1, col2 = st.columns(2)
|
| 409 |
-
with col1:
|
| 410 |
-
st.subheader("白班 (散场时间 ≤ 17:00)")
|
| 411 |
-
if part1_output:
|
| 412 |
-
tab1_1, tab1_2 = st.tabs(["PDF 预览 ", "图片预览 (PNG) "])
|
| 413 |
-
with tab1_1:
|
| 414 |
-
st.markdown(display_pdf(part1_output['pdf']), unsafe_allow_html=True)
|
| 415 |
-
with tab1_2:
|
| 416 |
-
st.image(part1_output['png'])
|
| 417 |
-
else:
|
| 418 |
-
st.info("白班没有排期数据。")
|
| 419 |
-
|
| 420 |
-
with col2:
|
| 421 |
-
st.subheader("晚班 (散场时间 > 17:00)")
|
| 422 |
-
if part2_output:
|
| 423 |
-
tab2_1, tab2_2 = st.tabs(["PDF 预览 ", "图片预览 (PNG) "])
|
| 424 |
-
with tab2_1:
|
| 425 |
-
st.markdown(display_pdf(part2_output['pdf']), unsafe_allow_html=True)
|
| 426 |
-
with tab2_2:
|
| 427 |
-
st.image(part2_output['png'])
|
| 428 |
-
else:
|
| 429 |
-
st.info("晚班没有排期数据。")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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otlib.lines import Line2D
|
| 6 |
-
import io
|
| 7 |
-
import base64
|
| 8 |
-
import os
|
| 9 |
-
from datetime import datetime, timedelta, time
|
| 10 |
-
from pypinyin import lazy_pinyin, Style
|
| 11 |
-
from matplotlib.backends.backend_pdf import PdfPages
|
| 12 |
-
import matplotlib.gridspec as gridspec
|
| 13 |
-
import math
|
| 14 |
-
|
| 15 |
-
# --- 常量和配置 ---
|
| 16 |
-
BUSINESS_START = "09:30"
|
| 17 |
-
BUSINESS_END = "01:30"
|
| 18 |
-
BORDER_COLOR = 'grey'
|
| 19 |
-
DATE_COLOR = '#A9A9A9'
|
| 20 |
-
A5_WIDTH_IN = 5.83
|
| 21 |
-
A5_HEIGHT_IN = 8.27
|
| 22 |
-
NUM_COLS = 3
|
| 23 |
-
|
| 24 |
-
# --- 字体清单 ---
|
| 25 |
-
ALL_FONTS = {
|
| 26 |
-
"思源黑体-常规 (推荐 LED 屏)": "SimHei.ttf",
|
| 27 |
-
"思源黑体-重体 (推荐散场表)": "SourceHanSansOLD-Heavy-2.otf",
|
| 28 |
-
"思源黑体-粗体": "SourceHanSansOLD-Bold-2.otf",
|
| 29 |
-
"思源宋体-常规": "SourceHanSansCN-Normal.otf",
|
| 30 |
-
"苹方-中黑": "PingFangSC-Medium.otf",
|
| 31 |
-
"苹方-半粗": "PingFangSC-Semibold.otf",
|
| 32 |
-
"苹方-极细": "PingFangSC-Ultralight.otf",
|
| 33 |
-
"阿里巴巴普惠体-常规": "Alibaba-PuHuiTi.ttf",
|
| 34 |
-
"阿里巴巴普惠体-粗体": "AlibabaPuHuiTi-Bold.otf",
|
| 35 |
-
"阿里巴巴普惠体-重体": "AlibabaPuHuiTi-Heavy.otf",
|
| 36 |
-
}
|
| 37 |
-
AVAILABLE_FONTS = {name: fname for name, fname in ALL_FONTS.items() if os.path.exists(fname)}
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
# --- 字体加载与文本处理函数 ---
|
| 41 |
-
|
| 42 |
-
def get_font_properties(font_path, size=14):
|
| 43 |
-
"""通用字体加载函数"""
|
| 44 |
-
if font_path and os.path.exists(font_path):
|
| 45 |
-
return font_manager.FontProperties(fname=font_path, size=size)
|
| 46 |
-
else:
|
| 47 |
-
st.warning(f"警告:未找到字体文件 '{font_path}',显示可能不正确。将使用默认字体。")
|
| 48 |
-
return font_manager.FontProperties(family='sans-serif', size=size)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
def get_pinyin_abbr(text):
|
| 52 |
-
"""获取中文文本前两个字的拼音首字母"""
|
| 53 |
-
if not text: return ""
|
| 54 |
-
chars = [c for c in text if '\u4e00' <= c <= '\u9fff'][:2]
|
| 55 |
-
if not chars: return ""
|
| 56 |
-
pinyin_list = lazy_pinyin(chars, style=Style.FIRST_LETTER)
|
| 57 |
-
return ''.join(pinyin_list).upper()
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
def format_seq(n):
|
| 61 |
-
"""将数字或字符转换为带圈序号 (①, ②, ③...),非数字则直接返回"""
|
| 62 |
-
try:
|
| 63 |
-
n = int(n)
|
| 64 |
-
except (ValueError, TypeError):
|
| 65 |
-
return str(n)
|
| 66 |
-
if n <= 0: return str(n)
|
| 67 |
-
circled_chars = "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
|
| 68 |
-
if 1 <= n <= 50: return circled_chars[n - 1]
|
| 69 |
-
return f'({n})'
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
# --- 核心数据处理函数 ---
|
| 73 |
-
|
| 74 |
-
def process_unified_schedule(file, split_time_str, time_adjustment_minutes=0):
|
| 75 |
-
"""
|
| 76 |
-
统一处理 '放映时间核对表.xls' 文件, 生成两种表格所需的数据。
|
| 77 |
-
"""
|
| 78 |
-
try:
|
| 79 |
-
date_df = pd.read_excel(file, header=None, skiprows=7, nrows=1, usecols=[3])
|
| 80 |
-
date_str = pd.to_datetime(date_df.iloc[0, 0]).strftime('%Y-%m-%d')
|
| 81 |
-
base_date = pd.to_datetime(date_str).date()
|
| 82 |
-
except Exception:
|
| 83 |
-
date_str = datetime.today().strftime('%Y-%m-%d')
|
| 84 |
-
base_date = datetime.today().date()
|
| 85 |
-
|
| 86 |
-
try:
|
| 87 |
-
df = pd.read_excel(file, header=9, usecols=[1, 2, 4, 5])
|
| 88 |
-
df.columns = ['Hall', 'StartTime', 'EndTime', 'Movie']
|
| 89 |
-
df['Hall'] = df['Hall'].ffill()
|
| 90 |
-
df.dropna(subset=['StartTime', 'EndTime', 'Movie'], inplace=True)
|
| 91 |
-
except Exception as e:
|
| 92 |
-
st.error(f"读取排期数据时出错: {e}。请检查文件格式是否为'放映时间核对表'。")
|
| 93 |
-
return None, None, None, date_str
|
| 94 |
-
|
| 95 |
-
# 'LED屏排片表' 数据处理
|
| 96 |
-
led_df = df.copy()
|
| 97 |
-
try:
|
| 98 |
-
# **优化2**: 优先提取 'X号',失败则取第一个字符 + '号'
|
| 99 |
-
extracted = led_df['Hall'].astype(str).str.extract(r'(\d+号)')
|
| 100 |
-
fallback = led_df['Hall'].astype(str).str[0] + '号'
|
| 101 |
-
led_df['Hall'] = extracted[0].fillna(fallback)
|
| 102 |
-
|
| 103 |
-
led_df['StartTime_dt'] = pd.to_datetime(led_df['StartTime'], format='%H:%M', errors='coerce').apply(
|
| 104 |
-
lambda t: t.replace(year=base_date.year, month=base_date.month, day=base_date.day) if pd.notnull(t) else t)
|
| 105 |
-
led_df['EndTime_dt'] = pd.to_datetime(led_df['EndTime'], format='%H:%M', errors='coerce').apply(
|
| 106 |
-
lambda t: t.replace(year=base_date.year, month=base_date.month, day=base_date.day) if pd.notnull(t) else t)
|
| 107 |
-
led_df.loc[led_df['EndTime_dt'] < led_df['StartTime_dt'], 'EndTime_dt'] += timedelta(days=1)
|
| 108 |
-
led_df = led_df.sort_values(['Hall', 'StartTime_dt'])
|
| 109 |
-
merged_rows = []
|
| 110 |
-
for _, group in led_df.groupby('Hall'):
|
| 111 |
-
current = None
|
| 112 |
-
for _, row in group.sort_values('StartTime_dt').iterrows():
|
| 113 |
-
if current is None:
|
| 114 |
-
current = row.copy()
|
| 115 |
-
elif row['Movie'] == current['Movie']:
|
| 116 |
-
current['EndTime_dt'] = row['EndTime_dt']
|
| 117 |
-
else:
|
| 118 |
-
merged_rows.append(current)
|
| 119 |
-
current = row.copy()
|
| 120 |
-
if current is not None: merged_rows.append(current)
|
| 121 |
-
merged_df = pd.DataFrame(merged_rows)
|
| 122 |
-
merged_df['StartTime_dt'] -= timedelta(minutes=10)
|
| 123 |
-
merged_df['EndTime_dt'] -= timedelta(minutes=5)
|
| 124 |
-
merged_df['Seq'] = merged_df.groupby('Hall').cumcount() + 1
|
| 125 |
-
merged_df['StartTime_str'] = merged_df['StartTime_dt'].dt.strftime('%H:%M')
|
| 126 |
-
merged_df['EndTime_str'] = merged_df['EndTime_dt'].dt.strftime('%H:%M')
|
| 127 |
-
led_schedule_df = merged_df[['Hall', 'Seq', 'Movie', 'StartTime_str', 'EndTime_str']]
|
| 128 |
-
except Exception as e:
|
| 129 |
-
st.error(f"处理 'LED屏排片表' 数据时出错: {e}")
|
| 130 |
-
led_schedule_df = None
|
| 131 |
-
|
| 132 |
-
# '散场时间快捷打印' 数据处理
|
| 133 |
-
times_df = df.copy()
|
| 134 |
-
try:
|
| 135 |
-
# **优化2**: 优先提取数字,失败则取第一个字符
|
| 136 |
-
num_part = times_df['Hall'].str.extract(r'(\d+)')[0]
|
| 137 |
-
char_part = times_df['Hall'].astype(str).str[0]
|
| 138 |
-
times_df['Hall'] = num_part.fillna(char_part)
|
| 139 |
-
times_df.dropna(subset=['Hall', 'StartTime', 'EndTime'], inplace=True)
|
| 140 |
-
times_df['StartTime_dt'] = pd.to_datetime(times_df['StartTime'], format='%H:%M', errors='coerce').apply(
|
| 141 |
-
lambda t: datetime.combine(base_date, t.time()) if pd.notnull(t) else pd.NaT)
|
| 142 |
-
times_df['EndTime_dt'] = pd.to_datetime(times_df['EndTime'], format='%H:%M', errors='coerce').apply(
|
| 143 |
-
lambda t: datetime.combine(base_date, t.time()) if pd.notnull(t) else pd.NaT)
|
| 144 |
-
times_df.loc[times_df['EndTime_dt'] < times_df['StartTime_dt'], 'EndTime_dt'] += timedelta(days=1)
|
| 145 |
-
|
| 146 |
-
# **优化4**: 应用时间提前量
|
| 147 |
-
if time_adjustment_minutes > 0:
|
| 148 |
-
times_df['EndTime_dt'] -= timedelta(minutes=time_adjustment_minutes)
|
| 149 |
-
|
| 150 |
-
business_start_dt = datetime.combine(base_date, datetime.strptime(BUSINESS_START, "%H:%M").time())
|
| 151 |
-
business_end_dt = datetime.combine(base_date, datetime.strptime(BUSINESS_END, "%H:%M").time())
|
| 152 |
-
if business_end_dt < business_start_dt: business_end_dt += timedelta(days=1)
|
| 153 |
-
times_df = times_df[(times_df['EndTime_dt'] >= business_start_dt) & (times_df['EndTime_dt'] <= business_end_dt)]
|
| 154 |
-
times_df = times_df.sort_values('EndTime_dt')
|
| 155 |
-
split_dt = datetime.combine(base_date, split_time_str)
|
| 156 |
-
part1 = times_df[times_df['EndTime_dt'] <= split_dt].copy()
|
| 157 |
-
part2 = times_df[times_df['EndTime_dt'] > split_dt].copy()
|
| 158 |
-
|
| 159 |
-
# **优化1**: 使用 %H:%M 保证两位小时
|
| 160 |
-
part1['EndTime'] = part1['EndTime_dt'].dt.strftime('%H:%M')
|
| 161 |
-
part2['EndTime'] = part2['EndTime_dt'].dt.strftime('%H:%M')
|
| 162 |
-
|
| 163 |
-
times_part1_df = part1[['Hall', 'EndTime']]
|
| 164 |
-
times_part2_df = part2[['Hall', 'EndTime']]
|
| 165 |
-
except Exception as e:
|
| 166 |
-
st.error(f"处理 '散场时间表' 数据时出错: {e}")
|
| 167 |
-
times_part1_df, times_part2_df = None, None
|
| 168 |
-
|
| 169 |
-
return led_schedule_df, times_part1_df, times_part2_df, date_str
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
# --- 'LED屏排片表' 布局生成函数 ---
|
| 173 |
-
def create_print_layout_led(data, date_str, font_path, generate_png=False):
|
| 174 |
-
if data is None or data.empty: return None
|
| 175 |
-
A4_width_in, A4_height_in = 8.27, 11.69
|
| 176 |
-
dpi = 300
|
| 177 |
-
total_content_rows = len(data)
|
| 178 |
-
layout_rows = max(total_content_rows, 25)
|
| 179 |
-
totalA = layout_rows + 2
|
| 180 |
-
row_height = A4_height_in / totalA
|
| 181 |
-
data = data.reset_index(drop=True)
|
| 182 |
-
data['hall_str'] = '$' + data['Hall'].str.replace('号', '') + '^{\#}$'
|
| 183 |
-
data['seq_str'] = data['Seq'].apply(format_seq)
|
| 184 |
-
data['pinyin_abbr'] = data['Movie'].apply(get_pinyin_abbr)
|
| 185 |
-
data['time_str'] = data['StartTime_str'] + ' - ' + data['EndTime_str']
|
| 186 |
-
temp_fig = plt.figure(figsize=(A4_width_in, A4_height_in), dpi=dpi)
|
| 187 |
-
renderer = temp_fig.canvas.get_renderer()
|
| 188 |
-
base_font_size_pt = (row_height * 0.9) * 72
|
| 189 |
-
seq_font_size_pt = (row_height * 0.5) * 72
|
| 190 |
-
|
| 191 |
-
def get_col_width_in(series, font_size_pt, is_math=False):
|
| 192 |
-
if series.empty: return 0
|
| 193 |
-
font_prop = get_font_properties(font_path, font_size_pt)
|
| 194 |
-
longest_str_idx = series.astype(str).str.len().idxmax()
|
| 195 |
-
max_content = str(series.loc[longest_str_idx])
|
| 196 |
-
text_width_px, _, _ = renderer.get_text_width_height_descent(max_content, font_prop, ismath=is_math)
|
| 197 |
-
return (text_width_px / dpi) * 1.1
|
| 198 |
-
|
| 199 |
-
margin_col_width = row_height
|
| 200 |
-
hall_col_width = get_col_width_in(data['hall_str'], base_font_size_pt, is_math=True)
|
| 201 |
-
seq_col_width = get_col_width_in(data['seq_str'], seq_font_size_pt)
|
| 202 |
-
pinyin_col_width = get_col_width_in(data['pinyin_abbr'], base_font_size_pt)
|
| 203 |
-
time_col_width = get_col_width_in(data['time_str'], base_font_size_pt)
|
| 204 |
-
movie_col_width = A4_width_in - (
|
| 205 |
-
margin_col_width * 2 + hall_col_width + seq_col_width + pinyin_col_width + time_col_width)
|
| 206 |
-
plt.close(temp_fig)
|
| 207 |
-
col_widths = {'hall': hall_col_width, 'seq': seq_col_width, 'movie': movie_col_width, 'pinyin': pinyin_col_width,
|
| 208 |
-
'time': time_col_width}
|
| 209 |
-
col_x_starts = {}
|
| 210 |
-
current_x = margin_col_width
|
| 211 |
-
for col_name in ['hall', 'seq', 'movie', 'pinyin', 'time']:
|
| 212 |
-
col_x_starts[col_name] = current_x
|
| 213 |
-
current_x += col_widths[col_name]
|
| 214 |
-
|
| 215 |
-
def draw_figure(fig, ax):
|
| 216 |
-
renderer = fig.canvas.get_renderer()
|
| 217 |
-
for col_name in ['hall', 'seq', 'movie', 'pinyin']:
|
| 218 |
-
x_line = col_x_starts[col_name] + col_widths[col_name]
|
| 219 |
-
line_top_y, line_bottom_y = A4_height_in - row_height, row_height
|
| 220 |
-
ax.add_line(
|
| 221 |
-
Line2D([x_line, x_line], [line_bottom_y, line_top_y], color='gray', linestyle=':', linewidth=0.5))
|
| 222 |
-
last_hall_drawn = None
|
| 223 |
-
for i, row in data.iterrows():
|
| 224 |
-
y_bottom = A4_height_in - (i + 2) * row_height
|
| 225 |
-
y_center = y_bottom + row_height / 2
|
| 226 |
-
if row['Hall'] != last_hall_drawn:
|
| 227 |
-
ax.text(col_x_starts['hall'] + col_widths['hall'] / 2, y_center, row['hall_str'],
|
| 228 |
-
fontproperties=get_font_properties(font_path, base_font_size_pt), ha='center', va='center')
|
| 229 |
-
last_hall_drawn = row['Hall']
|
| 230 |
-
ax.text(col_x_starts['seq'] + col_widths['seq'] / 2, y_center, row['seq_str'],
|
| 231 |
-
fontproperties=get_font_properties(font_path, seq_font_size_pt), ha='center', va='center')
|
| 232 |
-
ax.text(col_x_starts['pinyin'] + col_widths['pinyin'] / 2, y_center, row['pinyin_abbr'],
|
| 233 |
-
fontproperties=get_font_properties(font_path, base_font_size_pt), ha='center', va='center')
|
| 234 |
-
ax.text(col_x_starts['time'] + col_widths['time'] / 2, y_center, row['time_str'],
|
| 235 |
-
fontproperties=get_font_properties(font_path, base_font_size_pt), ha='center', va='center')
|
| 236 |
-
movie_font_size = base_font_size_pt
|
| 237 |
-
movie_font_prop = get_font_properties(font_path, movie_font_size)
|
| 238 |
-
text_w_px, _, _ = renderer.get_text_width_height_descent(row['Movie'], movie_font_prop, ismath=False)
|
| 239 |
-
text_w_in = text_w_px / dpi
|
| 240 |
-
max_width_in = col_widths['movie'] * 0.9
|
| 241 |
-
if text_w_in > max_width_in:
|
| 242 |
-
movie_font_size *= (max_width_in / text_w_in)
|
| 243 |
-
movie_font_prop = get_font_properties(font_path, movie_font_size)
|
| 244 |
-
ax.text(col_x_starts['movie'] + 0.05, y_center, row['Movie'], fontproperties=movie_font_prop, ha='left',
|
| 245 |
-
va='center')
|
| 246 |
-
is_last_in_hall = (i == len(data) - 1) or (row['Hall'] != data.loc[i + 1, 'Hall'])
|
| 247 |
-
line_start_x, line_end_x = margin_col_width, A4_width_in - margin_col_width
|
| 248 |
-
if is_last_in_hall:
|
| 249 |
-
ax.add_line(Line2D([line_start_x, line_end_x], [y_bottom, y_bottom], color='black', linestyle='-',
|
| 250 |
-
linewidth=0.8))
|
| 251 |
-
else:
|
| 252 |
-
ax.add_line(Line2D([line_start_x, line_end_x], [y_bottom, y_bottom], color='gray', linestyle=':',
|
| 253 |
-
linewidth=0.5))
|
| 254 |
-
|
| 255 |
-
outputs = {}
|
| 256 |
-
fig = plt.figure(figsize=(A4_width_in, A4_height_in), dpi=300)
|
| 257 |
-
ax = fig.add_axes([0, 0, 1, 1])
|
| 258 |
-
ax.set_axis_off();
|
| 259 |
-
ax.set_xlim(0, A4_width_in);
|
| 260 |
-
ax.set_ylim(0, A4_height_in)
|
| 261 |
-
ax.text(margin_col_width, A4_height_in - row_height, date_str, fontproperties=get_font_properties(font_path, 10),
|
| 262 |
-
color=DATE_COLOR, ha='left', va='bottom', transform=ax.transData)
|
| 263 |
-
draw_figure(fig, ax)
|
| 264 |
-
pdf_buf = io.BytesIO()
|
| 265 |
-
fig.savefig(pdf_buf, format='pdf', dpi=dpi, bbox_inches='tight', pad_inches=0)
|
| 266 |
-
pdf_buf.seek(0)
|
| 267 |
-
outputs['pdf'] = f"data:application/pdf;base64,{base64.b64encode(pdf_buf.getvalue()).decode()}"
|
| 268 |
-
if generate_png:
|
| 269 |
-
png_buf = io.BytesIO()
|
| 270 |
-
fig.savefig(png_buf, format='png', dpi=dpi, bbox_inches='tight', pad_inches=0)
|
| 271 |
-
png_buf.seek(0)
|
| 272 |
-
outputs['png'] = f"data:image/png;base64,{base64.b64encode(png_buf.getvalue()).decode()}"
|
| 273 |
-
plt.close(fig)
|
| 274 |
-
return outputs
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
# --- '散场时间表' 布局生成函数 ---
|
| 278 |
-
def create_print_layout_times(data, title, date_str, font_path, size_multiplier=1.1, hall_format='Default',
|
| 279 |
-
generate_png=False):
|
| 280 |
-
if data is None or data.empty: return None
|
| 281 |
-
|
| 282 |
-
def generate_figure():
|
| 283 |
-
total_items = len(data)
|
| 284 |
-
num_rows = math.ceil(total_items / NUM_COLS) if total_items > 0 else 1
|
| 285 |
-
data_area_height_in, cell_width_in = A5_HEIGHT_IN, A5_WIDTH_IN / NUM_COLS
|
| 286 |
-
cell_height_in = data_area_height_in / num_rows
|
| 287 |
-
target_width_pt, target_height_pt = (cell_width_in * 0.9) * 72, (cell_height_in * 0.9) * 72
|
| 288 |
-
font_size_based_on_width = target_width_pt / (8 * 0.6)
|
| 289 |
-
base_fontsize = min(font_size_based_on_width, target_height_pt) * size_multiplier
|
| 290 |
-
fig = plt.figure(figsize=(A5_WIDTH_IN, A5_HEIGHT_IN), dpi=300)
|
| 291 |
-
fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
|
| 292 |
-
gs = gridspec.GridSpec(num_rows, NUM_COLS, hspace=0, wspace=0, figure=fig)
|
| 293 |
-
data_values = data.values.tolist()
|
| 294 |
-
while len(data_values) % NUM_COLS != 0: data_values.append(['', ''])
|
| 295 |
-
rows_per_col_layout = math.ceil(len(data_values) / NUM_COLS)
|
| 296 |
-
sorted_data = [['', '']] * len(data_values)
|
| 297 |
-
for i, item in enumerate(data_values):
|
| 298 |
-
if item[0] and item[1]:
|
| 299 |
-
row_in_col, col_idx = i % rows_per_col_layout, i // rows_per_col_layout
|
| 300 |
-
new_index = row_in_col * NUM_COLS + col_idx
|
| 301 |
-
if new_index < len(sorted_data): sorted_data[new_index] = item
|
| 302 |
-
is_first_cell_with_data = True
|
| 303 |
-
for idx, (hall, end_time) in enumerate(sorted_data):
|
| 304 |
-
if hall and end_time:
|
| 305 |
-
row_grid, col_grid = idx // NUM_COLS, idx % NUM_COLS
|
| 306 |
-
ax = fig.add_subplot(gs[row_grid, col_grid])
|
| 307 |
-
for spine in ax.spines.values():
|
| 308 |
-
spine.set_visible(True);
|
| 309 |
-
spine.set_linestyle((0, (1, 2)))
|
| 310 |
-
spine.set_color(BORDER_COLOR);
|
| 311 |
-
spine.set_linewidth(0.75)
|
| 312 |
-
if is_first_cell_with_data:
|
| 313 |
-
ax.text(0.05, 0.95, f"{date_str} {title}",
|
| 314 |
-
fontproperties=get_font_properties(font_path, base_fontsize * 0.5), color=DATE_COLOR,
|
| 315 |
-
ha='left', va='top', transform=ax.transAxes)
|
| 316 |
-
is_first_cell_with_data = False
|
| 317 |
-
if hall_format == 'Superscript':
|
| 318 |
-
display_text = f'${str(hall)}^{{\#}}$ {end_time}'
|
| 319 |
-
elif hall_format == 'Circled':
|
| 320 |
-
display_text = f'{format_seq(hall)} {end_time}'
|
| 321 |
-
else: # Default
|
| 322 |
-
display_text = f"{str(hall)} {end_time}"
|
| 323 |
-
ax.text(0.5, 0.5, display_text, fontproperties=get_font_properties(font_path, base_fontsize),
|
| 324 |
-
ha='center', va='center', transform=ax.transAxes)
|
| 325 |
-
ax.set_xticks([]);
|
| 326 |
-
ax.set_yticks([]);
|
| 327 |
-
ax.set_facecolor('none')
|
| 328 |
-
return fig
|
| 329 |
-
|
| 330 |
-
fig_for_output = generate_figure()
|
| 331 |
-
outputs = {}
|
| 332 |
-
pdf_buffer = io.BytesIO()
|
| 333 |
-
with PdfPages(pdf_buffer) as pdf:
|
| 334 |
-
pdf.savefig(fig_for_output)
|
| 335 |
-
pdf_buffer.seek(0)
|
| 336 |
-
outputs['pdf'] = f"data:application/pdf;base64,{base64.b64encode(pdf_buffer.getvalue()).decode()}"
|
| 337 |
-
if generate_png:
|
| 338 |
-
png_buffer = io.BytesIO()
|
| 339 |
-
fig_for_output.savefig(png_buffer, format='png')
|
| 340 |
-
png_buffer.seek(0)
|
| 341 |
-
outputs['png'] = f'data:image/png;base64,{base64.b64encode(png_buffer.getvalue()).decode()}'
|
| 342 |
-
plt.close(fig_for_output)
|
| 343 |
-
return outputs
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
def display_pdf(base64_pdf):
|
| 347 |
-
"""在Streamlit中嵌入显示PDF"""
|
| 348 |
-
return f'<iframe src="{base64_pdf}" width="100%" height="800" type="application/pdf"></iframe>'
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
# --- Streamlit 主程序 ---
|
| 352 |
-
st.set_page_config(page_title="影院场次与散场时间快捷打印工具", layout="wide")
|
| 353 |
-
st.title("影院场次与散场时间快捷打印工具")
|
| 354 |
-
|
| 355 |
-
uploaded_file = st.file_uploader("请上传 `放映时间核对表.xls` 文件", type=["xls"])
|
| 356 |
-
|
| 357 |
-
with st.expander("⚙️ 显示与打印设置", expanded=False):
|
| 358 |
-
col1, col2 = st.columns(2)
|
| 359 |
-
with col1:
|
| 360 |
-
st.subheader("⚙️ 修改 LED 屏排片表设置")
|
| 361 |
-
led_font_name = st.selectbox("字体选择", options=list(AVAILABLE_FONTS.keys()), index=0, key="led_font")
|
| 362 |
-
led_font_path = AVAILABLE_FONTS.get(led_font_name)
|
| 363 |
-
generate_png_led = st.checkbox("生成 PNG 图片", value=False, key="png_led")
|
| 364 |
-
with col2:
|
| 365 |
-
st.subheader("⚙️ 散场时间表设置")
|
| 366 |
-
times_font_name = st.selectbox("字体选择", options=list(AVAILABLE_FONTS.keys()), index=1, key="times_font")
|
| 367 |
-
times_font_path = AVAILABLE_FONTS.get(times_font_name)
|
| 368 |
-
# **优化5**: 调整字体大小范围
|
| 369 |
-
font_size_multiplier = st.slider("字体大小调节", min_value=0.8, max_value=1.5, value=1.2, step=0.05,
|
| 370 |
-
help="调整字体在单元格内的相对大小")
|
| 371 |
-
split_time = st.time_input("白班 / 晚班分割时间", value=time(17, 0), help="散场时间在此时间点之前(含)的为白班")
|
| 372 |
-
# **优化4**: 增加时间提前设置
|
| 373 |
-
time_adjustment = st.slider("时间提前 (分钟)", min_value=0, max_value=10, value=0,
|
| 374 |
-
help="将所有散场时间提前 N 分钟显示")
|
| 375 |
-
hall_display_format = st.radio("影厅号格式", options=['Default', 'Superscript', 'Circled'],
|
| 376 |
-
format_func=lambda x:
|
| 377 |
-
{'Default': '默认 (2 18:28)', 'Superscript': '上标 (2# 18:28)',
|
| 378 |
-
'Circled': '带圈 (② 18:28)'}[x], horizontal=True)
|
| 379 |
-
generate_png_times = st.checkbox("生成 PNG 图片", value=False, key="png_times")
|
| 380 |
-
|
| 381 |
-
with st.expander("💡 使用帮助", expanded=False):
|
| 382 |
-
st.markdown("""
|
| 383 |
-
#### 🖨️ 功能简介
|
| 384 |
-
本工具用于将影院的 `放映时间核对表.xls` 文件快速转换为两种形式的打印页:
|
| 385 |
-
1. **修改 LED 屏幕排片表打印**:A4 竖版,详细列出影厅、场次、影片名、拼音缩写和时间范围,方便员工在修改 LED 屏幕时快速查阅和输入。
|
| 386 |
-
- 拼音缩写是为了在输入法如 QQ 拼音输入法等造词功能,拼音缩写填写快捷键,内容填写影片名字,更快捷输入。
|
| 387 |
-
- 时间范围已经优化过了,默认提前了 10 分钟。
|
| 388 |
-
2. **散场时间打印**:A5 竖版,以大字体分栏显示各影厅的散场时间,方便员工在疏散人群和清洁影厅时查阅。
|
| 389 |
-
- 内容分三列,顺序是每列从上到下。
|
| 390 |
-
- 可以在设置里面设置提前如 5 分钟,到时间就可以前往影厅在疏散人群和清洁影厅。
|
| 391 |
-
|
| 392 |
-
#### ⬇️ 操作步骤
|
| 393 |
-
1. **上传文件**:导出 `放映时间核对表.xls` 后,点击上方的 "Browse files" 按钮,选择您的 `放映时间核对表.xls` 文件。
|
| 394 |
-
2. **调整设置 (可选)**:点击上方的 "显示与打印设置" 打开设置面板,根据需要调整字体、大小、格式等。
|
| 395 |
-
3. **预览与打印**:
|
| 396 |
-
* 上传成功后,下方会自动生成预览。
|
| 397 |
-
* 默认显示 **PDF 预览**,这是最适合打印的格式。可以直接在预览界面点击 🖨️ 打印按钮,设置纸张大小即可打印。
|
| 398 |
-
* 如果勾选了 "生成 PNG 图片",可以切换到 **图片预览 (PNG)** 标签页查看或在新标签页中打开图片或下载图片后打印。
|
| 399 |
-
""")
|
| 400 |
-
|
| 401 |
-
# --- 主页面逻辑 ---
|
| 402 |
-
if uploaded_file:
|
| 403 |
-
with st.spinner("正在处理文件,请稍候..."):
|
| 404 |
-
led_data, times_part1, times_part2, date_str = process_unified_schedule(uploaded_file, split_time,
|
| 405 |
-
time_adjustment)
|
| 406 |
-
|
| 407 |
-
st.toast(f"文件处理完成!排期日期:**{date_str}**", icon="🎉")
|
| 408 |
-
|
| 409 |
-
# 显示 LED 屏排片表
|
| 410 |
-
st.header("🖥️ 修改 LED 屏幕排片表打印")
|
| 411 |
-
if led_data is not None and not led_data.empty:
|
| 412 |
-
led_output = create_print_layout_led(led_data, date_str, led_font_path, generate_png_led)
|
| 413 |
-
if led_output:
|
| 414 |
-
tabs = ["PDF 预览"]
|
| 415 |
-
if 'png' in led_output: tabs.append("PNG 预览")
|
| 416 |
-
tab_views = st.tabs(tabs)
|
| 417 |
-
with tab_views[0]:
|
| 418 |
-
st.markdown(display_pdf(led_output['pdf']), unsafe_allow_html=True)
|
| 419 |
-
if 'png' in led_output:
|
| 420 |
-
with tab_views[1]: st.image(led_output['png'], use_container_width=True)
|
| 421 |
-
else:
|
| 422 |
-
st.error("未能成功生成 '修改 LED 屏排片表'。请检查文件内容或格式。")
|
| 423 |
-
|
| 424 |
-
# 显示散场时间快捷打印
|
| 425 |
-
st.header("🔚 散场时间打印")
|
| 426 |
-
col1, col2 = st.columns(2)
|
| 427 |
-
with col1:
|
| 428 |
-
if times_part1 is not None and not times_part1.empty:
|
| 429 |
-
part1_output = create_print_layout_times(times_part1, "A", date_str, times_font_path, font_size_multiplier,
|
| 430 |
-
hall_display_format, generate_png_times)
|
| 431 |
-
if part1_output:
|
| 432 |
-
# **优化3**: 更改Tab标题
|
| 433 |
-
tabs1 = [f"白班 (≤ {split_time.strftime('%H:%M')}) PDF 预览"]
|
| 434 |
-
if 'png' in part1_output: tabs1.append(f"白班 (≤ {split_time.strftime('%H:%M')}) PNG 预览")
|
| 435 |
-
tab_views1 = st.tabs(tabs1)
|
| 436 |
-
with tab_views1[0]:
|
| 437 |
-
st.markdown(display_pdf(part1_output['pdf']), unsafe_allow_html=True)
|
| 438 |
-
if 'png' in part1_output:
|
| 439 |
-
with tab_views1[1]: st.image(part1_output['png'])
|
| 440 |
-
else:
|
| 441 |
-
st.info(f"白班 (≤ {split_time.strftime('%H:%M')}) 没有排期数据。")
|
| 442 |
-
|
| 443 |
-
with col2:
|
| 444 |
-
if times_part2 is not None and not times_part2.empty:
|
| 445 |
-
part2_output = create_print_layout_times(times_part2, "C", date_str, times_font_path, font_size_multiplier,
|
| 446 |
-
hall_display_format, generate_png_times)
|
| 447 |
-
if part2_output:
|
| 448 |
-
# **优化3**: 更改Tab标题
|
| 449 |
-
tabs2 = [f"晚班 (> {split_time.strftime('%H:%M')}) PDF 预览"]
|
| 450 |
-
if 'png' in part2_output: tabs2.append(f"晚班 (> {split_time.strftime('%H:%M')}) PNG 预览")
|
| 451 |
-
tab_views2 = st.tabs(tabs2)
|
| 452 |
-
with tab_views2[0]:
|
| 453 |
-
st.markdown(display_pdf(part2_output['pdf']), unsafe_allow_html=True)
|
| 454 |
-
if 'png' in part2_output:
|
| 455 |
-
with tab_views2[1]: st.image(part2_output['png'])
|
| 456 |
-
else:
|
| 457 |
-
st.info(f"晚班 (> {split_time.strftime('%H:%M')}) 没有排期数据。")
|
| 458 |
-
else:
|
| 459 |
-
st.info("👆 请先上传文件以生成预览。")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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