Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jerrrrry
easystart_v0.2
Commits
f30e0381
Commit
f30e0381
authored
Jul 24, 2025
by
jerrrrry
Browse files
Replace division.py
parent
f9b80654
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
21 deletions
+36
-21
division.py
division.py
+36
-21
No files found.
division.py
View file @
f30e0381
#!/usr/bin/env python3
"""
universal_ratio.py
一键批量对比
任意文件夹下
成对 Excel
python universal_ratio.py folder1 folder2 [folder3 ...]
输出:summary_ratio.xlsx(每张 Sheet 含
4
列百分比)
universal_ratio
_full
.py
一键批量对比成对 Excel
(含首 token 延迟)
python universal_ratio
_full
.py folder1 folder2 [folder3 ...]
输出:summary_ratio.xlsx(每张 Sheet 含
5
列百分比)
"""
import
argparse
...
...
@@ -13,7 +13,6 @@ import pandas as pd
from
openpyxl
import
Workbook
from
openpyxl.styles
import
Alignment
,
Border
,
Side
,
Font
,
PatternFill
from
openpyxl.utils
import
get_column_letter
from
openpyxl.styles
import
Font
DEFAULT_FONT
=
Font
(
name
=
'Arial'
,
size
=
10
)
# ------------------ 样式 ------------------
thin
=
Side
(
'thin'
)
...
...
@@ -21,6 +20,7 @@ border = Border(top=thin, bottom=thin, left=thin, right=thin)
center
=
Alignment
(
horizontal
=
'center'
,
vertical
=
'center'
,
wrap_text
=
True
)
header_font
=
Font
(
bold
=
True
,
color
=
'FFFFFF'
)
black_font
=
Font
(
name
=
'微软雅黑'
,
size
=
11
,
bold
=
True
,
color
=
'000000'
)
# 000000代表黑色
blue_fill
=
PatternFill
(
'solid'
,
fgColor
=
'e0ffff'
)
# 纯蓝
orange_fill
=
PatternFill
(
'solid'
,
fgColor
=
'faf0e6'
)
# 橙色
green_fill
=
PatternFill
(
'solid'
,
fgColor
=
'4de680'
)
# 绿色
...
...
@@ -49,18 +49,31 @@ def process_sheet(wb, prefix, path_A, path_B):
min_rows
=
min
(
len
(
df_A
),
len
(
df_B
))
df_A
,
df_B
=
df_A
.
iloc
[:
min_rows
],
df_B
.
iloc
[:
min_rows
]
# 要对比的列索引(总吞吐、生成吞吐、单路、不带首字)
pct_cols
=
[
5
,
6
,
10
,
11
]
titles
=
[
'总吞吐量(%)'
,
'生成吞吐量(%)'
,
'单路生成吞吐(%)'
,
'不带首字生成吞吐(%)'
]
# 列索引(总、生成、首token、单路、不带首)
pct_cols
=
[
5
,
6
,
7
,
10
,
11
]
titles
=
[
'总吞吐量(%)'
,
'生成吞吐量(%)'
,
'首token延迟(%)'
,
'单路生成吞吐(%)'
,
'不带首字生成吞吐(%)'
]
pct_rows
,
pct_df
=
[],
pd
.
DataFrame
()
for
r
in
range
(
2
,
len
(
df_A
)):
a
=
[
df_A
.
iloc
[
r
,
c
]
for
c
in
pct_cols
]
b
=
[
df_B
.
iloc
[
r
,
c
]
for
c
in
pct_cols
]
pct_rows
.
append
([
round
(
a
[
i
]
/
b
[
i
]
*
100
,
2
)
if
b
[
i
]
else
None
for
i
in
range
(
4
)])
a_vals
=
[
df_A
.
iloc
[
r
,
c
]
for
c
in
pct_cols
]
b_vals
=
[
df_B
.
iloc
[
r
,
c
]
for
c
in
pct_cols
]
pct
=
[]
for
i
,
(
a
,
b
)
in
enumerate
(
zip
(
a_vals
,
b_vals
)):
if
i
==
2
:
# 首 token 延迟:倒序
pct
.
append
(
round
(
b
/
a
*
100
,
2
)
if
a
else
None
)
else
:
pct
.
append
(
round
(
a
/
b
*
100
,
2
)
if
b
else
None
)
pct_rows
.
append
(
pct
)
pct_df
=
pd
.
DataFrame
(
pct_rows
,
columns
=
titles
)
avg
=
pct_df
.
mean
().
round
(
2
).
tolist
()
max_row_ws
=
[
idx
+
3
for
idx
in
pct_df
.
idxmax
()]
# 第 3 行开始
max_row_ws
=
[
idx
+
3
for
idx
in
pct_df
.
idxmax
()]
min_row_ws
=
[
idx
+
3
for
idx
in
pct_df
.
idxmin
()]
ws
=
wb
.
create_sheet
(
title
=
prefix
)
...
...
@@ -96,19 +109,21 @@ def process_sheet(wb, prefix, path_A, path_B):
for
r
in
range
(
1
,
len
(
rows_A
)
+
1
):
ws
.
cell
(
row
=
r
,
column
=
blank2
,
value
=
None
)
# ---------- 百分比 ----------
pct_start
=
blank2
+
1
# 百分比区
pct_start
=
blank2
+
1
# 数据从 blank2+2 列开始
for
c_idx
,
title
in
enumerate
(
titles
,
0
):
cell
=
ws
.
cell
(
row
=
2
,
column
=
pct_start
+
c_idx
,
value
=
title
)
cell
.
font
=
header_font
cell
.
fill
=
blue_fill
ws
.
cell
(
row
=
2
,
column
=
pct_start
+
c_idx
,
value
=
title
).
font
=
header_font
ws
.
cell
(
row
=
2
,
column
=
pct_start
+
c_idx
).
fill
=
blue_fill
# 写入数据
for
r_idx
,
vals
in
enumerate
(
pct_rows
,
0
):
for
c_idx
,
val
in
enumerate
(
vals
,
0
):
ws
.
cell
(
row
=
3
+
r_idx
,
column
=
pct_start
+
c_idx
,
value
=
val
)
# 平均值
# 平均值
行(关键修改:标签列向左移动)
avg_row
=
3
+
len
(
pct_rows
)
+
1
ws
.
cell
(
row
=
avg_row
,
column
=
pct_start
-
1
,
value
=
'平均值'
).
font
=
Font
(
bold
=
True
)
ws
.
cell
(
row
=
avg_row
,
column
=
pct_start
-
1
,
value
=
'平均值'
).
font
=
black_font
# 改为-2
for
c_idx
,
val
in
enumerate
(
avg
,
0
):
ws
.
cell
(
row
=
avg_row
,
column
=
pct_start
+
c_idx
,
value
=
val
)
...
...
@@ -130,7 +145,7 @@ def process_sheet(wb, prefix, path_A, path_B):
ws
.
column_dimensions
[
get_column_letter
(
col
[
0
].
column
)].
width
=
max_len
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'批量生成比例对比表'
)
parser
=
argparse
.
ArgumentParser
(
description
=
'批量生成比例对比表
(含首 token 延迟)
'
)
parser
.
add_argument
(
'folders'
,
nargs
=
'+'
,
help
=
'两个或多个文件夹路径'
)
args
=
parser
.
parse_args
()
...
...
@@ -140,7 +155,7 @@ def main():
return
wb
=
Workbook
()
wb
.
remove
(
wb
.
active
)
# 删除默认空 sheet
wb
.
remove
(
wb
.
active
)
for
prefix
,
paths
in
pairs
.
items
():
process_sheet
(
wb
,
prefix
,
*
paths
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment