Main > Reference Manual > Modeling > Calendar

A calendar represents a value that is varying over time.
Calendars can be linked to multiple entities: a maximum capacity limit of a resource, a minimum capacity usage of a resource, a minimum or maximum inventory limit of a buffer, etc...

Different types of calendar exist:

  • calendar_void:
    A calendar without any value in its buckets.
  • calendar_double:
    A calendar storing double numbers.
  • calendar_integer:
    A calendar storing integer numbers.
  • calendar_boolean:
    A calendar storing boolean values.
  • calendar_string:
    A calendar storing string values.
  • calendar_operation:
    A calendar storing operation values.

A calendar has multiple buckets to define the values over time. To determine the calendar value at a certain date the calendar will evaluate each of the buckets and combine the results in the following way:

  • A bucket is only valid from its "start" date (inclusive) till its "end" date (exclusive).
    Outside of this date range a bucket is never selected.
  • If multiple bucket are effective on a date, the one with the lowest "priority" value is taken.
    In case buckets have the same priority, the value of the bucket with the latest start date is selected.
  • In case no bucket is effective on a certain date, the calendar will return the "default" value.

Calendar Fields

Field Type Description
name non-empty string

Name of the calendar.
This is the key field and a required attribute.

default Varies with the calendar type

The default value of the calendar when no bucket is effective.

action

A
C
AC (default)
R

Type of action to be executed:

  • A: Add an new entity, and report an error if the entity already exists.
  • C: Change an existing entity, and report an error if the entity doesn't exist yet.
  • AC: Change an entity or create a new one if it doesn't exist yet.
  • R: Remove an entity, and report an error if the entity doesn't exist.
Method Description
setValue([start date],[end date],[value])

Creates or updates calendar buckets to reflect the specified value in the given date range.

buckets()

Returns an iterator over the calendar buckets.

events()

Returns an iterator over the calendar events. These are the dates at which the calendar value is changing.
Each event is a tuple with 2 fields:

  • date: date of the event.
  • value: value that becomes effective at the time of the event.

Bucket Fields

Field Type Description
start dateTime

Start date of the validity of this bucket.
When left unspecified, the entry is effective from the infinite past.

end dateTime

End date of the validity of this bucket.
When left unspecified, the entry is effective indefinitely in the future.

name normalizedString

Optional name of the bucket.
When left unspecified the default name is the start date of the bucket.

priority integer

Priority of this bucket when multiple buckets are effective for the same date.
Lower values indicate higher priority.

value Varies with the calendar type

The actual time-varying value.

action A
C
AC (default)
R

Type of action to be executed:

  • A: Add an new entity, and report an error if the entity already exists.
  • C: Change an existing entity, and report an error if the entity doesn't exist yet.
  • AC: Change an entity or create a new one if it doesn't exist yet.
  • R: Remove an entity, and report an error if the entity doesn't exist.

Example XML structures

  • Adding or changing a calendar and its buckets
 <plan>
   <calendars>
     <calendar name="cal" xsi:type="calendar_double">
       <default>5</default>
       <buckets>
         <bucket start="2007-01-01T00:00:00" value="10"
            priority="1"/>
         <!-- This entry overrides the first one during February. -->
         <bucket start="2007-02-01T00:00:00" end="2007-03-01T00:00:00
            value="20" priority="0"/>
       </buckets>
     </calendar >
   </calendars>
 </plan>
  • Removing a calendar
 <plan>
    <calendars>
       <calendar name="cal" action="R"/>
    </calendars>
 </plan>

Example Python code

  • Adding or changing a calendar and its buckets
   cal = frepple.calendar_double(name="cal", default=5)
  • Removing a calendar
   frepple.calendar(name="cal", action="R")
  • Iterating over all buckets of a calendar
   for b in frepple.calendar(name="cal").buckets():
     print b.name, b.value
  • Iterating over all events of a calendar, going forward in time from a certain date
   start = datetime.datetime(2009,1,1)
   for date, value in frepple.calendar(name="cal").events(start, True):
     print date, value