### Home Classes Methods

### In Files

- lib/taskjuggler/ResourceScenario.rb

### Parent

TaskJuggler::ScenarioData

### Methods

- ::new
- #allocated?
- #available?
- #book
- #bookBooking
- #booked?
- #bookedEffort
- #bookedTask
- #calcCriticalness
- #collectTimeOffIntervals
- #cost
- #finishScheduling
- #getAllocatedSlots
- #getAllocatedTime
- #getBookings
- #getEffectiveFreeTime
- #getEffectiveFreeWork
- #getEffectiveWork
- #getFreeSlots
- #getLeave
- #getLeaveSlots
- #getMaxSlot
- #getMinSlot
- #getTimeOffDays
- #getTimeOffSlots
- #getWorkSlots
- #preScheduleCheck
- #prepareScheduling
- #query_annualleave
- #query_annualleavebalance
- #query_cost
- #query_effort
- #query_effortdone
- #query_effortleft
- #query_freetime
- #query_freework
- #query_fte
- #query_headcount
- #query_rate
- #query_revenue
- #query_sickleave
- #query_specialleave
- #query_timeoffdays
- #query_unpaidleave
- #setDirectReports
- #setReports
- #treeSum
- #treeSumR
- #turnover

### Files

- CHANGELOG
- COPYING
- README.rdoc

### Class/Module Index

Quicksearch

