Simplify generate_tag_metrics logic

This commit is contained in:
Matthias 2024-06-11 19:53:22 +02:00
parent b8a4752636
commit 1b2cfc9857

View File

@ -157,12 +157,11 @@ def generate_tag_metrics(
tabular_data = [] tabular_data = []
if tag_type in results.columns: if tag_type in results.columns:
for tag, count in results[tag_type].value_counts().items(): for tags, group in results.groupby(tag_type):
result = results[results[tag_type] == tag] if skip_nan and group["profit_abs"].isnull().all():
if skip_nan and result["profit_abs"].isnull().all():
continue continue
tabular_data.append(_generate_result_line(result, starting_balance, tag)) tabular_data.append(_generate_result_line(group, starting_balance, tags))
# Sort by total profit %: # Sort by total profit %:
tabular_data = sorted(tabular_data, key=lambda k: k["profit_total_abs"], reverse=True) tabular_data = sorted(tabular_data, key=lambda k: k["profit_total_abs"], reverse=True)