"docs/vscode:/vscode.git/clone" did not exist on "c20ecb6a51cb58d408eb5ae7b03ac76c7b83e609"
Commit 94480c3f authored by yanke's avatar yanke
Browse files

fix bug

parent 87ab47a0
File deleted
......@@ -220,6 +220,13 @@ def apply_normalization(df, key_cols, normalize_configs, group_cols):
if effective_group_cols:
def normalize_group(group):
if not base_dict:
valid_data = group[group[col].notna() & (group[col] != 0)]
if len(valid_data) > 0:
base_val = valid_data[col].iloc[0]
else:
return group
else:
base_mask = pd.Series(True, index=group.index)
for k, v in base_dict.items():
if k in group.columns:
......@@ -245,7 +252,16 @@ def apply_normalization(df, key_cols, normalize_configs, group_cols):
group[col] = (group[col] / base_val) * 100
return group
df = df.groupby(effective_group_cols, group_keys=False).apply(normalize_group)
print(f" 归一化列 '{col}': 每个分组内基准值 {base_dict} = 100%")
base_display = base_dict if base_dict else '(自动选择第一个)'
print(f" 归一化列 '{col}': 每个分组内基准值 {base_display} = 100%")
else:
if not base_dict:
valid_data = df[df[col].notna() & (df[col] != 0)]
if len(valid_data) > 0:
base_values = valid_data[col].iloc[0]
else:
print(f" 警告: 无有效数据,跳过归一化")
continue
else:
base_mask = pd.Series(True, index=df.index)
for k, v in base_dict.items():
......@@ -263,7 +279,8 @@ def apply_normalization(df, key_cols, normalize_configs, group_cols):
print(f" 警告: 无有效数据,跳过归一化")
continue
df[col] = (df[col] / base_values) * 100
print(f" 归一化列 '{col}': 基准值 {base_dict} = 100%")
base_display = base_dict if base_dict else '(自动选择第一个)'
print(f" 归一化列 '{col}': 基准值 {base_display} = 100%")
return df
......@@ -293,17 +310,28 @@ def generate_chart(df_subset, output_path, colkey, outer_group_cols, inner_group
engine_values = df_grouped[compare_col].unique()
n_engines = len(engine_values)
max_inner_groups = 0
for _, outer_row in outer_values.iterrows():
df_outer = df_grouped.copy()
for gcol in outer_group_cols:
df_outer = df_outer[df_outer[gcol] == outer_row[gcol]]
pt = df_outer.pivot_table(index=inner_group_cols, columns=compare_col, values=metric_cols[0]).fillna(0)
max_inner_groups = max(max_inner_groups, len(pt))
color_palette = ['#2E86AB', '#A23B72', '#F18F01', '#C73E1D', '#3B1F2B', '#95C623', '#7B2D26']
colors = [color_palette[i % len(color_palette)] for i in range(n_engines)]
normalized_cols = [c['column'] for c in (normalize_configs or [])]
if merge_groups and n_outer > 1:
fig, axes = plt.subplots(1, 4, figsize=(8 * n_outer + 20, 10))
total_bars = max_inner_groups * n_engines
unit_width = 1.0
fig_width = max(8 * n_outer + 20, total_bars * unit_width + 5)
fig, axes = plt.subplots(1, 4, figsize=(fig_width, 10))
bar_width = 0.12
bar_spacing = 0.05
group_gap = 3
bar_width = min(0.2, 0.7 / max(n_engines, 1))
bar_spacing = bar_width * 0.3
group_gap = max(1.5, n_engines * bar_width * 0.8)
x_labels_all = None
......@@ -381,14 +409,17 @@ def generate_chart(df_subset, output_path, colkey, outer_group_cols, inner_group
ax.set_ylabel(metric, fontsize=10)
ax.set_title(f'{metric}', fontsize=12, fontweight='bold')
ax.grid(axis='y', alpha=0.3, linestyle='--')
ax.legend(fontsize=5, loc='upper right', framealpha=0.9, ncol=1)
ax.legend(fontsize=5, loc='upper left', bbox_to_anchor=(1.02, 1), framealpha=0.9, ncol=1)
else:
fig, axes = plt.subplots(n_outer, 4, figsize=(24, 5 * n_outer))
total_bars = max_inner_groups * n_engines
unit_width = 0.8
fig_width = max(24, total_bars * unit_width + 4)
fig, axes = plt.subplots(n_outer, 4, figsize=(fig_width, 5 * n_outer))
if n_outer == 1:
axes = axes.reshape(1, -1)
bar_width = 0.2
bar_width = min(0.25, 0.8 / max(n_engines, 1))
outer_label = '/'.join(outer_group_cols) if outer_group_cols else '全部'
......@@ -438,9 +469,9 @@ def generate_chart(df_subset, output_path, colkey, outer_group_cols, inner_group
ax.set_xticklabels(x_labels, rotation=45, ha='right', fontsize=7)
ax.grid(axis='y', alpha=0.3, linestyle='--')
ax.legend(fontsize=6, loc='upper right', framealpha=0.9, ncol=1)
ax.legend(fontsize=6, loc='upper left', bbox_to_anchor=(1.02, 1), framealpha=0.9, ncol=1)
plt.tight_layout()
plt.tight_layout(rect=[0, 0, 0.85, 1])
plt.savefig(output_path, dpi=150, bbox_inches='tight', facecolor='white')
plt.close()
return True
......
No preview for this file type
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment