Files
weval-l99/pipeline-close-refresh.sh
2026-04-24 04:38:58 +02:00

26 lines
823 B
Bash
Executable File

#!/bin/bash
# Auto-refresh pipeline-close cache from live PG
STAGES=$(PGPASSWORD=admin123 psql -h 10.1.0.3 -U admin -d adx_system -t -c "SELECT stage FROM admin.pipeline_deals" 2>/dev/null | grep -v "^$" | tr -d " \t")
TOTAL=0
COUNT=0
for s in $STAGES; do
case "$s" in
*won*|*Won*) W=100 ;;
*negot*|*Negot*) W=60 ;;
*propos*|*Propos*) W=40 ;;
*qualif*|*Qualif*) W=20 ;;
*new*|*open*|*New*|*Open*) W=15 ;;
*) W=30 ;;
esac
TOTAL=$((TOTAL + W))
COUNT=$((COUNT + 1))
done
if [ "$COUNT" -gt 0 ]; then
AVG=$(awk "BEGIN{printf \"%.1f\", $TOTAL/$COUNT}")
else
AVG=0
fi
TS=$(date -Iseconds)
echo "{\"weighted_pct\":$AVG,\"deals_count\":$COUNT,\"ts\":\"$TS\"}" > /opt/weval-l99/data/kpi-wire/pipeline-close.json
chown www-data:www-data /opt/weval-l99/data/kpi-wire/pipeline-close.json 2>/dev/null