-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
executable file
·174 lines (142 loc) · 6.76 KB
/
test_api.py
File metadata and controls
executable file
·174 lines (142 loc) · 6.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env python3
"""
Script de exemplo para testar a API de Job Matching
"""
import requests
import json
import time
from typing import Dict, List
class JobMatchingAPIClient:
def __init__(self, base_url: str = "http://localhost:8000"):
self.base_url = base_url
def health_check(self) -> Dict:
"""Verificar saúde da API"""
response = requests.get(f"{self.base_url}/health")
response.raise_for_status()
return response.json()
def predict_matches(self, candidate: Dict, jobs: List[Dict],
top_k: int = 5, threshold: float = 0.5) -> Dict:
"""Predizer matches entre candidato e vagas"""
payload = {
"candidate": candidate,
"jobs": jobs,
"top_k": top_k,
"threshold": threshold
}
response = requests.post(
f"{self.base_url}/predict",
json=payload,
headers={"Content-Type": "application/json"}
)
response.raise_for_status()
return response.json()
def main():
# Inicializar cliente
client = JobMatchingAPIClient()
print("🧪 Testando Job Matching API...\n")
# 1. Health Check
print("1. Health Check")
try:
health = client.health_check()
print(f"✅ Status: {health['status']}")
print(f" Device: {health['device']}")
print(f" Models: {'✅' if health['models_loaded'] else '❌'}")
except Exception as e:
print(f"❌ Health check falhou: {e}")
return
print("\n" + "="*50 + "\n")
# 2. Exemplo de Predição - Desenvolvedor Python
print("2. Teste: Desenvolvedor Python")
candidate_dev = {
"cv_pt": "Desenvolvedor Python com 5 anos de experiência em Django, FastAPI e PostgreSQL. Experiência com Docker, Git e metodologias ágeis.",
"objetivo_profissional": "Trabalhar como desenvolvedor backend senior em projetos desafiadores",
"conhecimentos_tecnicos": "Python, Django, FastAPI, PostgreSQL, Docker, Git, REST APIs, pytest"
}
jobs_tech = [
{
"titulo_vaga": "Desenvolvedor Python Senior",
"objetivo_vaga": "Desenvolver APIs e sistemas backend escaláveis",
"principais_atividades": "Programação em Python, desenvolvimento de APIs REST, trabalho com bancos de dados PostgreSQL",
"competencia_tecnicas_e_comportamentais": "Python, Django, FastAPI, PostgreSQL, Docker, trabalho em equipe, proatividade"
},
{
"titulo_vaga": "Analista de Marketing Digital",
"objetivo_vaga": "Gerenciar campanhas de marketing digital e análise de dados",
"principais_atividades": "Google Ads, Facebook Ads, análise de métricas, criação de conteúdo",
"competencia_tecnicas_e_comportamentais": "Marketing digital, Google Analytics, criatividade, comunicação"
},
{
"titulo_vaga": "DevOps Engineer",
"objetivo_vaga": "Automatizar deploy e infraestrutura",
"principais_atividades": "Docker, Kubernetes, CI/CD, monitoramento de aplicações",
"competencia_tecnicas_e_comportamentais": "Docker, Kubernetes, AWS, Python, shell script, proatividade"
}
]
try:
start_time = time.time()
result_dev = client.predict_matches(candidate_dev, jobs_tech, top_k=3, threshold=0.3)
end_time = time.time()
print(f"⏱️ Tempo de processamento: {end_time - start_time:.2f}s")
print(f"📊 Processamento interno: {result_dev['processing_time_ms']:.1f}ms")
print(f"🎯 Matches encontrados: {len(result_dev['recommendations'])}")
print("\n📋 Resultados:")
for i, match in enumerate(result_dev['recommendations'], 1):
print(f" {i}. Job {match['job_index']} - ML Score: {match['ml_score']:.3f} - Similarity: {match['similarity_score']:.3f}")
print(f" Preview: {match['job_preview'][:100]}...")
print()
except Exception as e:
print(f"❌ Erro na predição: {e}")
print("="*50 + "\n")
# 3. Exemplo - Data Scientist
print("3. Teste: Data Scientist")
candidate_ds = {
"cv_pt": "Cientista de dados com mestrado em estatística. Experiência com Python, R, machine learning e deep learning.",
"conhecimentos_tecnicos": "Python, R, pandas, scikit-learn, TensorFlow, PyTorch, SQL, estatística, machine learning"
}
jobs_ds = [
{
"titulo_vaga": "Data Scientist Senior",
"principais_atividades": "Desenvolver modelos de machine learning, análise de dados, Python, R",
"competencia_tecnicas_e_comportamentais": "Python, R, machine learning, estatística, SQL, comunicação"
},
{
"titulo_vaga": "Vendedor Externo",
"principais_atividades": "Vendas porta a porta, relacionamento com clientes",
"competencia_tecnicas_e_comportamentais": "Comunicação, persuasão, proatividade"
}
]
try:
result_ds = client.predict_matches(candidate_ds, jobs_ds, top_k=2, threshold=0.4)
print(f"🎯 Matches encontrados: {len(result_ds['recommendations'])}")
for i, match in enumerate(result_ds['recommendations'], 1):
print(f" {i}. Job {match['job_index']} - ML Score: {match['ml_score']:.3f}")
except Exception as e:
print(f"❌ Erro na predição: {e}")
print("\n" + "="*50 + "\n")
# 4. Teste de Performance
print("4. Teste de Performance (múltiplas vagas)")
# Criar 20 vagas similares
many_jobs = []
for i in range(20):
many_jobs.append({
"titulo_vaga": f"Desenvolvedor {i}",
"objetivo_vaga": f"Desenvolver software {i}",
"principais_atividades": f"Programação, desenvolvimento {i}",
"competencia_tecnicas_e_comportamentais": f"Python, programação {i}"
})
try:
start_time = time.time()
result_perf = client.predict_matches(candidate_dev, many_jobs, top_k=5, threshold=0.2)
end_time = time.time()
print(f"⏱️ Tempo total: {end_time - start_time:.2f}s para {len(many_jobs)} vagas")
print(f"📊 Processamento interno: {result_perf['processing_time_ms']:.1f}ms")
print(f"🎯 Matches encontrados: {len(result_perf['recommendations'])}")
except Exception as e:
print(f"❌ Erro no teste de performance: {e}")
print("\n✅ Testes concluídos!")
print("\n📊 Para monitoramento:")
print(" Grafana: http://localhost:3000")
print(" Prometheus: http://localhost:9090")
print(" Métricas API: http://localhost:8000/metrics")
if __name__ == "__main__":
main()