- TaskJuggler
- TaskJuggler::Account
- TaskJuggler::AccountAttribute
- TaskJuggler::AccountCredit
- TaskJuggler::AccountCreditListAttribute
- TaskJuggler::AccountListRE
- TaskJuggler::AccountScenario
- TaskJuggler::AlertLevelDefinition
- TaskJuggler::AlertLevelDefinitions
- TaskJuggler::Allocation
- TaskJuggler::AllocationAttribute
- TaskJuggler::AttributeBase
- TaskJuggler::AttributeDefinition
- TaskJuggler::AttributeOverwrite
- TaskJuggler::BatchProcessor
- TaskJuggler::Booking
- TaskJuggler::BookingListAttribute
- TaskJuggler::BooleanAttribute
- TaskJuggler::CSVFile
- TaskJuggler::CellSettingPattern
- TaskJuggler::CellSettingPatternList
- TaskJuggler::Charge
- TaskJuggler::ChargeListAttribute
- TaskJuggler::ChargeSet
- TaskJuggler::ChargeSetListAttribute
- TaskJuggler::ChartPlotter
- TaskJuggler::ChartPlotterError
- TaskJuggler::CollisionDetector
- TaskJuggler::ColumnListAttribute
- TaskJuggler::ColumnTable
- TaskJuggler::Daemon
- TaskJuggler::DaemonConnector
- TaskJuggler::DaemonConnectorMixin
- TaskJuggler::DataCache
- TaskJuggler::DataCacheEntry
- TaskJuggler::DateAttribute
- TaskJuggler::DefinitionListAttribute
- TaskJuggler::DependencyListAttribute
- TaskJuggler::DurationAttribute
- TaskJuggler::ExportRE
- TaskJuggler::FileList
- TaskJuggler::FileRecord
- TaskJuggler::FixnumAttribute
- TaskJuggler::FlagListAttribute
- TaskJuggler::FloatAttribute
- TaskJuggler::FormatListAttribute
- TaskJuggler::GanttChart
- TaskJuggler::GanttContainer
- TaskJuggler::GanttHeader
- TaskJuggler::GanttHeaderScaleItem
- TaskJuggler::GanttLine
- TaskJuggler::GanttLoadStack
- TaskJuggler::GanttMilestone
- TaskJuggler::GanttRouter
- TaskJuggler::GanttTaskBar
- TaskJuggler::HTMLDocument
- TaskJuggler::HTMLElements
- TaskJuggler::HTMLGraphics
- TaskJuggler::ICalReport
- TaskJuggler::ICalendar
- TaskJuggler::ICalendar::Component
- TaskJuggler::ICalendar::Event
- TaskJuggler::ICalendar::Journal
- TaskJuggler::ICalendar::Person
- TaskJuggler::ICalendar::Todo
- TaskJuggler::Interval
- TaskJuggler::IntervalList
- TaskJuggler::JobInfo
- TaskJuggler::Journal
- TaskJuggler::JournalEntry
- TaskJuggler::JournalEntryList
- TaskJuggler::JournalSortListAttribute
- TaskJuggler::KateSyntax
- TaskJuggler::KeywordArray
- TaskJuggler::KeywordDocumentation
- TaskJuggler::Leave
- TaskJuggler::LeaveAllowance
- TaskJuggler::LeaveAllowanceList
- TaskJuggler::LeaveAllowanceListAttribute
- TaskJuggler::LeaveList
- TaskJuggler::LeaveListAttribute
- TaskJuggler::Limits
- TaskJuggler::Limits::Limit
- TaskJuggler::LimitsAttribute
- TaskJuggler::ListAttributeBase
- TaskJuggler::Log
- TaskJuggler::LogicalAttribute
- TaskJuggler::LogicalExpression
- TaskJuggler::LogicalExpressionAttribute
- TaskJuggler::LogicalExpressionListAttribute
- TaskJuggler::LogicalFlag
- TaskJuggler::LogicalFunction
- TaskJuggler::LogicalOperation
- TaskJuggler::ManagerResponsibilities
- TaskJuggler::ManagerStatusRecord
- TaskJuggler::Message
- TaskJuggler::MessageHandler
- TaskJuggler::MessageHandlerInstance
- TaskJuggler::MspXmlRE
- TaskJuggler::Navigator
- TaskJuggler::NavigatorElement
- TaskJuggler::NikuProject
- TaskJuggler::NikuReport
- TaskJuggler::NikuResource
- TaskJuggler::NodeListAttribute
- TaskJuggler::PTNProxy
- TaskJuggler::Painter
- TaskJuggler::Painter::Circle
- TaskJuggler::Painter::Color
- TaskJuggler::Painter::Element
- TaskJuggler::Painter::Ellipse
- TaskJuggler::Painter::FontMetrics
- TaskJuggler::Painter::FontMetricsData
- TaskJuggler::Painter::Group
- TaskJuggler::Painter::Line
- TaskJuggler::Painter::Points
- TaskJuggler::Painter::PolyLine
- TaskJuggler::Painter::Primitives
- TaskJuggler::Painter::Rect
- TaskJuggler::Painter::SVGSupport
- TaskJuggler::Painter::Text
- TaskJuggler::PlaceHolderCell
- TaskJuggler::ProcessIntercom
- TaskJuggler::ProcessIntercomIface
- TaskJuggler::Project
- TaskJuggler::ProjectBroker
- TaskJuggler::ProjectBrokerIface
- TaskJuggler::ProjectFileParser
- TaskJuggler::ProjectFileScanner
- TaskJuggler::ProjectRecord
- TaskJuggler::ProjectServer
- TaskJuggler::ProjectServerIface
- TaskJuggler::PropertyAttribute
- TaskJuggler::PropertyList
- TaskJuggler::PropertySet
- TaskJuggler::PropertyTreeNode
- TaskJuggler::Query
- TaskJuggler::RTFHandlers
- TaskJuggler::RTFNavigator
- TaskJuggler::RTFQuery
- TaskJuggler::RTFReport
- TaskJuggler::RTFReportLink
- TaskJuggler::RTFWithQuerySupport
- TaskJuggler::RealFormat
- TaskJuggler::RealFormatAttribute
- TaskJuggler::ReferenceAttribute
- TaskJuggler::Report
- TaskJuggler::ReportBase
- TaskJuggler::ReportContext
- TaskJuggler::ReportScenario
- TaskJuggler::ReportServer
- TaskJuggler::ReportServerIface
- TaskJuggler::ReportServerRecord
- TaskJuggler::ReportServlet
- TaskJuggler::ReportTable
- TaskJuggler::ReportTableCell
- TaskJuggler::ReportTableColumn
- TaskJuggler::ReportTableLegend
- TaskJuggler::ReportTableLine
- TaskJuggler::Resource
- TaskJuggler::ResourceListAttribute
- TaskJuggler::ResourceListRE
- TaskJuggler::ResourceScenario
- TaskJuggler::RichText
- TaskJuggler::RichTextAttribute
- TaskJuggler::RichTextDocument
- TaskJuggler::RichTextElement
- TaskJuggler::RichTextFunctionExample
- TaskJuggler::RichTextFunctionHandler
- TaskJuggler::RichTextImage
- TaskJuggler::RichTextIntermediate
- TaskJuggler::RichTextParser
- TaskJuggler::RichTextScanner
- TaskJuggler::RichTextSnip
- TaskJuggler::RichTextSyntaxRules
- TaskJuggler::Scenario
- TaskJuggler::ScenarioData
- TaskJuggler::ScenarioListAttribute
- TaskJuggler::Scoreboard
- TaskJuggler::ScoreboardInterval
- TaskJuggler::SheetHandlerBase
- TaskJuggler::SheetReceiver
- TaskJuggler::SheetSender
- TaskJuggler::Shift
- TaskJuggler::ShiftAssignment
- TaskJuggler::ShiftAssignments
- TaskJuggler::ShiftAssignmentsAttribute
- TaskJuggler::ShiftScenario
- TaskJuggler::SimpleQueryExpander
- TaskJuggler::SortListAttribute
- TaskJuggler::StatusSheetReceiver
- TaskJuggler::StatusSheetReport
- TaskJuggler::StatusSheetSender
- TaskJuggler::StdIoWrapper
- TaskJuggler::StringAttribute
- TaskJuggler::SymbolAttribute
- TaskJuggler::SymbolListAttribute
- TaskJuggler::SyntaxReference
- TaskJuggler::TOCEntry
- TaskJuggler::TSResourceRecord
- TaskJuggler::TSTaskRecord
- TaskJuggler::TableColumnDefinition
- TaskJuggler::TableColumnSorter
- TaskJuggler::TableOfContents
- TaskJuggler::TableReport
- TaskJuggler::TableReportColumn
- TaskJuggler::TagFile
- TaskJuggler::TagFile::TagFileEntry
- TaskJuggler::Task
- TaskJuggler::TaskDepListAttribute
- TaskJuggler::TaskDependency
- TaskJuggler::TaskListAttribute
- TaskJuggler::TaskListRE
- TaskJuggler::TaskScenario
- TaskJuggler::TernarySearchTree
- TaskJuggler::TextFormatter
- TaskJuggler::TextParser
- TaskJuggler::TextParser::Macro
- TaskJuggler::TextParser::MacroTable
- TaskJuggler::TextParser::Pattern
- TaskJuggler::TextParser::Rule
- TaskJuggler::TextParser::Scanner
- TaskJuggler::TextParser::Scanner::BufferStreamHandle
- TaskJuggler::TextParser::Scanner::FileStreamHandle
- TaskJuggler::TextParser::Scanner::MacroStackEntry
- TaskJuggler::TextParser::Scanner::StreamHandle
- TaskJuggler::TextParser::SourceFileInfo
- TaskJuggler::TextParser::StackElement
- TaskJuggler::TextParser::State
- TaskJuggler::TextParser::StateTransition
- TaskJuggler::TextParser::TextParserResultArray
- TaskJuggler::TextParser::TokenDoc
- TaskJuggler::TextReport
- TaskJuggler::TimeInterval
- TaskJuggler::TimeIntervalListAttribute
- TaskJuggler::TimeSheet
- TaskJuggler::TimeSheetReceiver
- TaskJuggler::TimeSheetRecord
- TaskJuggler::TimeSheetReport
- TaskJuggler::TimeSheetSender
- TaskJuggler::TimeSheetSummary
- TaskJuggler::TimeSheets
- TaskJuggler::Tj3
- TaskJuggler::Tj3AppBase
- TaskJuggler::Tj3Client
- TaskJuggler::Tj3Daemon
- TaskJuggler::Tj3Man
- TaskJuggler::Tj3SheetAppBase
- TaskJuggler::Tj3SsReceiver
- TaskJuggler::Tj3SsSender
- TaskJuggler::Tj3TsReceiver
- TaskJuggler::Tj3TsSender
- TaskJuggler::Tj3TsSummary
- TaskJuggler::Tj3WebD
- TaskJuggler::TjException
- TaskJuggler::TjRuntimeError
- TaskJuggler::TjTime
- TaskJuggler::TjpExample
- TaskJuggler::TjpExportRE
- TaskJuggler::TjpSyntaxRules
- TaskJuggler::TraceReport
- TaskJuggler::URLParameter
- TaskJuggler::UserManual
- TaskJuggler::VimSyntax
- TaskJuggler::WebServer
- TaskJuggler::WelcomePage
- TaskJuggler::WorkingHours
- TaskJuggler::WorkingHoursAttribute
- TaskJuggler::XMLBlob
- TaskJuggler::XMLComment
- TaskJuggler::XMLDocument
- TaskJuggler::XMLElement
- TaskJuggler::XMLNamedText
- TaskJuggler::XMLText
- Diff
- Diff::Hunk
- AppConfig
- Diffable
- DiffableString
- Object
- RuntimeConfig
- String

