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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Smart coaching - analyzes user's job search behavior and provides actionable tips.
|
| 3 |
+
"""
|
| 4 |
+
from datetime import datetime, timedelta, timezone
|
| 5 |
+
|
| 6 |
+
from fastapi import APIRouter
|
| 7 |
+
from sqlalchemy import func, select
|
| 8 |
+
|
| 9 |
+
from app.api.deps import CurrentUser, DBSession
|
| 10 |
+
from app.models.application import Application
|
| 11 |
+
from app.models.job import SavedJob
|
| 12 |
+
from app.models.user import Profile
|
| 13 |
+
|
| 14 |
+
router = APIRouter(prefix="/coaching", tags=["coaching"])
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@router.get("/tips")
|
| 18 |
+
async def get_coaching_tips(db: DBSession, user: CurrentUser):
|
| 19 |
+
"""
|
| 20 |
+
Analyze job search behavior and return personalized coaching tips.
|
| 21 |
+
Based on patterns in applications, saved jobs, and profile completeness.
|
| 22 |
+
"""
|
| 23 |
+
now = datetime.now(timezone.utc)
|
| 24 |
+
week_ago = now - timedelta(days=7)
|
| 25 |
+
month_ago = now - timedelta(days=30)
|
| 26 |
+
|
| 27 |
+
tips = []
|
| 28 |
+
|
| 29 |
+
# Check profile completeness
|
| 30 |
+
profile_result = await db.execute(select(Profile).where(Profile.user_id == user.id))
|
| 31 |
+
profile = profile_result.scalar_one_or_none()
|
| 32 |
+
|
| 33 |
+
if not profile or not profile.headline:
|
| 34 |
+
tips.append({
|
| 35 |
+
"priority": "high",
|
| 36 |
+
"category": "profile",
|
| 37 |
+
"tip": "Complete your profile headline",
|
| 38 |
+
"detail": "Profiles with headlines get 3x better AI recommendations. Add a clear headline like 'Senior Frontend Engineer'.",
|
| 39 |
+
"action_url": "/profile",
|
| 40 |
+
})
|
| 41 |
+
|
| 42 |
+
if not profile or not profile.skills or len(profile.skills) < 5:
|
| 43 |
+
tips.append({
|
| 44 |
+
"priority": "high",
|
| 45 |
+
"category": "profile",
|
| 46 |
+
"tip": "Add more skills to your profile",
|
| 47 |
+
"detail": "The AI recommendation engine uses your skills to match jobs. Add at least 8-10 key skills.",
|
| 48 |
+
"action_url": "/profile",
|
| 49 |
+
})
|
| 50 |
+
|
| 51 |
+
if not profile or not profile.experience:
|
| 52 |
+
tips.append({
|
| 53 |
+
"priority": "high",
|
| 54 |
+
"category": "profile",
|
| 55 |
+
"tip": "Add your work experience",
|
| 56 |
+
"detail": "Experience data powers resume tailoring and interview prep. Even 1-2 roles help significantly.",
|
| 57 |
+
"action_url": "/profile",
|
| 58 |
+
})
|
| 59 |
+
|
| 60 |
+
# Application frequency
|
| 61 |
+
weekly_apps = await db.scalar(
|
| 62 |
+
select(func.count(Application.id)).where(
|
| 63 |
+
Application.user_id == user.id, Application.created_at >= week_ago
|
| 64 |
+
)
|
| 65 |
+
) or 0
|
| 66 |
+
|
| 67 |
+
monthly_apps = await db.scalar(
|
| 68 |
+
select(func.count(Application.id)).where(
|
| 69 |
+
Application.user_id == user.id, Application.created_at >= month_ago
|
| 70 |
+
)
|
| 71 |
+
) or 0
|
| 72 |
+
|
| 73 |
+
if weekly_apps == 0 and monthly_apps > 0:
|
| 74 |
+
tips.append({
|
| 75 |
+
"priority": "medium",
|
| 76 |
+
"category": "consistency",
|
| 77 |
+
"tip": "You haven't applied to anything this week",
|
| 78 |
+
"detail": "Consistency beats volume. Try to apply to 3-5 quality jobs per week to maintain momentum.",
|
| 79 |
+
"action_url": "/jobs",
|
| 80 |
+
})
|
| 81 |
+
elif monthly_apps == 0:
|
| 82 |
+
tips.append({
|
| 83 |
+
"priority": "high",
|
| 84 |
+
"category": "action",
|
| 85 |
+
"tip": "Start applying!",
|
| 86 |
+
"detail": "You haven't applied to any jobs yet. Browse jobs and start with roles you're most excited about.",
|
| 87 |
+
"action_url": "/jobs",
|
| 88 |
+
})
|
| 89 |
+
elif weekly_apps > 15:
|
| 90 |
+
tips.append({
|
| 91 |
+
"priority": "medium",
|
| 92 |
+
"category": "quality",
|
| 93 |
+
"tip": "Consider quality over quantity",
|
| 94 |
+
"detail": f"You applied to {weekly_apps} jobs this week. Try tailoring your resume for your top 5 picks instead of spray-and-pray.",
|
| 95 |
+
"action_url": "/resume",
|
| 96 |
+
})
|
| 97 |
+
|
| 98 |
+
# Check response rate
|
| 99 |
+
total_apps = await db.scalar(
|
| 100 |
+
select(func.count(Application.id)).where(Application.user_id == user.id)
|
| 101 |
+
) or 0
|
| 102 |
+
|
| 103 |
+
if total_apps >= 10:
|
| 104 |
+
responded = await db.scalar(
|
| 105 |
+
select(func.count(Application.id)).where(
|
| 106 |
+
Application.user_id == user.id,
|
| 107 |
+
Application.status.in_(("screening", "interviewing", "offer", "accepted", "rejected")),
|
| 108 |
+
)
|
| 109 |
+
) or 0
|
| 110 |
+
|
| 111 |
+
response_rate = (responded / total_apps) * 100
|
| 112 |
+
if response_rate < 15:
|
| 113 |
+
tips.append({
|
| 114 |
+
"priority": "high",
|
| 115 |
+
"category": "resume",
|
| 116 |
+
"tip": "Low response rate - review your resume",
|
| 117 |
+
"detail": f"Your response rate is {response_rate:.0f}%. Industry average is 15-25%. Try the ATS checker to optimize keywords.",
|
| 118 |
+
"action_url": "/ats-checker",
|
| 119 |
+
})
|
| 120 |
+
|
| 121 |
+
# Check saved jobs not applied
|
| 122 |
+
saved_count = await db.scalar(
|
| 123 |
+
select(func.count(SavedJob.id)).where(SavedJob.user_id == user.id)
|
| 124 |
+
) or 0
|
| 125 |
+
|
| 126 |
+
if saved_count > 10 and weekly_apps < 3:
|
| 127 |
+
tips.append({
|
| 128 |
+
"priority": "medium",
|
| 129 |
+
"category": "action",
|
| 130 |
+
"tip": f"You have {saved_count} saved jobs — time to apply!",
|
| 131 |
+
"detail": "Saved jobs expire. Review your saved list and apply to your top choices this week.",
|
| 132 |
+
"action_url": "/saved",
|
| 133 |
+
})
|
| 134 |
+
|
| 135 |
+
# Ghosted applications
|
| 136 |
+
ghosted = await db.scalar(
|
| 137 |
+
select(func.count(Application.id)).where(
|
| 138 |
+
Application.user_id == user.id, Application.status == "ghosted"
|
| 139 |
+
)
|
| 140 |
+
) or 0
|
| 141 |
+
|
| 142 |
+
if ghosted >= 3:
|
| 143 |
+
tips.append({
|
| 144 |
+
"priority": "low",
|
| 145 |
+
"category": "follow_up",
|
| 146 |
+
"tip": f"{ghosted} applications marked as ghosted",
|
| 147 |
+
"detail": "Getting ghosted is normal. Consider sending a brief follow-up email 7 days after applying.",
|
| 148 |
+
"action_url": "/applications",
|
| 149 |
+
})
|
| 150 |
+
|
| 151 |
+
# Networking tip
|
| 152 |
+
if total_apps >= 5 and not tips:
|
| 153 |
+
tips.append({
|
| 154 |
+
"priority": "low",
|
| 155 |
+
"category": "networking",
|
| 156 |
+
"tip": "Boost your odds with networking",
|
| 157 |
+
"detail": "Referrals have 5-10x higher success rates. Use the Networking page to draft outreach messages.",
|
| 158 |
+
"action_url": "/networking",
|
| 159 |
+
})
|
| 160 |
+
|
| 161 |
+
# Sort by priority
|
| 162 |
+
priority_order = {"high": 0, "medium": 1, "low": 2}
|
| 163 |
+
tips.sort(key=lambda t: priority_order.get(t["priority"], 99))
|
| 164 |
+
|
| 165 |
+
return {
|
| 166 |
+
"tips": tips[:5], # Max 5 tips
|
| 167 |
+
"stats": {
|
| 168 |
+
"weekly_applications": weekly_apps,
|
| 169 |
+
"monthly_applications": monthly_apps,
|
| 170 |
+
"total_applications": total_apps,
|
| 171 |
+
"saved_jobs": saved_count,
|
| 172 |
+
},
|
| 173 |
+
}
|