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

Fix gap analysis glitches.

This commit is contained in:
hacksalot 2016-01-04 00:14:43 -05:00
parent f2001bcbb1
commit 2465f2ce1c
2 changed files with 55 additions and 39 deletions

View File

@ -13,6 +13,7 @@ Employment gap analysis for HackMyResume.
var _ = require('underscore');
var FluentDate = require('../core/fluent-date');
var moment = require('moment');
var LO = require('lodash');
@ -26,6 +27,8 @@ Employment gap analysis for HackMyResume.
moniker: 'gap-inspector',
/**
Run the Gap Analyzer on a resume.
@method run
@ -39,10 +42,26 @@ Employment gap analysis for HackMyResume.
*/
run: function( rez ) {
// This is what we'll return
var coverage = {
gaps: [],
overlaps: [],
duration: {
total: 0,
work: 0,
gaps: 0
},
pct: '0%'
};
// Missing employment section? Bye bye.
var hist = LO.get( rez, 'employment.history' );
if( !hist || !hist.length ) { return coverage; }
// 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 new_e = hist.map( function( job ){
var obj = _.pick( job, ['start', 'end'] );
if( obj && (obj.start || obj.end)) {
obj = _.pairs( obj );
@ -53,30 +72,22 @@ Employment gap analysis for HackMyResume.
return obj;
});
// Flatten the array.
new_e = _.flatten( new_e, true );
// Remove empties (objects that had no .start or .end date)
new_e = _.omit( new_e, function(v) {
var isEmpty = ( !v || !v.length || !v[0] || !v[0].length );
if( isEmpty ) console.log('Found empty');
return isEmpty;
// Flatten the array, remove empties, and sort
new_e = _.filter( _.flatten( new_e, true ), function(v) {
return ( v && v.length && v[0] && v[0].length );
});
// Sort the array, mixing start dates and end dates together
if( !new_e || !new_e.length ) return coverage;
new_e = _.sortBy( new_e, function( elem ) { return elem[1].unix(); });
var num_gaps = 0
, ref_count = 0
, total_days = 0
, total_work_days = 0
, coverage = { gaps: [], overlaps: [] }
, gap_start;
// Iterative over elements in the array. Each time a start date is found,
// Iterate 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.
// When the reference count is > 0, the candidate is employed. When the
// reference count reaches 2, the candidate is overlapped.
var num_gaps = 0, ref_count = 0, total_gap_days = 0, total_work_days = 0
, gap_start;
new_e.forEach( function(point) {
var inc = point[0] === 'start' ? 1 : -1;
@ -89,29 +100,28 @@ Employment gap analysis for HackMyResume.
if( lastGap ) {
lastGap.end = point[1];
lastGap.duration = lastGap.end.diff( lastGap.start, 'days' );
total_days += lastGap.duration;
total_gap_days += lastGap.duration;
}
}
else if( ref_count === 2 && inc === 1 ) {
coverage.overlaps.push( { start: point[1], end: null });
}
else if( ref_count === 1 && inc === -1 ) {
var lastOverlap = _.last( coverage.overlaps );
if( lastOverlap ) {
lastOverlap.end = point[1];
lastOverlap.duration = lastOverlap.end.diff( lastOverlap.start, 'days' );
if( lastOverlap.duration === 0 ) {
var lastOver = _.last( coverage.overlaps );
if( lastOver ) {
lastOver.end = point[1];
lastOver.duration = lastOver.end.diff( lastOver.start, 'days' );
if( lastOver.duration === 0 ) {
coverage.overlaps.pop();
}
total_work_days += lastOverlap.duration;
total_work_days += lastOver.duration;
}
}
});
// var now = moment();
// _.each( coverage.overlaps, function(ol) {
// return ol.end = ol.end || now;
// });
// It's possible that the last overlap didn't have an explicit .end date.
// If so, set the end date to the present date and compute the overlap
// duration normally.
if( coverage.overlaps.length ) {
if( !_.last( coverage.overlaps ).end ) {
var l = _.last( coverage.overlaps );
@ -120,11 +130,15 @@ Employment gap analysis for HackMyResume.
}
}
coverage.duration = total_days;
coverage.pct = ( total_days > 0 ) ?
(100.0 - ( total_days / rez.duration('days') * 100)).toFixed(1) + '%' :
var dur = {
total: rez.duration('days'),
work: total_work_days,
gaps: total_gap_days
};
coverage.pct = ( dur.total > 0 && dur.work > 0 ) ?
((((dur.total - dur.gaps) / dur.total) * 100)).toFixed(1) + '%' :
'???';
coverage.duration = dur;
return coverage;
}

View File

@ -58,18 +58,20 @@ Implementation of the 'analyze' verb for HackMyResume.
log(chalk.cyan.bold('\nSECTIONS') + chalk.cyan(' (') + chalk.white.bold(_.keys(info.totals).length) + chalk.cyan('):\n'));
var pad = require('string-padding');
_.each( info.totals, function(tot, key) {
log(chalk.cyan(pad(key + ': ',20)) + chalk.cyan.bold(pad(tot.toString(),4)));
log(chalk.cyan(pad(key + ': ',20)) + chalk.cyan.bold(pad(tot.toString(),5)));
});
log();
log(chalk.cyan.bold('COVERAGE') + chalk.cyan(' (') + chalk.white.bold( info.coverage.pct ) + chalk.cyan('):\n'));
log(chalk.cyan(pad('Gaps: ', padding + 3)) + chalk.cyan.bold(info.coverage.gaps.length) + chalk.cyan(' [') + info.coverage.gaps.map(function(g) {
log(chalk.cyan(pad('Total Days: ', padding)) + chalk.cyan.bold( pad(info.coverage.duration.total.toString(),5) ));
log(chalk.cyan(pad('Employed: ', padding)) + chalk.cyan.bold( pad((info.coverage.duration.total - info.coverage.duration.gaps).toString(),5) ));
log(chalk.cyan(pad('Gaps: ', padding + 4)) + chalk.cyan.bold(info.coverage.gaps.length) + chalk.cyan(' [') + info.coverage.gaps.map(function(g) {
var clr = 'green';
if( g.duration > 35 ) clr = 'yellow';
if( g.duration > 90 ) clr = 'red';
return chalk[clr].bold( g.duration) ;
}).join(', ') + chalk.cyan(']') );
log(chalk.cyan(pad('Overlaps: ', padding + 3)) + chalk.cyan.bold(info.coverage.overlaps.length) + chalk.cyan(' [') + info.coverage.overlaps.map(function(ol) {
log(chalk.cyan(pad('Overlaps: ', padding + 4)) + chalk.cyan.bold(info.coverage.overlaps.length) + chalk.cyan(' [') + info.coverage.overlaps.map(function(ol) {
var clr = 'green';
if( ol.duration > 35 ) clr = 'yellow';
if( ol.duration > 90 ) clr = 'red';
@ -82,10 +84,10 @@ Implementation of the 'analyze' verb for HackMyResume.
chalk.cyan('):\n\n') +
info.keywords.map(function(g) {
tot += g.count;
return chalk.cyan( pad(g.name + ': ', padding) ) + chalk.cyan.bold( pad( g.count.toString(), 4 )) + chalk.cyan(' mentions');
return chalk.cyan( pad(g.name + ': ', padding) ) + chalk.cyan.bold( pad( g.count.toString(), 5 )) + chalk.cyan(' mentions');
}).join('\n'));
log(chalk.cyan( pad('TOTAL: ', padding) ) + chalk.white.bold( pad( tot.toString(), 4 )) + chalk.cyan(' mentions'));
log(chalk.cyan( pad('TOTAL: ', padding) ) + chalk.white.bold( pad( tot.toString(), 5 )) + chalk.cyan(' mentions'));
}