No matching classes.

# TaskJuggler::ResourceScenario

### Public Class Methods

new(resource, scenarioIdx, attributes) click to toggle source

    # File lib/taskjuggler/ResourceScenario.rb, line 18
    def initialize(resource, scenarioIdx, attributes)
      super

      # Scoreboard may be nil, a Task, or a bit vector encoded as a Fixnum
      # nil:        Value has not been determined yet.
      # Task:       A reference to a Task object
      # Bit 0:      Reserved
      # Bit 1:      0: Work time (as defined by working hours)
      #             1: No work time (as defined by working hours)
      # Bit 2 - 5:  0: No holiday or leave time
      #             1: Public holiday (holiday)
      #             2: Annual leave
      #             3: Special leave
      #             4: Sick leave
      #             5: unpaid leave
      #             6: blocked for other projects
      #             7 - 15: Reserved
      # Bit 6 - 7:  Reserved
      # Bit 8:      0: No global override
      #             1: Override global setting
      # The scoreboard is only created when needed to save memory for projects
      # which read-in the coporate employee database but only need a small
      # subset.
      @scoreboard = nil

      # The index of the earliest booked time slot.
      @firstBookedSlot = nil
      # Same but for each assigned resource.
      @firstBookedSlots = {}
      # The index of the last booked time Slot.
      @lastBookedSlot = nil
      # Same but for each assigned resource.
      @lastBookedSlots = {}

      # First available slot of the resource.
      @minslot = nil
      # Last available slot of the resource.
      @maxslot = nil

      # Attributed are only really created when they are accessed the first
      # time. So make sure some needed attributes really exist so we don't
      # have to check for existance each time we access them.
      %( alloctdeffort chargeset criticalness directreports duties efficiency
          effort limits managers rate reports shifts
          leaves leaveallowances workinghours ).each do |attr|
        @property[attr, @scenarioIdx]
      end

      @dCache = DataCache.instance
    end

### Public Instance Methods

allocated?(iv, task = nil) click to toggle source

Returns true if the resource or any of its children is allocated during the period specified with the TimeInterval iv. If task is not nil only allocations to this tasks are respected.

    # File lib/taskjuggler/ResourceScenario.rb, line 594
    def allocated?(iv, task = nil)
      return false if task && !@duties.include?(task)

      startIdx = @project.dateToIdx(iv.start)
      endIdx = @project.dateToIdx(iv.end)

      startIdx, endIdx = fitIndicies(startIdx, endIdx, task)
      return false if startIdx >= endIdx

      return allocatedSub(startIdx, endIdx, task)
    end

available?(sbIdx) click to toggle source

Returns true if the resource is available at the time specified by sbIdx.

    # File lib/taskjuggler/ResourceScenario.rb, line 161
    def available?(sbIdx)
      return false unless @scoreboard[sbIdx].nil?

      limits = @limits
      return false if limits && !limits.ok?(sbIdx)

      true
    end

book(sbIdx, task, force = false) click to toggle source

