Skip to content

Instantly share code, notes, and snippets.

@lmaccherone
Created January 25, 2012 02:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmaccherone/1674264 to your computer and use it in GitHub Desktop.
Save lmaccherone/1674264 to your computer and use it in GitHub Desktop.
Using ChartTime to divvy up Release resources across Iterations
{ChartTimeRange, ChartTime, ChartTimeIterator} = require('../src/ChartTime')
# Setting up the context
workDays = 'Monday, Tuesday, Wednesday, Thursday, Friday'
holidays = [
{month: 1, day: 1},
{month: 7, day: 4},
{month: 12, day: 25},
{year: 2012, month: 5, day: 28}
# Fill in the rest for your company if you want holidays taken into account
]
spec = {
workDays: workDays,
holidays: holidays
}
# Establishing the releases
rawReleases = [
{start: '2010-01-01', pastEnd: '2016-01-01', resources: 300},
{start: '2012-02-01', pastEnd: '2013-01-01', resources: 100},
{start: '2011-10-31', pastEnd: '2012-02-01', resources: 80},
{start: '2011-11-03', pastEnd: '2012-01-28', resources: 25},
{start: '2011-12-29', pastEnd: '2012-12-30', resources: 140},
]
releases = []
max = new ChartTime('BEFORE_FIRST', 'day')
min = new ChartTime('PAST_LAST', 'day')
for release, idx in rawReleases
spec.start = release.start
spec.pastEnd = release.pastEnd
temp = new ChartTimeRange(spec)
temp.resources = release.resources # Attaching to ChartTimeRange Object. Hackish but works in javascript
if temp.start.$lt(min) then min = temp.start
if temp.pastEnd.$gt(max) then max = temp.pastEnd
releases.push(temp)
# Counting the number of work days in each release and dividing all of the resources up by that number of days
for release in releases
release.workDays = release.getIterator().getAll().length
release.resourcesPerWorkDay = release.resources / release.workDays
# Establishing an iterator covering the entire range of work days from the earliest release start to the latest release end
allDaysRangeSpec = {
start: min,
pastEnd: max,
holidays: holidays,
workDays: workDays
}
allDaysIterator = new ChartTimeIterator(allDaysRangeSpec)
resourcesPerDay = {}
while allDaysIterator.hasNext()
day = allDaysIterator.next()
dayString = day.toString()
total = 0
for release in releases
if release.contains(day)
total += release.resourcesPerWorkDay
resourcesPerDay[dayString] = total
# Establishing the range checkers for each iteration and setting the totals to zero
iStart = new ChartTime('2012-01-12') # Iterations start on a Thursday?
iPastEnd = iStart.add(14)
iFinalPastEnd = new ChartTime('2012-05-04')
iterations = {}
while iPastEnd.$lt(iFinalPastEnd)
iStartString = iStart.toString()
spec.start = iStart
spec.pastEnd = iPastEnd
iteration = {
range: new ChartTimeRange(spec),
totalResources: 0
}
iterations[iStartString] = iteration
iStart = iPastEnd
iPastEnd = iStart.add(14)
# Walk through each day and if that day is in an iteration, add it's resources to the iteration
for day, resources of resourcesPerDay
for iStartString, iteration of iterations
if iteration.range.contains(new ChartTime(day))
iteration.totalResources += resources
# Print out the results
for iStartString, iteration of iterations
console.log(iStartString, iteration.totalResources)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment