1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-06-07 21:16:14 +01:00

Finish HackMyCore reshaping.

Reintroduce HackMyCore, dropping the interim submodule, and reorganize
and improve tests.
This commit is contained in:
hacksalot
2016-01-29 15:23:57 -05:00
parent e9971eb882
commit 0f65e4c9f3
130 changed files with 5384 additions and 337 deletions

View File

@ -0,0 +1,139 @@
###*
Employment gap analysis for HackMyResume.
@license MIT. See LICENSE.md for details.
@module inspectors/gap-inspector
###
_ = require 'underscore'
FluentDate = require '../core/fluent-date'
moment = require 'moment'
LO = require 'lodash'
###*
Identify gaps in the candidate's employment history.
###
gapInspector = module.exports =
moniker: 'gap-inspector'
###*
Run the Gap Analyzer on a resume.
@method run
@return {Array} 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: (rez) ->
# This is what we'll return
coverage =
gaps: []
overlaps: []
pct: '0%'
duration:
total: 0
work: 0
gaps: 0
# Missing employment section? Bye bye.
hist = LO.get rez, 'employment.history'
return coverage if !hist || !hist.length
# 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.
new_e = hist.map( ( job ) ->
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, remove empties, and sort
new_e = _.filter _.flatten( new_e, true ), (v) ->
return v && v.length && v[0] && v[0].length
return coverage if !new_e || !new_e.length
new_e = _.sortBy new_e, ( elem ) -> return elem[1].unix()
# 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 reaches 2, the candidate is overlapped.
num_gaps = 0
ref_count = 0
total_gap_days = 0
gap_start = null
new_e.forEach (point) ->
inc = if point[0] == 'start' then 1 else -1
ref_count += inc
# If the ref count just reached 0, start a new GAP
if ref_count == 0
coverage.gaps.push( { start: point[1], end: null })
# If the ref count reached 1 by rising, end the last GAP
else if ref_count == 1 && inc == 1
lastGap = _.last( coverage.gaps )
if lastGap
lastGap.end = point[1]
lastGap.duration = lastGap.end.diff( lastGap.start, 'days' )
total_gap_days += lastGap.duration
# If the ref count reaches 2 by rising, start a new OVERLAP
else if ref_count == 2 && inc == 1
coverage.overlaps.push( { start: point[1], end: null })
# If the ref count reaches 1 by falling, end the last OVERLAP
else if ref_count == 1 && inc == -1
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()
# It's possible that the last gap/overlap didn't have an explicit .end
# date.If so, set the end date to the present date and compute the
# duration normally.
if coverage.overlaps.length
o = _.last( coverage.overlaps )
if o && !o.end
o.end = moment()
o.duration = o.end.diff( o.start, 'days' )
if coverage.gaps.length
g = _.last( coverage.gaps )
if g && !g.end
g.end = moment()
g.duration = g.end.diff( g.start, 'days' )
# Package data for return to the client
tdur = rez.duration('days')
dur =
total: tdur
work: tdur - total_gap_days
gaps: total_gap_days
coverage.pct = if dur.total > 0 && dur.work > 0 then ((((dur.total - dur.gaps) / dur.total) * 100)).toFixed(1) + '%' else '???'
coverage.duration = dur
coverage

View File

@ -0,0 +1,68 @@
###*
Keyword analysis for HackMyResume.
@license MIT. See LICENSE.md for details.
@module inspectors/keyword-inspector
###
_ = require('underscore')
FluentDate = require('../core/fluent-date')
###*
Analyze the resume's use of keywords.
TODO: BUG: Keyword search regex is inaccurate, especially for one or two
letter keywords like "C" or "CLI".
@class keywordInspector
###
keywordInspector = module.exports =
###* A unique name for this inspector. ###
moniker: 'keyword-inspector'
###*
Run the Keyword Inspector on a resume.
@method run
@return An collection of statistical keyword data.
###
run: ( rez ) ->
# "Quote" or safely escape a keyword so it can be used as a regex. For
# example, if the keyword is "C++", yield "C\+\+".
# http://stackoverflow.com/a/2593661/4942583
regex_quote = (str) -> (str + '').replace(/[.?*+^$[\]\\(){}|-]/ig, "\\$&")
# Create a searchable plain-text digest of the resume
# TODO: BUG: Don't search within keywords for other keywords. Job A
# declares the "foo" keyword. Job B declares the "foo & bar" keyword. Job
# B's mention of "foobar" should not count as a mention of "foo".
# To achieve this, remove keywords from the search digest and treat them
# separately.
searchable = ''
rez.transformStrings ['imp', 'computed', 'safe'], ( key, val ) ->
searchable += ' ' + val
# Assemble a regex skeleton we can use to test for keywords with a bit
# more
prefix = '(?:' + ['^', '\\s+', '[\\.,]+'].join('|') + ')'
suffix = '(?:' + ['$', '\\s+', '[\\.,]+'].join('|') + ')'
return rez.keywords().map (kw) ->
# 1. Using word boundary or other regex class is inaccurate
#
# var regex = new RegExp( '\\b' + regex_quote( kw )/* + '\\b'*/, 'ig');
#
# 2. Searching for the raw keyword is inaccurate ("C" will match any
# word containing a 'c'!).
#
# var regex = new RegExp( regex_quote( kw ), 'ig');
#
# 3. Instead, use a custom regex with special delimeters.
regex_str = prefix + regex_quote( kw ) + suffix
regex = new RegExp( regex_str, 'ig')
myArray = null
count = 0
while (myArray = regex.exec( searchable )) != null
count++
name: kw
count: count

View File

@ -0,0 +1,36 @@
###*
Section analysis for HackMyResume.
@license MIT. See LICENSE.md for details.
@module inspectors/totals-inspector
###
_ = require 'underscore'
FluentDate = require '../core/fluent-date'
###*
Retrieve sectional overview and summary information.
@class totalsInspector
###
totalsInspector = module.exports =
moniker: 'totals-inspector'
###*
Run the Totals Inspector on a resume.
@method run
@return An object containing summary information for each section on the
resume.
###
run: ( rez ) ->
sectionTotals = { }
_.each rez, (val, key) ->
if _.isArray( val ) && !_.isString(val)
sectionTotals[ key ] = val.length
else if val.history && _.isArray( val.history )
sectionTotals[ key ] = val.history.length;
else if val.sets && _.isArray( val.sets )
sectionTotals[ key ] = val.sets.length;
totals: sectionTotals,
numSections: Object.keys( sectionTotals ).length