Book the slot indicated by the scoreboard index `sbIdx` for Task `task`. If `force` is true, overwrite the existing booking for this slot. The method returns true if the slot was available.

    # File lib/taskjuggler/ResourceScenario.rb, line 186
    def book(sbIdx, task, force = false)
      return false if !force && !available?(sbIdx)

      # Make sure the task is in the list of duties.
      unless @duties.include?(task)
        @duties << task
      end

      #puts "Booking resource #{@property.fullId} at " +
      #     "#{@scoreboard.idxToDate(sbIdx)}/#{sbIdx} for task #{task.fullId}\n"
      @scoreboard[sbIdx] = task
      # Track the total allocated slots for this resource.
      @effort += @efficiency
      @limits.inc(sbIdx) if @limits

      # Scoreboard iterations are fairly expensive but they are very frequent
      # operations in later processing. To limit the interations to the
      # relevant intervals, we store the interval for all bookings and for
      # each individual task.
      if @firstBookedSlot.nil? || @firstBookedSlot > sbIdx
        @firstBookedSlot = @firstBookedSlots[task] = sbIdx
      elsif @firstBookedSlots[task].nil? || @firstBookedSlots[task] > sbIdx
        @firstBookedSlots[task] = sbIdx
      end
      if @lastBookedSlot.nil? || @lastBookedSlot < sbIdx
        @lastBookedSlot = @lastBookedSlots[task] = sbIdx
      elsif @lastBookedSlots[task].nil? || @lastBookedSlots[task] < sbIdx
        @lastBookedSlots[task] = sbIdx
      end

      true
    end

bookBooking(sbIdx, booking) click to toggle source

    # File lib/taskjuggler/ResourceScenario.rb, line 219
    def bookBooking(sbIdx, booking)
      initScoreboard if @scoreboard.nil?

      unless @scoreboard[sbIdx].nil?
        if booked?(sbIdx)
          error('booking_conflict',
                "Resource #{@property.fullId} has multiple conflicting " +
                "bookings for #{@scoreboard.idxToDate(sbIdx)}. The " +
                "conflicting tasks are #{@scoreboard[sbIdx].fullId} and " +
                "#{booking.task.fullId}.", booking.sourceFileInfo)
        end
        val = @scoreboard[sbIdx]
        if ((val & 2) != 0 && booking.overtime < 1)
          # The booking is blocked due to the overtime attribute. Now let's
          # see if the user wants to be warned about it.
          if booking.sloppy < 1
            error('booking_no_duty',
                  "Resource #{@property.fullId} has no duty at " +
                  "#{@scoreboard.idxToDate(sbIdx)}.",
                  booking.sourceFileInfo)
          end
          return false
        end
        if ((val & 0x3C) != 0 && booking.overtime < 2)
          # The booking is blocked due to the overtime attribute. Now let's
          # see if the user wants to be warned about it.
          if booking.sloppy < 2
            error('booking_on_vacation',
                  "Resource #{@property.fullId} is on vacation at " +
                  "#{@scoreboard.idxToDate(sbIdx)}.",
                  booking.sourceFileInfo)
          end
          return false
        end
      end

      book(sbIdx, booking.task, true)
    end

booked?(sbIdx) click to toggle source

Return true if the resource is booked for a tasks at the time specified by sbIdx.

    # File lib/taskjuggler/ResourceScenario.rb, line 172
    def booked?(sbIdx)
      @scoreboard[sbIdx].is_a?(Task)
    end

bookedEffort() click to toggle source

@effort only trackes the already allocated effort for leaf resources. It's too expensive to propagate this to the group resources on every booking. If a value for a group effort is needed, it's computed here.

    # File lib/taskjuggler/ResourceScenario.rb, line 261
    def bookedEffort
      if @property.leaf?
        @effort
      else
        effort = 0
        @property.kids.each do |r|
          effort += r.bookedEffort(@scenarioIdx)
        end
        effort
      end
    end

bookedTask(sbIdx) click to toggle source

Return the Task that this resource is booked for at the time specified by sbIdx. If not booked to a task, nil is returned.

    # File lib/taskjuggler/ResourceScenario.rb, line 178
    def bookedTask(sbIdx)
      return nil unless (sb = @scoreboard[sbIdx]).is_a?(Task)
      sb
    end

calcCriticalness() click to toggle source

The criticalness of a resource is a measure for the probabilty that all allocations can be fullfilled. The smaller the value, the more likely will the tasks get the resource. A value above 1.0 means that statistically some tasks will not get their resources. A value between 0 and 1 implies no guarantee, though.

    # File lib/taskjuggler/ResourceScenario.rb, line 83
    def calcCriticalness
      if @scoreboard.nil?
        # Resources that are not allocated are not critical at all.
        @criticalness = 0.0
      else
        freeSlots = 0
        @scoreboard.each do |slot|
          freeSlots += 1 if slot.nil?
        end
        @criticalness = freeSlots == 0 ? 1.0 :
          @alloctdeffort / freeSlots
      end
    end

collectTimeOffIntervals(iv, minDuration) click to toggle source

Return a list of scoreboard intervals that are at least minDuration long and contain only off-duty and leave slots. The result is an Array of

