Ajusta detalhamento do componente B no frontend

This commit is contained in:
Frederico Castro
2025-12-13 08:15:44 -03:00
parent 9d2a300df5
commit abfd11d4de
4 changed files with 742 additions and 52 deletions

View File

@@ -8,6 +8,43 @@ const api = axios.create({
timeout: 180000,
});
const calcularComponenteB = (coordenacoesProgramas = []) => {
if (!coordenacoesProgramas.length) {
return { base: 0, tempo: 0, extras: 0, bonus: 0, total: 0 };
}
const agora = new Date();
const base = 70;
let anosTotais = 0;
coordenacoesProgramas.forEach((coord) => {
const inicio = coord.periodo?.inicio ? new Date(coord.periodo.inicio) : null;
const fim = coord.periodo?.fim ? new Date(coord.periodo.fim) : agora;
if (inicio && fim >= inicio) {
const diffAnos = Math.floor((fim - inicio) / (365 * 24 * 60 * 60 * 1000));
anosTotais += diffAnos;
}
});
const tempo = Math.min(anosTotais * 5, 50);
const programasDistintos = new Set(
coordenacoesProgramas.map((c) => c.id_programa || c.codigo_programa || c.nome_programa)
).size;
const extras = programasDistintos > 1 ? Math.min((programasDistintos - 1) * 20, 40) : 0;
let maiorNota = 0;
coordenacoesProgramas.forEach((coord) => {
const n = String(coord.nota_ppg || '').trim();
if (['7', '6', '5', '4', '3'].includes(n)) {
maiorNota = Math.max(maiorNota, parseInt(n, 10));
}
});
const bonus = ({ 7: 20, 6: 15, 5: 10, 4: 5, 3: 0 }[maiorNota] ?? 0);
const total = base + tempo + extras + bonus;
return { base, tempo, extras, bonus, total };
};
export const rankingService = {
async getRanking(page = 1, size = 100) {
// Usa ranking paginado (Oracle) para percorrer os 350k
@@ -43,6 +80,20 @@ export const rankingService = {
periodo: mapPeriodo(coord),
}));
let compB;
if (coordenacoesProgramas.length > 0) {
compB = calcularComponenteB(coordenacoesProgramas);
} else {
const totalB = Number(c.componente_b || 0);
compB = {
base: totalB > 0 ? totalB : 0,
tempo: 0,
extras: 0,
bonus: 0,
total: totalB,
};
}
return {
id_pessoa: c.id_pessoa,
nome: c.nome,
@@ -50,7 +101,7 @@ export const rankingService = {
posicao: c.posicao,
pontuacao_total: c.pontuacao_total,
componente_a: c.componente_a,
componente_b: c.componente_b,
componente_b: compB.total,
componente_c: c.componente_c,
componente_d: c.componente_d,
ativo: c.ativo,
@@ -59,7 +110,14 @@ export const rankingService = {
pontuacao: {
pontuacao_total: c.pontuacao_total,
componente_a: { base: c.componente_a, tempo: 0, extras: 0, bonus: 0, retorno: 0, total: c.componente_a },
componente_b: { base: c.componente_b, tempo: 0, extras: 0, bonus: 0, retorno: 0, total: c.componente_b },
componente_b: {
base: compB.base,
tempo: compB.tempo,
extras: compB.extras,
bonus: compB.bonus,
retorno: 0,
total: compB.total,
},
componente_c: { base: c.componente_c, tempo: 0, extras: 0, bonus: 0, retorno: 0, total: c.componente_c },
componente_d: { base: c.componente_d, tempo: 0, extras: 0, bonus: 0, retorno: 0, total: c.componente_d },
},