### Home Classes Methods

### In Files

- lib/taskjuggler/ShiftAssignments.rb

### Parent

Monitor

### Methods

- ::new
- ::sbClear
- ::scoreboards
- #addAssignment
- #assigned?
- #collectTimeOffIntervals
- #getSbSlot
- #hashKey
- #onLeave?
- #onShift?
- #timeOff?
- #to_s

### Included Modules

- ObjectSpace

### 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::ShiftAssignments

This class manages a list of ShiftAssignment elements. The intervals of the assignments must not overlap.

Since it is fairly costly to determine the onShift and onLeave values for a given date we use a scoreboard to cache all computed values. Changes to the assigment set invalidate the cache again.

To optimize memory usage and computation time the Scoreboard objects for similar ShiftAssignments are shared.

Scoreboard may be nil or a bit vector encoded as a Fixnum nil: Value has not been determined yet. Bit 0: 0: No assignment

    1: Has assignement

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

### Attributes

assignments[R]
project[RW]

### Public Class Methods

new(sa = nil) click to toggle source

    # File lib/taskjuggler/ShiftAssignments.rb, line 111
    def initialize(sa = nil)
      define_finalizer(self, self.class.method(:deleteScoreboard).to_proc)

      # An Array of ShiftAssignment objects.
      @assignments = []

      # A String that uniquely identifies the content of this ShiftAssignment
      # object.
      @hashKey = nil

      if sa
        # A ShiftAssignments object was passed to the contructor. We create a
        # deep copy of it.
        @project = sa.project
        sa.assignments.each do |assignment|
          @assignments << assignment.copy
        end
        # Create a new ScoreBoard or share one with a ShiftAssignments object
        # that has the same set of shift assignments.
        @scoreboard = newScoreboard
      else
        @project = nil
        @scoreboard = nil
      end
    end

sbClear() click to toggle source

    # File lib/taskjuggler/ShiftAssignments.rb, line 218
    def ShiftAssignments.sbClear
      @@scoreboards = {}
    end

scoreboards() click to toggle source

    # File lib/taskjuggler/ShiftAssignments.rb, line 214
    def ShiftAssignments.scoreboards
      @@scoreboards
    end

### Public Instance Methods

addAssignment(shiftAssignment) click to toggle source

Add a new assignment to the list. In case there was no overlap the function returns true. Otherwise false.

    # File lib/taskjuggler/ShiftAssignments.rb, line 139
    def addAssignment(shiftAssignment)
      # Make sure we don't insert overlapping assignments.
      return false if overlaps?(shiftAssignment.interval)

      @assignments << shiftAssignment
      @scoreboard = newScoreboard
      true
    end

assigned?(idx) click to toggle source

Returns true if any of the defined shift periods overlaps with the date or interval specified by idx.

    # File lib/taskjuggler/ShiftAssignments.rb, line 181
    def assigned?(idx)
      (getSbSlot(idx) & 1) == 1
    end

collectTimeOffIntervals(iv, minDuration) click to toggle source

Return a list of intervals that lay within iv and are at least minDuration long and contain no working time.

    # File lib/taskjuggler/ShiftAssignments.rb, line 208
    def collectTimeOffIntervals(iv, minDuration)
      @scoreboard.collectIntervals(iv, minDuration) do |val|
        (val & 0x3E) != 0
      end
    end

getSbSlot(idx) click to toggle source

This function returns the entry in the scoreboard that corresponds to idx. If the slot has not yet been determined, it's calculated first.

    # File lib/taskjuggler/ShiftAssignments.rb, line 150
    def getSbSlot(idx)
      # Check if we have a value already for this slot.
      return @scoreboard[idx] unless @scoreboard[idx].nil?

      date = @scoreboard.idxToDate(idx)
      # If not, compute it.
      @assignments.each do |sa|
        next unless sa.assigned?(date)

        # Mark the slot as 'assigned'. Meaning, the rest of the bits are valid
        # for this time slot.
        @scoreboard[idx] = 1

        # Set bit 1 if the shift is not active
        @scoreboard[idx] |= 1 << 1 unless sa.onShift?(date)

        # Set bits 2 - 5 to 1 if it's a leave slot.
        @scoreboard[idx] |= 1 << 3 if sa.onLeave?(date)

        # Set the 8th bit if the shift replaces global leaves.
        @scoreboard[idx] |= 1 << 8 if sa.replace?(date)

        return @scoreboard[idx]
      end

      # The slot is not covered by any assignment.
      @scoreboard[idx] = 0
    end

hashKey() click to toggle source

    # File lib/taskjuggler/ShiftAssignments.rb, line 239
    def hashKey
      @hashKey if @hashKey

      @hashKey = "#{@project.object_id}|"
      @assignments.sort! { |a, b| a.interval.start <=> b.interval.start }
      @assignments.each { |a| @hashKey += a.hashKey + '||' }
      @hashKey
    end

onLeave?(idx) click to toggle source

Returns true if any of the defined shift periods contains the date specified by the scoreboard index idx and if the shift has a leave defined for the date.

    # File lib/taskjuggler/ShiftAssignments.rb, line 202
    def onLeave?(idx)
      (getSbSlot(idx) & 0x3C) != 0
    end

onShift?(idx) click to toggle source

Returns true if any of the defined shift periods contains the date specified by the scoreboard index idx and the shift has working hours defined for that date.

    # File lib/taskjuggler/ShiftAssignments.rb, line 188
    def onShift?(idx)
      (getSbSlot(idx) & (1 << 1)) == 0
    end

timeOff?(idx) click to toggle source

Returns true if any of the defined shift periods contains the date specified by the scoreboard index idx and the shift has a leave defined or all off hours defined for that date.

    # File lib/taskjuggler/ShiftAssignments.rb, line 195
    def timeOff?(idx)
      (getSbSlot(idx) & 0x3E) != 0
    end

to_s() click to toggle source

This function is primarily used for debugging purposes.

    # File lib/taskjuggler/ShiftAssignments.rb, line 223
    def to_s
      return '' if @assignments.empty?

      out = "shifts "
      first = true
      @assignments.each do |sa|
        if first
          first = false
        else
          out += ', '
        end
        out += sa.to_s
      end
      out
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.