Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function attachAssessmentsAttributes(application, data, preset, stringArray = [], skipProcentage = false) {
- const applicationQuestions = application?.criticalRequirements?.applicationQuestions || [];
- for (const keyString of stringArray) {
- const applicationQuestion = applicationQuestions.find(aq => aq?.question?.qualityAttribute?.key === keyString);
- if (applicationQuestion) {
- data[keyString] = applicationQuestion.answer;
- } else {
- data[keyString] = example[keyString];
- }
- }
- const assessments = ["clarifications", "1st-interview", "2nd-interview", "post_interview_survey"];
- const parsedAvgValues = [];
- for (const assessmentName of assessments) {
- const details = application?.criticalRequirements[assessmentName];
- if (!details) continue;
- const scores = application?.assessments?.[assessmentName]?.scores || [];
- if (!scores || !scores.length) continue;
- const result = details.reduce((res, curr, index) => {
- const key = res.find(r => r.key === curr?.question?.qualityAttribute?.key);
- if (scores[index] === null) return res; // skip nulls
- const score = { ...curr, score: scores[index] };
- if (key) { key.stack.push(score); } else {
- res.push({ key: curr?.question?.qualityAttribute?.key, name: curr?.question?.qualityAttribute?.name, stack: [score] });
- }
- return res;
- }, []).map(item => {
- const arrayStack = (item?.stack || []).filter(item => item.score);
- const score = arrayStack.reduce((r, it) => r + (parseFloat(it.score) || 0), 0);
- const avg = parseFloat(((score / arrayStack.length) || 0).toFixed(3));
- return { ...item, avg };
- }).map(q => _.omit(q, ['stack']));
- parsedAvgValues.push(...result);
- }
- for (const key in preset) {
- if (stringArray.includes(key)) continue;
- const keyInStack = preset[key];
- const item = parsedAvgValues.find(r => r.key === key);
- if (skipProcentage) {
- data[keyInStack] = parseFloat(item?.avg);
- } else {
- data[keyInStack] = parseFloat((((item?.avg || 0) / 7) || 0).toFixed(3));
- }
- }
- return data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement