Created
June 4, 2015 22:22
-
-
Save rh0dium/11afa273a841f2f1161e to your computer and use it in GitHub Desktop.
Man hours is simply check-in time minus checkout-time. We normalize this to 8 hours per day (user modifiable) and exclude weekends. Additionally since a person cannot physically work on two files at the same time we divide it out by the number of files in the checkin. It is important to note that man hours is calculated AFTER the event takes pla…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def normalize_man_hours(**kwargs): | |
""" | |
If the time_difference is less than 8 hours than return that. | |
If the time difference is greater than 8 hours we need to limit it to 8 hours per | |
day excluding weekends. | |
""" | |
hours, minutes, seconds = kwargs.get('time_difference', "0:0:0").split(":") | |
hours, minutes, seconds = int(hours), int(minutes), int(seconds) | |
total_seconds = hours * 60 * 60 + minutes * 60 + seconds | |
delta = datetime.timedelta(seconds=max([total_seconds, MINIMUM_CHECKOUT_TIME])) | |
to_date = kwargs.get('timestamp') | |
if isinstance(to_date, basestring): | |
to_date = dateutil.parser.parse(re.sub(":000000", "", to_date)) | |
from_date = to_date - delta | |
# log.debug("Start Date: {} End Date: {}".format( | |
# from_date.strftime("%c"), to_date.strftime("%c"))) | |
time_difference = to_date - from_date | |
hours, remainder = divmod(time_difference.seconds, 3600) | |
minutes, seconds = divmod(remainder, 60) | |
# log.debug("Delta days is {} days, {} hours, {} minutes, {} seconds".format( | |
# time_difference.days, hours, minutes, seconds)) | |
# Filter out weekends | |
day_gen = (from_date + datetime.timedelta(days=x + 1) for x in xrange((to_date - from_date).days)) | |
days = sum(1 for day in day_gen if day.weekday() < 5) | |
total_man_hours = time_difference.seconds/3600.0 | |
if days: | |
# I'll give you the hours if it's past the workday ;) | |
day_one = abs(datetime.datetime( | |
from_date.year, from_date.month, from_date.day, | |
settings.ENVISION_LATEST_WORK_HOUR, 0) - from_date) | |
day_one_hours = min([day_one.seconds/3600.0, settings.ENVISION_MAX_WORKHOURS_PER_DAY]) | |
# log.debug("Day one man hours: {}".format(day_one_hours)) | |
last_day = abs(to_date - datetime.datetime( | |
to_date.year, to_date.month, to_date.day, | |
settings.ENVISION_EARLIEST_WORK_HOUR, 0)) | |
last_day_hours = min([last_day.seconds/3600.0, settings.ENVISION_MAX_WORKHOURS_PER_DAY]) | |
# log.debug("Last day man hours: {}".format(last_day_hours)) | |
remaining_hours = (days - 1) * settings.ENVISION_MAX_WORKHOURS_PER_DAY | |
total_man_hours = day_one_hours + last_day_hours + remaining_hours | |
man_hours = total_man_hours / kwargs.get('qty', 1) | |
log.debug("Change: {} {} Changes: Man hours: {} Total Man Hours: {}".format( | |
kwargs.get('change'), kwargs.get('qty', 1), man_hours, total_man_hours)) | |
return {'man_hours': man_hours} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment