File size: 2,684 Bytes
fb2a8ad 3253dc0 f59d2a5 fb2a8ad | 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 | // lib/scoring-service.ts
import { authFetch } from "@/lib/api"
import { CalculateWeightPayload, WeightBody } from "@/types/calculate"
import { FilterFormValues } from "@/types/candidate-table"
const BASE_URL = "https://byteriot-candidateexplorer.hf.space/CandidateExplorer/agentic"
function toFilterBody(filters: FilterFormValues) {
return {
gpa_edu_1: filters.educations[0]?.gpa || null,
univ_edu_1: filters.educations[0]?.university || null,
major_edu_1: filters.educations[0]?.major || null,
gpa_edu_2: filters.educations[1]?.gpa || null,
univ_edu_2: filters.educations[1]?.university || null,
major_edu_2: filters.educations[1]?.major || null,
gpa_edu_3: filters.educations[2]?.gpa || null,
univ_edu_3: filters.educations[2]?.university || null,
major_edu_3: filters.educations[2]?.major || null,
domicile: filters.domicile || null,
yoe: filters.yoe || null,
hardskills: filters.hardskills?.length ? [filters.hardskills] : null,
softskills: filters.softskills?.length ? [filters.softskills] : null,
certifications: filters.certifications?.length ? [filters.certifications] : null,
business_domain: filters.businessDomain?.length ? [filters.businessDomain] : null,
}
}
function toWeightBody(value: CalculateWeightPayload): WeightBody {
const edu = (i: number) => value.education[i] ?? { university: 0, major: 0, gpa: 0 }
return {
univ_edu_1: edu(0).university / 100, major_edu_1: edu(0).major / 100, gpa_edu_1: edu(0).gpa / 100,
univ_edu_2: edu(1).university / 100, major_edu_2: edu(1).major / 100, gpa_edu_2: edu(1).gpa / 100,
univ_edu_3: edu(2).university / 100, major_edu_3: edu(2).major / 100, gpa_edu_3: edu(2).gpa / 100,
domicile: value.others.domicile / 100,
yoe: value.others.yearOfExperiences / 100,
hardskills: value.others.hardskills / 100,
softskills: value.others.softskills / 100,
certifications: value.others.certifications / 100,
business_domain: value.others.businessDomain / 100,
}
}
async function postJSON(url: string, body?: unknown) {
const res = await authFetch(url, {
method: "POST",
...(body ? { body: JSON.stringify(body) } : {}),
})
if (!res.ok) throw new Error(`Request failed: ${url} (${res.status})`)
return res.json()
}
export async function createAndCalculateScore(
filters: FilterFormValues,
weights: CalculateWeightPayload
): Promise<{ criteriaId: string }> {
const res = await postJSON("/api/agentic", {
filters,
weights
})
return { criteriaId: res.data.criteria_id }
} |