start, end

  TjTime values.

    # File lib/taskjuggler/ResourceScenario.rb, line 675
    def collectTimeOffIntervals(iv, minDuration)
      # Time-off intervals are only useful for leaf resources. Group resources
      # would just default to the global working hours.
      return [] unless @property.leaf?

      initScoreboard if @scoreboard.nil?

      @scoreboard.collectIntervals(iv, minDuration) do |val|
        val.is_a?(Fixnum) && (val & 0x3E) != 0
      end
    end

cost(startIdx, endIdx, task = nil) click to toggle source

Returns the cost for using this resource during the specified TimeInterval period. If a Task task is provided, only the work on this particular task is considered.

    # File lib/taskjuggler/ResourceScenario.rb, line 587
    def cost(startIdx, endIdx, task = nil)
      getAllocatedTime(startIdx, endIdx, task) * @rate
    end

finishScheduling() click to toggle source

This method does some housekeeping work after the scheduling is completed. It's meant to be called for top-level resources and then recursively descends into all child resources.

    # File lib/taskjuggler/ResourceScenario.rb, line 136
    def finishScheduling
      # Recursively descend into all child resources.
      @property.children.each do |resource|
        resource.finishScheduling(@scenarioIdx)
      end

      # Add the parent tasks of each task to the duties list.
      @duties.each do |task|
        task.ancestors(true).each do |pTask|
          @duties << pTask unless @duties.include?(pTask)
        end
      end

      # Add the assigned task to the parent(s) resource duties list.
      @property.parents.each do |pResource|
        @duties.each do |task|
          unless pResource['duties', @scenarioIdx].include?(task)
            pResource['duties', @scenarioIdx] << task
          end
        end
      end
    end

getAllocatedSlots(startIdx, endIdx, task = nil) click to toggle source

Count the booked slots between the start and end index. If task is not nil count only those slots that are assigned to this particular task or any of its sub tasks.

    # File lib/taskjuggler/ResourceScenario.rb, line 690
    def getAllocatedSlots(startIdx, endIdx, task = nil)
      # If there is no scoreboard, we don't have any allocations.
      return 0 unless @scoreboard

      startIdx, endIdx = fitIndicies(startIdx, endIdx, task)
      return 0 if startIdx >= endIdx

      bookedSlots = 0
      taskList = task ? task.all : []
      @scoreboard.each(startIdx, endIdx) do |slot|
        if slot.is_a?(Task) && (task.nil? || taskList.include?(slot))
          bookedSlots += 1
        end
      end

      bookedSlots
    end

getAllocatedTime(startIdx, endIdx, task = nil) click to toggle source

Returns the allocated accumulated time of this resource and its children.

    # File lib/taskjuggler/ResourceScenario.rb, line 517
    def getAllocatedTime(startIdx, endIdx, task = nil)
      treeSum(startIdx, endIdx, task) do
        return 0 if @scoreboard.nil?

        @project.convertToDailyLoad(@project['scheduleGranularity'] *
            getAllocatedSlots(startIdx, endIdx, task))
      end
    end

getBookings(iv = nil, hashByTask = true) click to toggle source

Iterate over the scoreboard and turn its content into a set of Bookings.

    _iv_ can be a TimeInterval to limit the bookings within the provided
    period. if _hashByTask_ is true, the result is a Hash of Arrays with
    bookings hashed by Task. Otherwise it's just a plain Array with
    Bookings.

    # File lib/taskjuggler/ResourceScenario.rb, line 611
    def getBookings(iv = nil, hashByTask = true)
      bookings = hashByTask ? {} : []
      return bookings if @property.container? || @scoreboard.nil? ||
                         @firstBookedSlot.nil? || @lastBookedSlot.nil?

      # To speedup the collection we start with the first booked slot and end
      # with the last booked slot.
      startIdx = @firstBookedSlot
      endIdx = @lastBookedSlot + 1

      # If the user provided a TimeInterval, we only return bookings within
      # this TimeInterval.
      if iv
        ivStartIdx = @project.dateToIdx(iv.start)
        ivEndIdx = @project.dateToIdx(iv.end)
        startIdx = ivStartIdx if ivStartIdx > startIdx
        endIdx = ivEndIdx if ivEndIdx < endIdx
      end

      lastTask = nil
      bookingStart = nil

      startIdx.upto(endIdx) do |idx|
        task = @scoreboard[idx]
        # Now we watch for task changes.
        if task != lastTask ||
           (task.is_a?(Task) && (lastTask.nil? || idx == endIdx))
          if lastTask
            # We've found the end of a task booking series.
            # If we don't have a Booking for the task yet, we create one.
            if hashByTask
              if bookings[lastTask].nil?
                bookings[lastTask] = Booking.new(@property, lastTask, [])
              end
              # Append the new interval to the Booking.
              bookings[lastTask].intervals <<
              TimeInterval.new(@scoreboard.idxToDate(bookingStart),
                               @scoreboard.idxToDate(idx))
            else
              if bookings.empty? || bookings.last.task != lastTask
                bookings << Booking.new(@property, lastTask, [])
              end
              # Append the new interval to the Booking.
              bookings.last.intervals <<
              TimeInterval.new(@scoreboard.idxToDate(bookingStart),
                               @scoreboard.idxToDate(idx))
            end

          end
          # Get ready for the next task booking interval
          if task.is_a?(Task)
            lastTask = task
            bookingStart = idx
          else
            lastTask = bookingStart = nil
          end
        end
      end
      bookings
    end

getEffectiveFreeTime(startIdx, endIdx) click to toggle source

