Improve Slack vertical clarity: header blocks, grouped ok summary, dividers
- Vertical detail messages use Slack header block for prominent title - 'Todo en orden' groups campaigns by vertical with CPL/obj summary per vertical - Divider between each campaign within a vertical detail message Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
bde5856f32
commit
8480e530a0
@ -354,18 +354,28 @@ def send_daily_report(
|
||||
"text": f"⛔ {total_ad_pauses} {noun} recomendados para pausar — ver detalle por vertical"}],
|
||||
})
|
||||
|
||||
# "Todo en orden" summary
|
||||
# "Todo en orden" summary — grouped by vertical
|
||||
if camps_ok:
|
||||
blocks.append({"type": "divider"})
|
||||
ok_lines = []
|
||||
for name, (_, detail) in sorted(camps_ok.items(), key=lambda x: x[1][1]["vertical"]):
|
||||
v = detail["vertical"]
|
||||
leads_1d = detail.get("leads_1d", 0)
|
||||
spend_1d = detail.get("spend_1d", 0.0)
|
||||
ok_lines.append(f"✅ *{name}* · {spend_1d:.0f}€ / {leads_1d} leads ayer")
|
||||
ok_by_v: dict = {}
|
||||
for name, (_, detail) in camps_ok.items():
|
||||
ok_by_v.setdefault(detail["vertical"], []).append((name, detail))
|
||||
ok_lines = ["*Todo en orden*"]
|
||||
for vert in sorted(ok_by_v.keys()):
|
||||
v_data = (verticals or {}).get(vert, {})
|
||||
v_spend = v_data.get("spend", 0)
|
||||
v_leads = v_data.get("leads", 0)
|
||||
v_cpl = round(v_spend / v_leads, 2) if v_leads > 0 else 0.0
|
||||
v_obj = v_data.get("target_cpl", 0)
|
||||
ok_lines.append(f"\n✅ *{vert.upper()}* · CPL {v_cpl:.2f}€ obj {v_obj:.2f}€")
|
||||
for name, detail in sorted(ok_by_v[vert], key=lambda x: -x[1].get("spend_1d", 0)):
|
||||
ok_lines.append(
|
||||
f" • {name} · "
|
||||
f"{detail.get('spend_1d', 0):.0f}€ / {detail.get('leads_1d', 0)} leads ayer"
|
||||
)
|
||||
blocks.append({
|
||||
"type": "section",
|
||||
"text": {"type": "mrkdwn", "text": "*Todo en orden*\n" + "\n".join(ok_lines)},
|
||||
"text": {"type": "mrkdwn", "text": "\n".join(ok_lines)},
|
||||
})
|
||||
|
||||
blocks.append({
|
||||
@ -392,18 +402,28 @@ def send_daily_report(
|
||||
m_str = f"+{v_margin:.0f}€" if v_margin >= 0 else f"{v_margin:.0f}€"
|
||||
obj_str = f" · obj {v_obj:.2f}€" if v_obj else ""
|
||||
|
||||
v_blocks: list = [{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": (
|
||||
f"📊 *{v.upper()}* · {v_spend:.0f}€ · {v_leads} leads · "
|
||||
f"CPL {v_cpl:.2f}€{obj_str} · Margen {m_str}"
|
||||
),
|
||||
v_blocks: list = [
|
||||
{
|
||||
"type": "header",
|
||||
"text": {"type": "plain_text", "text": f"📊 {v.upper()}"},
|
||||
},
|
||||
}]
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": (
|
||||
f"{v_spend:.0f}€ · {v_leads} leads · "
|
||||
f"CPL {v_cpl:.2f}€{obj_str} · Margen {m_str}"
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
for cid, detail, act in sorted(camp_list, key=lambda x: -x[1].get("spend_1d", 0)):
|
||||
for i, (cid, detail, act) in enumerate(
|
||||
sorted(camp_list, key=lambda x: -x[1].get("spend_1d", 0))
|
||||
):
|
||||
if i > 0:
|
||||
v_blocks.append({"type": "divider"})
|
||||
name = detail["name"]
|
||||
spend_1d = detail.get("spend_1d", 0.0)
|
||||
leads_1d = detail.get("leads_1d", 0)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user