1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-12-23 05:37:23 +00:00

Handle missing dates during gap inspection.

This commit is contained in:
hacksalot 2016-01-03 23:17:36 -05:00
parent c711cb7922
commit d5afb3eb2e

View File

@ -12,6 +12,7 @@ Employment gap analysis for HackMyResume.
var _ = require('underscore');
var FluentDate = require('../core/fluent-date');
var moment = require('moment');
@ -42,25 +43,41 @@ Employment gap analysis for HackMyResume.
// 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] );
var obj = _.pick( job, ['start', 'end'] );
if( obj && (obj.start || obj.end)) {
obj = _.pairs( obj );
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 );
// 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;
});
// Sort the array, mixing start dates and end dates together
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,
// 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, total_days = 0, total_work_days = 0,
coverage = { gaps: [], overlaps: [] };
new_e.forEach( function(point) {
var inc = point[0] === 'start' ? 1 : -1;
ref_count += inc;
@ -95,10 +112,12 @@ Employment gap analysis for HackMyResume.
// _.each( coverage.overlaps, function(ol) {
// return ol.end = ol.end || now;
// });
if( !_.last( coverage.overlaps ).end ) {
var l = _.last( coverage.overlaps );
l.end = moment();
l.duration = l.end.diff( l.start, 'days' );
if( coverage.overlaps.length ) {
if( !_.last( coverage.overlaps ).end ) {
var l = _.last( coverage.overlaps );
l.end = moment();
l.duration = l.end.diff( l.start, 'days' );
}
}
coverage.duration = total_days;