50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
// front-end/app/composables/useInteligencia.ts
|
|
import { editais } from '~/data/mock/editais'
|
|
import { concorrentes } from '~/data/mock/concorrentes'
|
|
|
|
export function useInteligencia() {
|
|
const totalEditais = editais.length
|
|
const vencidas = editais.filter(e => e.status === 'vencida')
|
|
const perdidas = editais.filter(e => e.status === 'perdida')
|
|
|
|
const taxaVitoria = computed(() =>
|
|
totalEditais > 0 ? Math.round((vencidas.length / totalEditais) * 100) : 0
|
|
)
|
|
|
|
const valorGanho = computed(() =>
|
|
vencidas.reduce((acc, e) => acc + e.valorEstimado, 0)
|
|
)
|
|
|
|
const ticketMedio = computed(() =>
|
|
vencidas.length > 0 ? valorGanho.value / vencidas.length : 0
|
|
)
|
|
|
|
const porModalidade = computed(() => {
|
|
const counts: Record<string, { total: number; vitorias: number }> = {}
|
|
for (const e of editais) {
|
|
if (!counts[e.modalidade]) counts[e.modalidade] = { total: 0, vitorias: 0 }
|
|
counts[e.modalidade].total++
|
|
if (e.status === 'vencida') counts[e.modalidade].vitorias++
|
|
}
|
|
return counts
|
|
})
|
|
|
|
const motivoPerda = computed(() => {
|
|
const motivos = [
|
|
'GOV - PERDIDO POR PREÇO',
|
|
'GOV - PERDIDO POR DOCUMENTAÇÃO',
|
|
'GOV - PERDIDO NO ALEATÓRIO',
|
|
'GOV - DECLINADO POR REQUISITO TÉCNICO',
|
|
'GOV - DECLINADO OUTROS',
|
|
'Outro',
|
|
]
|
|
return motivos.map((m, i) => ({ motivo: m, quantidade: [3, 1, 1, 1, 0, 1][i] ?? 0 }))
|
|
})
|
|
|
|
const concorrentesFrequentes = computed(() =>
|
|
[...concorrentes].sort((a, b) => b.totalDisputas - a.totalDisputas).slice(0, 5)
|
|
)
|
|
|
|
return { taxaVitoria, valorGanho, ticketMedio, porModalidade, motivoPerda, concorrentesFrequentes, vencidas, perdidas }
|
|
}
|