Return the unallocated work time (in seconds) of the resource and its children.

    # File lib/taskjuggler/ResourceScenario.rb, line 528
    def getEffectiveFreeTime(startIdx, endIdx)
      treeSum(startIdx, endIdx) do
        getFreeSlots(startIdx, endIdx) * @project['scheduleGranularity']
      end
    end

getEffectiveFreeWork(startIdx, endIdx) click to toggle source

Return the unallocated work of the resource and its children weighted by their efficiency.

    # File lib/taskjuggler/ResourceScenario.rb, line 536
    def getEffectiveFreeWork(startIdx, endIdx)
      treeSum(startIdx, endIdx) do
        @project.convertToDailyLoad(getFreeSlots(startIdx, endIdx) *
                                    @project['scheduleGranularity']) *
                                    @efficiency
      end
    end

getEffectiveWork(startIdx, endIdx, task = nil) click to toggle source

Returns the work of the resource (and its children) weighted by their efficiency. If task is provided, only the work for this task and all its sub tasks are being counted.

    # File lib/taskjuggler/ResourceScenario.rb, line 488
    def getEffectiveWork(startIdx, endIdx, task = nil)
      # Make sure we have the real Task and not a proxy.
      task = task.ptn if task
      # There can't be any effective work if the start is after the end or the
      # todo list doesn't contain the specified task.
      return 0.0 if startIdx >= endIdx || (task && !@duties.include?(task))
      # Temporary workaround until @duties is fixed again.

      # The unique key we use to address the result in the cache.
      @dCache.cached(self, :ResourceScenarioGetEffectiveWork, startIdx, endIdx,
                     task) do
        work = 0.0
        if @property.container?
          @property.kids.each do |resource|
            work += resource.getEffectiveWork(@scenarioIdx, startIdx, endIdx,
                                              task)
          end
        else
          unless @scoreboard.nil?
            work = @project.convertToDailyLoad(
                     getAllocatedSlots(startIdx, endIdx, task) *
                     @project['scheduleGranularity']) * @efficiency
          end
        end
        work
      end
    end

getFreeSlots(startIdx, endIdx) click to toggle source

Count the free slots between the start and end index.

    # File lib/taskjuggler/ResourceScenario.rb, line 726
    def getFreeSlots(startIdx, endIdx)
      countSlots(startIdx, endIdx) do |val|
        val.nil?
      end
    end

getLeave(startIdx, endIdx, type) click to toggle source

Returns the number of leave days for the period described by startIdx and endIdx for the given type of leave.

    # File lib/taskjuggler/ResourceScenario.rb, line 477
    def getLeave(startIdx, endIdx, type)
      treeSum(startIdx, endIdx, type) do
        @project.convertToDailyLoad(@project['scheduleGranularity'] *
            getLeaveSlots(startIdx, endIdx, type))
      end
    end

getLeaveSlots(startIdx, endIdx, type) click to toggle source

Count the number of slots that are work time slots but marked as annual leave.

    # File lib/taskjuggler/ResourceScenario.rb, line 719
    def getLeaveSlots(startIdx, endIdx, type)
      countSlots(startIdx, endIdx) do |val|
        val.is_a?(Fixnum) && (val & 0x3E) == (Leave::Types[type] << 2)
      end
    end

getMaxSlot() click to toggle source

Get the last available slot of the resource.

    # File lib/taskjuggler/ResourceScenario.rb, line 747
    def getMaxSlot
      @maxslot
    end

getMinSlot() click to toggle source

Get the first available slot of the resource.

    # File lib/taskjuggler/ResourceScenario.rb, line 742
    def getMinSlot
      @minslot
    end

getTimeOffDays(startIdx, endIdx) click to toggle source

Return the number of working days that are blocked by leaves.

    # File lib/taskjuggler/ResourceScenario.rb, line 545
    def getTimeOffDays(startIdx, endIdx)
      treeSum(startIdx, endIdx) do
        @project.convertToDailyLoad(getTimeOffSlots(startIdx, endIdx) *
                                    @project['scheduleGranularity']) *
                                    @efficiency
      end
    end

getTimeOffSlots(startIdx, endIdx) click to toggle source

Count the regular work time slots between the start and end index that have been blocked by leaves.

    # File lib/taskjuggler/ResourceScenario.rb, line 734
    def getTimeOffSlots(startIdx, endIdx)
      countSlots(startIdx, endIdx) do |val|
        # Bit 1 needs to be unset and the leave bits must not be 0.
        val.is_a?(Fixnum) && (val & 0x2) == 0 && (val & 0x3C) != 0
      end
    end

getWorkSlots(startIdx, endIdx) click to toggle source

Count the number of slots betweend the startIdx and endIdx that can be used for work

    # File lib/taskjuggler/ResourceScenario.rb, line 710
    def getWorkSlots(startIdx, endIdx)
      countSlots(startIdx, endIdx) do |val|
        # We count free slots and assigned slots.
        val.nil? || val.is_a?(Task)
      end
    end

preScheduleCheck() click to toggle source

    # File lib/taskjuggler/ResourceScenario.rb, line 119
    def preScheduleCheck
      @managers.each do |manager|
        unless manager.leaf?
          error('manager_is_group',
                "Resource #{@property.fullId} has group #{manager.fullId} " +
                "assigned as manager. Managers must be leaf resources.")
        end
        if manager == @property
          error('manager_is_self',
                "Resource #{@property.fullId} cannot manage itself.")
        end
      end
    end

prepareScheduling() click to toggle source

