From 6285c2db3bbfa7ebbce5bd25f54023820bf6299b Mon Sep 17 00:00:00 2001 From: hacksalot Date: Fri, 1 Jan 2016 03:39:48 -0500 Subject: [PATCH] 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. --- package.json | 4 +- src/hackmycmd.js | 1 + src/inspectors/gap-inspector.js | 86 +++++++++++++++++++++++++++++++++ src/verbs/analyze.js | 64 ++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 src/inspectors/gap-inspector.js create mode 100644 src/verbs/analyze.js diff --git a/package.json b/package.json index c6f3eee..bab3436 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/hackmycmd.js b/src/hackmycmd.js index ad62e4e..be9e69b 100644 --- a/src/hackmycmd.js +++ b/src/hackmycmd.js @@ -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'), diff --git a/src/inspectors/gap-inspector.js b/src/inspectors/gap-inspector.js new file mode 100644 index 0000000..5f24b1c --- /dev/null +++ b/src/inspectors/gap-inspector.js @@ -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; + } + + + }; + + + +}()); diff --git a/src/verbs/analyze.js b/src/verbs/analyze.js new file mode 100644 index 0000000..3392add --- /dev/null +++ b/src/verbs/analyze.js @@ -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') + }; + } + + + +}());