# history

source:
  import json
  from pathlib import Path
  import pandas as pd
  import matplotlib.pyplot as plt

  BASE = Path('../data/results').resolve()

  def load(name):
      return pd.read_csv(BASE / f'{name}.csv')

  totales = json.loads((BASE / 'totales_globales.json').read_text())
  totales

source_raw:
  import json
  from pathlib import Path
  import pandas as pd
  import matplotlib.pyplot as plt

  BASE = Path('../data/results').resolve()

  def load(name):
      return pd.read_csv(BASE / f'{name}.csv')

  totales = json.loads((BASE / 'totales_globales.json').read_text())
  totales


source:
  # Top 15 centros por valor A (más facturado vía call_center)
  top = df.sort_values('A_quote_cc_eur', ascending=False).head(15).iloc[::-1]
  fig, ax = plt.subplots(figsize=(10, 7))
  y = range(len(top))
  ax.barh(y, top.A_quote_cc_eur, label='A (cc -> factura)')
  ax.barh(y, (top.B_mismo_cliente_eur - top.A_quote_cc_eur).clip(lower=0),
          left=top.A_quote_cc_eur, label='B-A (mismo cliente extra)')
  ax.set_yticks(list(y)); ax.set_yticklabels(top.center_name)
  ax.set_xlabel('€ facturados (90d)')
  ax.legend(); ax.set_title('Top 15 centros — quotes call_center -> factura')
  plt.tight_layout(); plt.show()

source_raw:
  # Top 15 centros por valor A (más facturado vía call_center)
  top = df.sort_values('A_quote_cc_eur', ascending=False).head(15).iloc[::-1]
  fig, ax = plt.subplots(figsize=(10, 7))
  y = range(len(top))
  ax.barh(y, top.A_quote_cc_eur, label='A (cc -> factura)')
  ax.barh(y, (top.B_mismo_cliente_eur - top.A_quote_cc_eur).clip(lower=0),
          left=top.A_quote_cc_eur, label='B-A (mismo cliente extra)')
  ax.set_yticks(list(y)); ax.set_yticklabels(top.center_name)
  ax.set_xlabel('€ facturados (90d)')
  ax.legend(); ax.set_title('Top 15 centros — quotes call_center -> factura')
  plt.tight_layout(); plt.show()


source:
  top_regen = regen.head(15).iloc[::-1]
  fig, ax = plt.subplots(figsize=(10, 6))
  y = range(len(top_regen))
  ax.barh(y, top_regen.q0_regenerados_aqui)
  ax.set_yticks(list(y)); ax.set_yticklabels(top_regen.center_name)
  ax.set_xlabel('# Q0 (de call_center) regenerados en este centro')
  ax.set_title('Top centros regeneradores de presupuesto call_center (90d Q0, 60d window)')
  plt.tight_layout(); plt.show()

source_raw:
  top_regen = regen.head(15).iloc[::-1]
  fig, ax = plt.subplots(figsize=(10, 6))
  y = range(len(top_regen))
  ax.barh(y, top_regen.q0_regenerados_aqui)
  ax.set_yticks(list(y)); ax.set_yticklabels(top_regen.center_name)
  ax.set_xlabel('# Q0 (de call_center) regenerados en este centro')
  ax.set_title('Top centros regeneradores de presupuesto call_center (90d Q0, 60d window)')
  plt.tight_layout(); plt.show()


