47 lines
1.5 KiB
Bash
Executable File
47 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# WINNING CONFIG DETECTOR - Détecte et promeut les winners
|
|
# Usage: ./winning-detector.sh
|
|
|
|
LOG_FILE="/var/log/wevads/winner-detection.log"
|
|
mkdir -p /var/log/wevads
|
|
|
|
echo "$(date) - Running winner detection" >> $LOG_FILE
|
|
|
|
# Trouver les nouvelles configs gagnantes
|
|
NEW_WINNERS=$(PGPASSWORD=admin123 psql -U admin -d adx_system -t -A -c "
|
|
SELECT id, isp_target, send_method, inbox_rate, total_sent
|
|
FROM admin.brain_configs
|
|
WHERE total_sent >= 10
|
|
AND inbox_rate >= 80
|
|
AND is_winner = false;
|
|
")
|
|
|
|
COUNT=0
|
|
while IFS='|' read -r ID ISP METHOD RATE TESTS; do
|
|
[ -z "$ID" ] && continue
|
|
|
|
echo "🏆 New winner: Config #$ID - $ISP via $METHOD ($RATE% inbox)"
|
|
|
|
# Marquer comme winner
|
|
PGPASSWORD=admin123 psql -U admin -d adx_system -c "
|
|
UPDATE admin.brain_configs SET is_winner = true WHERE id = $ID;
|
|
|
|
INSERT INTO admin.brain_winners (config_id, isp_target, send_method, inbox_rate, promoted_at)
|
|
VALUES ($ID, '$ISP', '$METHOD', $RATE, NOW())
|
|
ON CONFLICT (config_id) DO UPDATE SET inbox_rate = $RATE, promoted_at = NOW();
|
|
" 2>/dev/null
|
|
|
|
((COUNT++))
|
|
done <<< "$NEW_WINNERS"
|
|
|
|
# Rétrograder les configs qui ne performent plus
|
|
PGPASSWORD=admin123 psql -U admin -d adx_system -c "
|
|
UPDATE admin.brain_configs
|
|
SET is_winner = false
|
|
WHERE is_winner = true
|
|
AND (inbox_rate < 70 OR last_tested < NOW() - INTERVAL '6 months');
|
|
" 2>/dev/null
|
|
|
|
echo "$(date) - Promoted $COUNT new winners" >> $LOG_FILE
|
|
echo "{\"new_winners\":$COUNT}"
|