This method must be called at the beginning of each scheduling run. It initializes variables used during the scheduling process.

    # File lib/taskjuggler/ResourceScenario.rb, line 71
    def prepareScheduling
      @effort = 0
      initScoreboard if @property.leaf?

      setDirectReports
    end

query_annualleave(query) click to toggle source

Compute the annual leave days within the period specified by the query. The result is in days.

    # File lib/taskjuggler/ResourceScenario.rb, line 275
    def query_annualleave(query)
      query.sortable = query.numerical = val =
        getLeave(query.startIdx, query.endIdx, :annual)
      query.string = query.scaleLoad(val)
    end

query_annualleavebalance(query) click to toggle source

    # File lib/taskjuggler/ResourceScenario.rb, line 281
    def query_annualleavebalance(query)
      if @property.leaf?
        leave = getLeave(query.startIdx, query.endIdx, :annual)
        allowanceSlots = @leaveallowances.balance(:annual, query.start,
                                                  query.end)
        allowance = @project.slotsToDays(allowanceSlots)
        query.sortable = query.numerical = val = allowance - leave
        query.string = query.scaleLoad(val)
      end
    end

query_cost(query) click to toggle source

Compute the cost generated by this Resource for a given Account during a given interval. If a Task is provided as scopeProperty only the turnover directly assiciated with the Task is taken into account.

    # File lib/taskjuggler/ResourceScenario.rb, line 296
    def query_cost(query)
      if query.costAccount
        query.sortable = query.numerical = cost =
          turnover(query.startIdx, query.endIdx, query.costAccount,
                   query.scopeProperty, true)
        query.string = query.currencyFormat.format(cost)
      else
        query.string = 'No \balance\ defined!'
      end
    end

query_effort(query) click to toggle source

The effort allocated to the Resource in the specified interval. In case a Task is given as scope property only the effort allocated to this Task is taken into account.

    # File lib/taskjuggler/ResourceScenario.rb, line 310
    def query_effort(query)
      query.sortable = query.numerical = effort =
        getEffectiveWork(query.startIdx, query.endIdx, query.scopeProperty)
      query.string = query.scaleLoad(effort)
    end

query_effortdone(query) click to toggle source

The completed (as of 'now') effort allocated for the resource in the specified interval. In case a Task is given as scope property only the effort allocated for this Task is taken into account.

    # File lib/taskjuggler/ResourceScenario.rb, line 319
    def query_effortdone(query)
      # For this query, we always override the query period.
      query.sortable = query.numerical = effort =
        getEffectiveWork(@project.dateToIdx(@project['start'], false),
                         @project.dateToIdx(@project['now']),
                         query.scopeProperty)
      query.string = query.scaleLoad(effort)
    end

query_effortleft(query) click to toggle source

The remaining (as of 'now') effort allocated for the resource in the specified interval. In case a Task is given as scope property only the effort allocated for this Task is taken into account.

    # File lib/taskjuggler/ResourceScenario.rb, line 332
    def query_effortleft(query)
      # For this query, we always override the query period.
      query.sortable = query.numerical = effort =
        getEffectiveWork(@project.dateToIdx(@project['now']),
                         @project.dateToIdx(@project['end'], false),
                         query.scopeProperty)
      query.string = query.scaleLoad(effort)
    end

query_freetime(query) click to toggle source

The unallocated work time of the Resource during the specified interval.

    # File lib/taskjuggler/ResourceScenario.rb, line 342
    def query_freetime(query)
      query.sortable = query.numerical = time =
        getEffectiveFreeTime(query.startIdx, query.endIdx) / (60 * 60 * 24)
      query.string = query.scaleDuration(time)
    end

query_freework(query) click to toggle source

The unallocated effort of the Resource during the specified interval.

    # File lib/taskjuggler/ResourceScenario.rb, line 349
    def query_freework(query)
      query.sortable = query.numerical = work =
        getEffectiveFreeWork(query.startIdx, query.endIdx)
      query.string = query.scaleLoad(work)
    end

query_fte(query) click to toggle source

The the Full-time equivalent for the resource or group.

    # File lib/taskjuggler/ResourceScenario.rb, line 356
    def query_fte(query)
      fte = 0.0
      if @property.container?
        # Accumulate the FTEs of all sub-resources.
        @property.kids.each do |resource|
          resource.query_fte(@scenarioIdx, query)
          fte += query.to_num
        end
      else
        # TODO: Getting the globalWorkSlots is relatively expensive. We
        # probably don't need to compute this for every resource.
        globalWorkSlots = @project.getWorkSlots(query.startIdx, query.endIdx)
        workSlots = getWorkSlots(query.startIdx, query.endIdx)
        if globalWorkSlots > 0
          fte = (workSlots.to_f / globalWorkSlots) * @efficiency
        end
      end

      query.sortable = query.numerical = fte
      query.string = query.numberFormat.format(fte)
    end

query_headcount(query) click to toggle source

The headcount of the resource or group.

    # File lib/taskjuggler/ResourceScenario.rb, line 379
    def query_headcount(query)
      headcount = 0
      if @property.container?
        @property.kids.each do |resource|
          resource.query_headcount(@scenarioIdx, query)
          headcount += query.to_num
        end
      else
        headcount += @efficiency.round
      end

      query.sortable = query.numerical = headcount
      query.string = query.numberFormat.format(headcount)
    end

query_rate(query) click to toggle source

