forked from santifer/career-ops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalize-statuses.mjs
More file actions
173 lines (136 loc) · 5.4 KB
/
normalize-statuses.mjs
File metadata and controls
173 lines (136 loc) · 5.4 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env node
/**
* normalize-statuses.mjs — Clean non-canonical states in applications.md
*
* Maps all non-canonical statuses to canonical ones per states.yml:
* Evaluada, Aplicado, Respondido, Entrevista, Oferta, Rechazado, Descartado, NO APLICAR
*
* Also strips markdown bold (**) and dates from the status field,
* moving DUPLICADO info to the notes column.
*
* Run: node career-ops/normalize-statuses.mjs [--dry-run]
*/
import { readFileSync, writeFileSync, copyFileSync, existsSync } from 'fs';
import { join } from 'path';
const CAREER_OPS = new URL('.', import.meta.url).pathname;
// Support both layouts: data/applications.md (boilerplate) and applications.md (original)
const APPS_FILE = existsSync(join(CAREER_OPS, 'data/applications.md'))
? join(CAREER_OPS, 'data/applications.md')
: join(CAREER_OPS, 'applications.md');
const DRY_RUN = process.argv.includes('--dry-run');
// Canonical status mapping
function normalizeStatus(raw) {
// Strip markdown bold
let s = raw.replace(/\*\*/g, '').trim();
const lower = s.toLowerCase();
// DUPLICADO variants → Descartado
if (/^duplicado/i.test(s) || /^dup\b/i.test(s)) {
return { status: 'Descartado', moveToNotes: raw.trim() };
}
// CERRADA → Descartado
if (/^cerrada$/i.test(s)) return { status: 'Descartado' };
// Cancelada (possibly with date) → Descartado
if (/^cancelada/i.test(s)) return { status: 'Descartado' };
// Descartada → Descartado
if (/^descartada$/i.test(s)) return { status: 'Descartado' };
// Rechazada → Rechazado
if (/^rechazada$/i.test(s)) return { status: 'Rechazado' };
// Rechazado with date → Rechazado (strip date)
if (/^rechazado\s+\d{4}/i.test(s)) return { status: 'Rechazado' };
// Aplicado with date → Aplicado (strip date)
if (/^aplicado\s+\d{4}/i.test(s)) return { status: 'Aplicado' };
// CONDICIONAL → Evaluada
if (/^condicional$/i.test(s)) return { status: 'Evaluada' };
// HOLD → Evaluada
if (/^hold$/i.test(s)) return { status: 'Evaluada' };
// MONITOR → Evaluada
if (/^monitor$/i.test(s)) return { status: 'Evaluada' };
// EVALUAR → Evaluada
if (/^evaluar$/i.test(s)) return { status: 'Evaluada' };
// Verificar → Evaluada
if (/^verificar$/i.test(s)) return { status: 'Evaluada' };
// GEO BLOCKER → NO APLICAR
if (/geo.?blocker/i.test(s)) return { status: 'NO APLICAR' };
// Repost #NNN → Descartado
if (/^repost/i.test(s)) return { status: 'Descartado', moveToNotes: raw.trim() };
// "—" (em dash, no status) → Descartado
if (s === '—' || s === '-' || s === '') return { status: 'Descartado' };
// Already canonical — just fix casing/bold
const canonical = [
'Evaluada', 'Aplicado', 'Respondido', 'Entrevista',
'Oferta', 'Rechazado', 'Descartado', 'NO APLICAR',
];
for (const c of canonical) {
if (lower === c.toLowerCase()) return { status: c };
}
// Aliases from states.yml
if (['enviada', 'aplicada', 'applied', 'sent'].includes(lower)) return { status: 'Aplicado' };
if (['cerrada', 'descartada'].includes(lower)) return { status: 'Descartado' };
if (['no aplicar', 'no_aplicar', 'skip'].includes(lower)) return { status: 'NO APLICAR' };
// Unknown — flag it
return { status: null, unknown: true };
}
// Read applications.md
if (!existsSync(APPS_FILE)) {
console.log('No applications.md found. Nothing to normalize.');
process.exit(0);
}
const content = readFileSync(APPS_FILE, 'utf-8');
const lines = content.split('\n');
let changes = 0;
let unknowns = [];
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (!line.startsWith('|')) continue;
const parts = line.split('|').map(s => s.trim());
// Format: ['', '#', 'fecha', 'empresa', 'rol', 'score', 'STATUS', 'pdf', 'report', 'notas', '']
if (parts.length < 9) continue;
if (parts[1] === '#' || parts[1] === '---' || parts[1] === '') continue;
const num = parseInt(parts[1]);
if (isNaN(num)) continue;
const rawStatus = parts[6];
const result = normalizeStatus(rawStatus);
if (result.unknown) {
unknowns.push({ num, rawStatus, line: i + 1 });
continue;
}
if (result.status === rawStatus) continue; // Already canonical
// Apply change
const oldStatus = rawStatus;
parts[6] = result.status;
// Move DUPLICADO info to notes if needed
if (result.moveToNotes && parts[9]) {
const existing = parts[9] || '';
if (!existing.includes(result.moveToNotes)) {
parts[9] = result.moveToNotes + (existing ? '. ' + existing : '');
}
} else if (result.moveToNotes && !parts[9]) {
parts[9] = result.moveToNotes;
}
// Also strip bold from score field
if (parts[5]) {
parts[5] = parts[5].replace(/\*\*/g, '');
}
// Reconstruct line
const newLine = '| ' + parts.slice(1, -1).join(' | ') + ' |';
lines[i] = newLine;
changes++;
console.log(`#${num}: "${oldStatus}" → "${result.status}"`);
}
if (unknowns.length > 0) {
console.log(`\n⚠️ ${unknowns.length} unknown statuses:`);
for (const u of unknowns) {
console.log(` #${u.num} (line ${u.line}): "${u.rawStatus}"`);
}
}
console.log(`\n📊 ${changes} statuses normalized`);
if (!DRY_RUN && changes > 0) {
// Backup first
copyFileSync(APPS_FILE, APPS_FILE + '.bak');
writeFileSync(APPS_FILE, lines.join('\n'));
console.log('✅ Written to applications.md (backup: applications.md.bak)');
} else if (DRY_RUN) {
console.log('(dry-run — no changes written)');
} else {
console.log('✅ No changes needed');
}