in analysis/render.py [0:0]
def fmt_metric_value(x: np.float64, metric_type: str) -> str:
"""Format a metric value"""
if np.isnan(x):
out = "--"
elif np.isinf(x):
sign = "" if x > 0 else "-"
out = f"{sign}∞"
elif metric_type in ["EventRate", "UserRate"]:
dp = 0 if x == 0 or np.isclose(x, 100) else 1
out = format(x / 100.0, f".{dp}%")
elif metric_type in ["EventCount", "UserCount"]:
if x >= 1e15:
out = format(x, ".2e")
elif x >= 1e12:
out = f"{x / 1e12:.1f}T"
elif x >= 1e9:
out = f"{x / 1e9:.1f}B"
elif x >= 1e6:
out = f"{x / 1e6:.1f}M"
else:
out = format(int(x), ",d")
# Sum, Average, Percentile, etc
else:
if np.fabs(x) >= 10_000 and np.fabs(x) < 1e6:
out = format(x, ",.0f")
else:
out = format(x, ",.4g").replace("e+0", "e+").replace("e-0", "e-")
return out