Spaces:
Running
Running
axeronis commited on
Commit ·
c3b853e
1
Parent(s): bd67dde
feat: advanced sales psychology integration, notification fixes and performance optimization
Browse files
backend/alembic/versions/2026_01_26_add_psychotype_enums.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
"""Add new psychotype enum values for extended DISC classification.
|
| 2 |
-
|
| 3 |
-
Revision ID: add_psychotype_enums
|
| 4 |
-
Revises: 2026_01_24_granular_notif
|
| 5 |
-
Create Date: 2026-01-26
|
| 6 |
-
"""
|
| 7 |
-
from alembic import op
|
| 8 |
-
import sqlalchemy as sa
|
| 9 |
-
|
| 10 |
-
# revision identifiers
|
| 11 |
-
revision = 'add_psychotype_enums'
|
| 12 |
-
down_revision = '2026_01_24_granular_notif'
|
| 13 |
-
branch_labels = None
|
| 14 |
-
depends_on = None
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def upgrade():
|
| 19 |
-
"""Add new psychotype values to the PostgreSQL ENUM."""
|
| 20 |
-
# In PostgreSQL, we need to ALTER TYPE to add new enum values
|
| 21 |
-
# These must be added one by one
|
| 22 |
-
|
| 23 |
-
# Add 'analytical' value
|
| 24 |
-
op.execute("ALTER TYPE psychotype ADD VALUE IF NOT EXISTS 'analytical'")
|
| 25 |
-
|
| 26 |
-
# Add 'driven' value
|
| 27 |
-
op.execute("ALTER TYPE psychotype ADD VALUE IF NOT EXISTS 'driven'")
|
| 28 |
-
|
| 29 |
-
# Add 'emotional' value
|
| 30 |
-
op.execute("ALTER TYPE psychotype ADD VALUE IF NOT EXISTS 'emotional'")
|
| 31 |
-
|
| 32 |
-
# Add 'harmonic' value
|
| 33 |
-
op.execute("ALTER TYPE psychotype ADD VALUE IF NOT EXISTS 'harmonic'")
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def downgrade():
|
| 37 |
-
"""
|
| 38 |
-
PostgreSQL does not support removing values from ENUMs.
|
| 39 |
-
This is a one-way migration.
|
| 40 |
-
"""
|
| 41 |
-
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backend/app/models/lead.py
CHANGED
|
@@ -25,17 +25,11 @@ class LeadHeat(str, Enum):
|
|
| 25 |
|
| 26 |
|
| 27 |
class Psychotype(str, Enum):
|
| 28 |
-
"""DISC personality types
|
| 29 |
-
# Old DISC values (for backward compatibility)
|
| 30 |
DOMINANT = "dominant" # D - Direct, Results-oriented
|
| 31 |
INFLUENTIAL = "influential" # I - Enthusiastic, Social
|
| 32 |
STEADY = "steady" # S - Supportive, Patient
|
| 33 |
CONSCIENTIOUS = "conscientious" # C - Analytical, Detail-oriented
|
| 34 |
-
# New classification values
|
| 35 |
-
ANALYTICAL = "analytical" # Фокус на цифрах и фактах
|
| 36 |
-
DRIVEN = "driven" # Фокус на результате и времени
|
| 37 |
-
EMOTIONAL = "emotional" # Фокус на чувствах и престиже
|
| 38 |
-
HARMONIC = "harmonic" # Фокус на отношениях и доверии
|
| 39 |
UNKNOWN = "unknown"
|
| 40 |
|
| 41 |
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
class Psychotype(str, Enum):
|
| 28 |
+
"""DISC personality types."""
|
|
|
|
| 29 |
DOMINANT = "dominant" # D - Direct, Results-oriented
|
| 30 |
INFLUENTIAL = "influential" # I - Enthusiastic, Social
|
| 31 |
STEADY = "steady" # S - Supportive, Patient
|
| 32 |
CONSCIENTIOUS = "conscientious" # C - Analytical, Detail-oriented
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
UNKNOWN = "unknown"
|
| 34 |
|
| 35 |
|
backend/app/services/ai_core/lead_analyzer.py
CHANGED
|
@@ -640,12 +640,8 @@ async def analyze_lead_impl(
|
|
| 640 |
psychotype_str = await ai_core.llm.analyze_psychotype(user_messages)
|
| 641 |
psychotype_str = psychotype_str.replace("*", "").strip().lower()
|
| 642 |
|
| 643 |
-
# Validate psychotype -
|
| 644 |
-
valid_psychotypes = [
|
| 645 |
-
'dominant', 'influential', 'steady', 'conscientious', # Old DISC
|
| 646 |
-
'analytical', 'driven', 'emotional', 'harmonic', # New classification
|
| 647 |
-
'unknown'
|
| 648 |
-
]
|
| 649 |
if not psychotype_str or psychotype_str not in valid_psychotypes:
|
| 650 |
psychotype_str = 'unknown'
|
| 651 |
|
|
@@ -677,9 +673,6 @@ async def analyze_lead_impl(
|
|
| 677 |
else:
|
| 678 |
lead.heat_level = LeadHeat.JUNK
|
| 679 |
|
| 680 |
-
# DEBUG: Log heat level transition
|
| 681 |
-
print(f"🔥 Heat transition: {previous_heat_level} -> {lead.heat_level} (score: {heat_score})")
|
| 682 |
-
|
| 683 |
# 🔥 HOT LEAD NOTIFICATION
|
| 684 |
if previous_heat_level != LeadHeat.HOT and lead.heat_level == LeadHeat.HOT:
|
| 685 |
print(f"🔥 Lead {lead.id} became HOT! Sending notification...")
|
|
@@ -693,11 +686,6 @@ async def analyze_lead_impl(
|
|
| 693 |
print(f"✅ HOT lead notification sent successfully")
|
| 694 |
except Exception as e:
|
| 695 |
print(f"⚠️ Failed to send HOT lead notification: {e}")
|
| 696 |
-
import traceback
|
| 697 |
-
traceback.print_exc()
|
| 698 |
-
else:
|
| 699 |
-
if lead.heat_level == LeadHeat.HOT:
|
| 700 |
-
print(f"🔥 Lead {lead.id} is still HOT (no new notification, already notified)")
|
| 701 |
|
| 702 |
# 3. Generate and merge summary
|
| 703 |
try:
|
|
|
|
| 640 |
psychotype_str = await ai_core.llm.analyze_psychotype(user_messages)
|
| 641 |
psychotype_str = psychotype_str.replace("*", "").strip().lower()
|
| 642 |
|
| 643 |
+
# Validate psychotype - default to 'unknown' if empty or invalid
|
| 644 |
+
valid_psychotypes = ['dominant', 'influential', 'steady', 'conscientious', 'unknown']
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
if not psychotype_str or psychotype_str not in valid_psychotypes:
|
| 646 |
psychotype_str = 'unknown'
|
| 647 |
|
|
|
|
| 673 |
else:
|
| 674 |
lead.heat_level = LeadHeat.JUNK
|
| 675 |
|
|
|
|
|
|
|
|
|
|
| 676 |
# 🔥 HOT LEAD NOTIFICATION
|
| 677 |
if previous_heat_level != LeadHeat.HOT and lead.heat_level == LeadHeat.HOT:
|
| 678 |
print(f"🔥 Lead {lead.id} became HOT! Sending notification...")
|
|
|
|
| 686 |
print(f"✅ HOT lead notification sent successfully")
|
| 687 |
except Exception as e:
|
| 688 |
print(f"⚠️ Failed to send HOT lead notification: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 689 |
|
| 690 |
# 3. Generate and merge summary
|
| 691 |
try:
|