forked from Mroziu12/DVP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessExperienceLevel.js
More file actions
86 lines (72 loc) · 2.7 KB
/
processExperienceLevel.js
File metadata and controls
86 lines (72 loc) · 2.7 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const fs = require('fs');
const path = require('path');
/**
* Process ClearOffers.json to extract experience level distribution
* for pie chart visualization.
*
* Experience levels: Junior, Mid, Senior, Lead
* Note: "unknown" values are treated as "Lead"
*/
function processExperienceLevel() {
try {
// Read the ClearOffers.json file
const dataPath = path.join(__dirname, '..', 'ClearOffers2.json');
const rawData = fs.readFileSync(dataPath, 'utf8');
const offers = JSON.parse(rawData);
// Initialize counters
const experienceCounts = {
'Junior': 0,
'Mid': 0,
'Senior': 0,
'Lead': 0
};
// Process each offer
offers.forEach(offer => {
let level = offer.experience_level;
// Treat "unknown" as "Lead"
if (!level || level.toLowerCase() === 'unknown') {
level = 'Lead';
}
// Normalize the level name (capitalize first letter)
const normalizedLevel = level.charAt(0).toUpperCase() + level.slice(1).toLowerCase();
// Increment counter if it's a valid level
if (experienceCounts.hasOwnProperty(normalizedLevel)) {
experienceCounts[normalizedLevel]++;
} else {
// If we encounter an unexpected level, log it and count as Lead
console.warn(`Unexpected experience level: "${level}" - treating as Lead`);
experienceCounts['Lead']++;
}
});
// Convert to pie chart format
const pieChartData = Object.entries(experienceCounts).map(([label, value]) => ({
label,
value
}));
// Calculate percentages
const total = offers.length;
const dataWithPercentages = pieChartData.map(item => ({
...item,
percentage: ((item.value / total) * 100).toFixed(2)
}));
// Output results
console.log('\n=== Experience Level Distribution ===');
console.log(`Total offers analyzed: ${total}`);
console.log('\nBreakdown:');
dataWithPercentages.forEach(item => {
console.log(` ${item.label}: ${item.value} (${item.percentage}%)`);
});
console.log('\n=== Pie Chart Data ===');
console.log(JSON.stringify(pieChartData, null, 2));
return pieChartData;
} catch (error) {
console.error('Error processing experience level data:', error.message);
throw error;
}
}
// Run the processor if executed directly
if (require.main === module) {
processExperienceLevel();
}
// Export for use in other modules
module.exports = processExperienceLevel;