scraper/util.py
def compute_labor_hours(sloc, month_hours='cocomo_book'):
    """
    Compute the labor hours, given a count of source lines of code

    The intention is to use the COCOMO II model to compute this value.

    References:
    - http://csse.usc.edu/tools/cocomoii.php
    - http://docs.python-guide.org/en/latest/scenarios/scrape/
    """
    # Calculation of hours in a month
    if month_hours == 'hours_per_year':
        # Use number of working hours in a year:
        # (40 Hours / week) * (52 weeks / year) / (12 months / year) ~= 173.33
        HOURS_PER_PERSON_MONTH = 40.0 * 52 / 12
    else:
        # Use value from COCOMO II Book (month_hours=='cocomo_book'):
        # Reference: https://dl.acm.org/citation.cfm?id=557000
        # This is the value used by the Code.gov team:
        # https://github.com/GSA/code-gov/blob/master/LABOR_HOUR_CALC.md
        HOURS_PER_PERSON_MONTH = 152.0

    cocomo_url = 'http://csse.usc.edu/tools/cocomoii.php'
    page = requests.post(cocomo_url, data={'new_size': sloc})

    try:
        person_months = float(EFFORT_REGEX.search(page.text).group(1))
    except AttributeError:
        logger.error('Unable to find Person Months in page text: sloc=%s', sloc)
        # If there is no match, and .search(..) returns None
        person_months = 0

    labor_hours = person_months * HOURS_PER_PERSON_MONTH
    logger.debug('sloc=%d labor_hours=%d', sloc, labor_hours)

    return labor_hours
def compute_labor_hours(sloc, month_hours='cocomo_book'):
    # Calculation of hours in a month
    if month_hours == 'hours_per_year':
        # Use number of working hours in a year:
        # (40 Hours / week) * (52 weeks / year) / (12 months / year) ~= 173.33
        HOURS_PER_PERSON_MONTH = 40.0 * 52 / 12
    else:
        # Use value from COCOMO II Book (month_hours=='cocomo_book'):
        # Reference: https://dl.acm.org/citation.cfm?id=557000
        # This is the value used by the Code.gov team:
        # https://github.com/GSA/code-gov/blob/master/LABOR_HOUR_CALC.md
        HOURS_PER_PERSON_MONTH = 152.0

    cocomo_url = 'http://csse.usc.edu/tools/cocomoii.php'
    page = requests.post(cocomo_url, data={'new_size': sloc})

    try:
        person_months = float(EFFORT_REGEX.search(page.text).group(1))
    except AttributeError:
        logger.error('Unable to find Person Months in page text: sloc=%s', sloc)
        # If there is no match, and .search(..) returns None
        person_months = 0

    labor_hours = person_months * HOURS_PER_PERSON_MONTH
    logger.debug('sloc=%d labor_hours=%d', sloc, labor_hours)

    return labor_hours
def compute_labor_hours ( sloc , month_hours = 'cocomo_book' ) : # Calculation of hours in a month if month_hours == 'hours_per_year' : # Use number of working hours in a year: # (40 Hours / week) * (52 weeks / year) / (12 months / year) ~= 173.33 HOURS_PER_PERSON_MONTH = 40.0 * 52 / 12 else : # Use value from COCOMO II Book (month_hours=='cocomo_book'): # Reference: https://dl.acm.org/citation.cfm?id=557000 # This is the value used by the Code.gov team: # https://github.com/GSA/code-gov/blob/master/LABOR_HOUR_CALC.md HOURS_PER_PERSON_MONTH = 152.0 cocomo_url = 'http://csse.usc.edu/tools/cocomoii.php' page = requests . post ( cocomo_url , data = { 'new_size' : sloc } ) try : person_months = float ( EFFORT_REGEX . search ( page . text ) . group ( 1 ) ) except AttributeError : logger . error ( 'Unable to find Person Months in page text: sloc=%s' , sloc ) # If there is no match, and .search(..) returns None person_months = 0 labor_hours = person_months * HOURS_PER_PERSON_MONTH logger . debug ( 'sloc=%d labor_hours=%d' , sloc , labor_hours ) return labor_hours
Compute the labor hours, given a count of source lines of code

    The intention is to use the COCOMO II model to compute this value.

    References:
    - http://csse.usc.edu/tools/cocomoii.php
    - http://docs.python-guide.org/en/latest/scenarios/scrape/
Compute the labor hours given a count of source lines of code