Get the rate of the resource.

    # File lib/taskjuggler/ResourceScenario.rb, line 395
    def query_rate(query)
      query.sortable = query.numerical = r = rate
      query.string = query.currencyFormat.format(r)
    end

query_revenue(query) click to toggle source

Compute the revenue generated by this Resource for a given Account during a given interval. If a Task is provided as scopeProperty only the revenue directly associated to this Task is taken into account.

    # File lib/taskjuggler/ResourceScenario.rb, line 403
    def query_revenue(query)
      if query.revenueAccount
        query.sortable = query.numerical = revenue =
          turnover(query.startIdx, query.endIdx, query.revenueAccount,
                   query.scopeProperty)
        query.string = query.currencyFormat.format(revenue)
      else
        query.string = 'No \balance\ defined!'
      end
    end

query_sickleave(query) click to toggle source

Compute the sick leave days within the period specified by the query. The result is in days.

    # File lib/taskjuggler/ResourceScenario.rb, line 416
    def query_sickleave(query)
      query.sortable = query.numerical = val =
        getLeave(query.startIdx, query.endIdx, :sick)
      query.string = query.scaleLoad(val)
    end

query_specialleave(query) click to toggle source

Compute the special leave days within the period specified by the query. The result is in days.

    # File lib/taskjuggler/ResourceScenario.rb, line 424
    def query_specialleave(query)
      query.sortable = query.numerical = val =
        getLeave(query.startIdx, query.endIdx, :special)
      query.string = query.scaleLoad(val)
    end

query_timeoffdays(query) click to toggle source

The work time of the Resource that was blocked by leaves during the specified TimeInterval. The result is in working days (effort).

    # File lib/taskjuggler/ResourceScenario.rb, line 432
    def query_timeoffdays(query)
      query.sortable = query.numerical = time =
        getTimeOffDays(query.startIdx, query.endIdx)
      query.string = query.scaleLoad(time)
    end

query_unpaidleave(query) click to toggle source

Compute the unpaid leave days within the period specified by the query. The result is in days.

    # File lib/taskjuggler/ResourceScenario.rb, line 440
    def query_unpaidleave(query)
      query.sortable = query.numerical = val =
        getLeave(query.startIdx, query.endIdx, :unpaid)
      query.string = query.scaleLoad(val)
    end

setDirectReports() click to toggle source

    # File lib/taskjuggler/ResourceScenario.rb, line 97
    def setDirectReports
      # Only leaf resources have reporting lines.
      return unless @property.leaf?

      # The 'directreports' attribute is the reverse link for the 'managers'
      # attribute. In contrast to the 'managers' attribute, the
      # 'directreports' list has no duplicate entries.
      @managers.each do |manager|
        unless manager['directreports', @scenarioIdx].include?(@property)
          manager['directreports', @scenarioIdx] << @property
        end
      end
    end

setReports() click to toggle source

    # File lib/taskjuggler/ResourceScenario.rb, line 111
    def setReports
      return unless @directreports.empty?

      @managers.each do |r|
        r.setReports_i(@scenarioIdx, [ @property ])
      end
    end

treeSum(startIdx, endIdx, *args, &block) click to toggle source

A generic tree iterator that recursively accumulates the result of the block for each leaf object.

    # File lib/taskjuggler/ResourceScenario.rb, line 448
    def treeSum(startIdx, endIdx, *args, &block)
      cacheTag = "#{self.class}.#{caller[0][/`.*'/][1..-2]}"
      treeSumR(cacheTag, startIdx, endIdx, *args, &block)
    end

treeSumR(cacheTag, startIdx, endIdx, *args, &block) click to toggle source

Recursing method for treeSum.

    # File lib/taskjuggler/ResourceScenario.rb, line 454
    def treeSumR(cacheTag, startIdx, endIdx, *args, &block)
      # Check if the value to be computed is already in the data cache. If so,
      # return it. Otherwise we have to compute it first and then store it in
      # the cache. We use the signature of the method that called treeSum()
      # and its arguments together with 'self' as index to the cache.
      @dCache.cached(self, cacheTag, startIdx, endIdx, *args) do
        if @property.container?
          sum = 0.0
          # Iterate over all the kids and accumulate the result of the
          # recursively called method.
          @property.kids.each do |resource|
            sum += resource.treeSumR(@scenarioIdx, cacheTag, startIdx, endIdx,
                                     *args, &block)
          end
          sum
        else
          instance_eval(&block)
        end
      end
    end

turnover(startIdx, endIdx, account, task = nil, includeKids = false) click to toggle source

    # File lib/taskjuggler/ResourceScenario.rb, line 553
    def turnover(startIdx, endIdx, account, task = nil, includeKids = false)
      amount = 0.0
      if @property.container? && includeKids
        @property.kids.each do |child|
          amount += child.turnover(@scenarioIdx, startIdx, endIdx, account,
                                   task)
        end
      else
        if task
          # If we have a known task, we only include the amount that is
          # specific to this resource, this task and the chargeset of the
          # task.
          amount += task.turnover(@scenarioIdx, startIdx, endIdx, account,
                                  @property)
        elsif !@chargeset.empty?
          # If no tasks was provided, we include the amount of this resource,
          # weighted by the chargeset of this resource.
          totalResourceCost = cost(startIdx, endIdx)
          @chargeset.each do |set|
            set.each do |accnt, share|
              if share > 0.0 && (accnt == account || accnt.isChildOf?(account))
                amount += totalResourceCost * share
              end
            end
          end
        end
      end

      amount
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.