Atualização do promt + correção de bug *Cristiano*

This commit is contained in:
2026-02-13 14:17:21 -03:00
parent 7b9011403b
commit 5bfaeefdb2
3 changed files with 106 additions and 54 deletions

View File

@@ -5,7 +5,7 @@ use polars::prelude::*;
use reqwest;
use std::env;
use std::time::Duration;
use std::path::Path;
use csv;
use std::fs::metadata;
@@ -22,15 +22,15 @@ struct CsvHeader {
#[derive(Debug, serde::Deserialize)]
struct CsvEvaluation {
APRESENTAÇÃO: u8,
APRESENTACAO: u8,
CONFIRMAÇÃO_DE_EMAIL: u8,
CONFIRMAÇÃO_DE_TELEFONE: u8,
PROTOCOLO: u8,
USO_DO_PORTUGUÊS: u8,
PACIÊNCIA_E_EDUCAÇÃO: u8,
USO_DO_PORTUGUES: u8,
PACIENCIA_E_EDUCACAO: u8,
DISPONIBILIDADE: u8,
CONHECIMENTO_TÉCNICO: u8,
DIDATISMO: u8,
// CONHECIMENTO_TÉCNICO: u8,
ESCLARECIMENTO: u8,
ID_TALK: String,
}
@@ -254,47 +254,103 @@ fn main() {
eprintln!("📏 Tamanho: {} bytes", meta.len());
}
// Opcional: mostrar as primeiras linhas do CSV
eprintln!("📄 Primeiras 200 caracteres do CSV:\n{}", &ai_response[..200.min(ai_response.len())]);
//
// Opcional: mostrar as primeiras linhas do CSV
eprintln!("📄 Primeiras 200 caracteres do CSV antes de sanitizar:\n{}", &ai_response[..200.min(ai_response.len())]);
//
let mut reader = csv::ReaderBuilder::new()
.has_headers(true)
.delimiter(b';')
.from_reader(ai_response.as_bytes());
// --- SALVAR CSV SANITIZADO PARA INSPEÇÃO ---
//let sanitized_path = file_path_csv.path().with_extension("sanitized.csv");
// if let Err(e) = std::fs::write(&sanitized_path, &ai_response) {
// eprintln!("⚠️ Erro ao salvar CSV sanitizado: {}", e);
//} else {
// eprintln!("💾 CSV sanitizado salvo: {:?}", sanitized_path);
// }
// ---------------------------------------------
// ---------- LOG 2: tenta desserializar e conta os registros ----------
let deserialized = reader.deserialize::<CsvHeader>().collect::<Vec<_>>();
eprintln!("🧾 Total de linhas lidas (incluindo cabeçalho?): {}", deserialized.len());
for (i, result) in deserialized.iter().enumerate() {
match result {
Ok(record) => {
eprintln!("✅ Linha {}: CATEGORIA={}, PONTOS={:?}", i, record.CATEGORIA, record.PONTOS);
}
Err(e) => {
eprintln!("❌ Linha {} ERRO: {}", i, e);
}
}
}
//
// --- SALVAR CSV SANITIZADO EM PASTA SEPARADA ---
// Define o diretório base para os arquivos sanitizados
let sanitized_base = Path::new("./evaluations_sanitized");
// Obtém o caminho relativo do arquivo original em relação a "./evaluations"
// Exemplo: "./evaluations/2026-02-09/arquivo.csv" -> "2026-02-09/arquivo.csv"
if let Ok(relative_path) = file_path_csv.path().strip_prefix("./evaluations") {
let dest_path = sanitized_base.join(relative_path);
// Cria o diretório de destino, se necessário
if let Some(parent) = dest_path.parent() {
std::fs::create_dir_all(parent).expect("Falha ao criar diretório para sanitizados");
}
// Altera a extensão para .sanitized.csv (ou mantém .csv, como preferir)
let dest_path = dest_path.with_extension("sanitized.csv");
// Escreve o arquivo
if let Err(e) = std::fs::write(&dest_path, &ai_response) {
eprintln!("⚠️ Erro ao salvar CSV sanitizado em {:?}: {}", dest_path, e);
} else {
eprintln!("💾 CSV sanitizado salvo em: {:?}", dest_path);
}
} else {
eprintln!("⚠️ Caminho do arquivo não está dentro de ./evaluations: {:?}", file_path_csv.path());
}
let mut deserialized_iter = reader.deserialize::<CsvHeader>();
let mut columns = deserialized_iter
.filter_ok(|value| value.PONTOS.is_some())
.map_ok(|value| {
let col =
Column::new(value.CATEGORIA.into(), [value.PONTOS.unwrap() as u32]);
col
})
.filter_map(|value| {
if value.is_ok() {
return Some(value.unwrap());
}
None
})
.collect_vec();
let mut reader = csv::ReaderBuilder::new()
.has_headers(true)
.delimiter(b';')
.from_reader(ai_response.as_bytes());
// ---------- LOG 2: tenta desserializar e conta os registros ----------
let deserialized = reader.deserialize::<CsvHeader>().collect::<Vec<_>>();
eprintln!("🧾 Total de linhas lidas (incluindo cabeçalho?): {}", deserialized.len());
for (i, result) in deserialized.iter().enumerate() {
match result {
Ok(record) => {
eprintln!("✅ Linha {}: CATEGORIA={}, PONTOS={:?}", i, record.CATEGORIA, record.PONTOS);
}
Err(e) => {
eprintln!("❌ Linha {} ERRO: {}", i, e);
}
}
}
//
//let mut deserialized_iter = reader.deserialize::<CsvHeader>();
// let mut columns = deserialized_iter
// .filter_ok(|value| value.PONTOS.is_some())
// .map_ok(|value| {
// let col =
// Column::new(value.CATEGORIA.into(), [value.PONTOS.unwrap() as u32]);
// col
// })
// .filter_map(|value| {
// if value.is_ok() {
// return Some(value.unwrap());
// }
// None
//})
//.collect_vec();
let mut columns = deserialized
.into_iter() // usa os registros já lidos
.filter_ok(|value| {
// Se PONTOS for None, considera como 0 e mantém a linha
true // sempre mantém
})
.map_ok(|value| {
let pontos = value.PONTOS.unwrap_or(0) as u32;
Column::new(value.CATEGORIA.into(), [pontos])
})
//.filter_ok(|value| value.PONTOS.is_some())
//.map_ok(|value| {
//let pontos = value.PONTOS.unwrap() as u32;
//Column::new(value.CATEGORIA.into(), [pontos])
// })
.filter_map(|value| value.ok())
.collect_vec();
if columns.len() != 8 {
return None;