1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-07-02 08:20:05 +01:00

Introduce "analyze" verb and framework.

Introduce a new "analyze" command and start setting up the inspector /
analyzer pipeline with a simple "gap analysis" inspector using a
reference-counted gap detection approach.
This commit is contained in:
hacksalot 2016-01-01 03:39:48 -05:00
parent 3453293c79
commit 6285c2db3b
4 changed files with 153 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "hackmyresume",
"version": "1.3.1",
"version": "1.4.0",
"description": "Generate polished résumés and CVs in HTML, Markdown, LaTeX, MS Word, PDF, plain text, JSON, XML, YAML, smoke signal, and carrier pigeon.",
"repository": {
"type": "git",
@ -47,7 +47,7 @@
"dependencies": {
"colors": "^1.1.2",
"copy": "^0.1.3",
"fresca": "~0.2.2",
"fresca": "~0.2.4",
"fresh-themes": "~0.9.3-beta",
"fs-extra": "^0.24.0",
"handlebars": "^4.0.5",

View File

@ -25,6 +25,7 @@ Internal resume generation logic for HackMyResume.
*/
var v = {
build: require('./verbs/generate'),
analyze: require('./verbs/analyze'),
validate: require('./verbs/validate'),
convert: require('./verbs/convert'),
new: require('./verbs/create'),

View File

@ -0,0 +1,86 @@
/**
Employment gap analysis for HackMyResume.
@license MIT. See LICENSE.md for details.
@module gap-analyzer.js
*/
(function() {
var _ = require('underscore');
var FluentDate = require('../core/fluent-date');
/**
Identify gaps in the candidate's employment history.
@class gapInspector
*/
var gapInspector = module.exports = {
moniker: 'gap-inspector',
/**
Run the Gap Analyzer on a resume.
@method run
@return An array of object representing gaps in the candidate's employment
history. Each object provides the start, end, and duration of the gap:
{ <-- gap
start: // A Moment.js date
end: // A Moment.js date
duration: // Gap length
}
*/
run: function( rez ) {
// Convert the candidate's employment history to an array of dates,
// where each element in the array is a start date or an end date of a
// job -- it doesn't matter which.
var new_e = rez.employment.history.map( function( job ){
var obj = _.pairs( _.pick( job, ['start', 'end'] ) );
obj[0][1] = FluentDate.fmt( obj[0][1] );
if( obj.length > 1 )
obj[1][1] = FluentDate.fmt( obj[1][1] );
return obj;
});
// Flatten the array.
new_e = _.flatten( new_e, true );
// Sort the array, mixing start dates and end dates together
new_e = _.sortBy( new_e, function( elem ) { return elem[1].unix(); });
// Iterative over elements in the array. Each time a start date is found,
// increment a reference count. Each time an end date is found, decrement
// the reference count. When the reference count reaches 0, we have a gap.
// When the reference count is > 0, the candidate is employed.
var num_gaps = 0, ref_count = 0, gap_start,gaps = [];
new_e.forEach( function(point) {
var inc = point[0] === 'start' ? 1 : -1;
ref_count += inc;
if( ref_count === 0 ) {
gaps.push( { start: point[1], end: null });
}
else if( ref_count === 1 && inc === 1 ) {
var lastGap = _.last( gaps );
if( lastGap ) {
lastGap.end = point[1];
lastGap.duration = lastGap.end.diff( lastGap.start, 'days' );
}
}
});
return gaps;
}
};
}());

64
src/verbs/analyze.js Normal file
View File

@ -0,0 +1,64 @@
/**
Implementation of the 'analyze' verb for HackMyResume.
@module create.js
@license MIT. See LICENSE.md for details.
*/
(function(){
var FLUENT = require('../hackmyapi')
, MKDIRP = require('mkdirp')
, PATH = require('path')
, _ = require('underscore')
, ResumeFactory = require('../core/resume-factory');
/**
Run the 'analyze' command.
*/
module.exports = function analyze( src, dst, opts, logger ) {
var _log = logger || console.log;
if( !src || !src.length ) throw { fluenterror: 8 };
var sourceResumes = ResumeFactory.load( src, _log, null, true );
var nlzrs = _loadInspectors();
sourceResumes.forEach( function(r) {
_analyze( r, nlzrs, opts, _log );
});
};
/**
Analyze a single resume.
*/
function _analyze( resumeObject, nlzrs, opts, log ) {
var rez = resumeObject.rez;
var safeFormat = rez.meta.format.startsWith('FRESH') ? 'FRESH' : 'JRS';
log('Analyzing '.useful + safeFormat.useful.bold +
' resume: '.useful + resumeObject.file.useful.bold);
var info = _.mapObject( nlzrs, function(val, key) {
return val.run( resumeObject.rez );
});
console.log('Gaps: ' + info.gaps.length );
}
/**
Load inspectors.
*/
function _loadInspectors() {
return {
gaps: require('../inspectors/gap-inspector')
};
}
}());