Task definition and customization.
Tasks are the things that need to be scheduled and can represent work items, reservations, meetings, events, etc. All tasks are simple JSON objects with a set of options which determines how the task is scheduled. The only required options are the id and duration of the task.
// a basic task called 'Task1' that is 60 minutes long var task = {id: 'Task1', duration: 60};
Important By default, tasks
will be broken into smaller chunks when needed in order to best fit the
schedule. If you want a task to be scheduled as one contiguous
block of time, set minLength
equal to the task
duration
.
Tasks are JSON objects that are customized using the following properties:
minLength
equal to duration
if you want to make sure the task is scheduled in one contiguous
chunk of time.Later
schedule. The task will never be scheduled for a
time when the available schedule is invalid.Example tasks:
// a task that is 60 minutes long var t1 = {id: 'Task1', duration: 60}; // a task that can only be broken up into pieces that are at least 30 min long var t2 = {id: 'Task2', duration: 60, minLength: 30}; // a task that depends on two other tasks var t3 = {id: 'Task3', duration: 60, dependsOn: ['Task1', 'Task2']}; // a task that requires resource A var t4 = {id: 'Task4', duration: 60, resources: ['A']}; // a task that requires resource A AND resource B var t5 = {id: 'Task5', duration: 60, resources: ['A', 'B']}; // a task that requires resource A OR resource B var t6 = {id: 'Task6', duration: 60, resources: [['A', 'B']]}; // a task that requires (resource A OR resource B) and resource C var t7 = {id: 'Task7', duration: 60, resources: [['A', 'B'], 'C']}; // a task that can only be scheduled on weekdays var t8 = { id: 'Task8', duration: 60, available: later.parse.text('every weekday') }; // a task with a priority set var t9 = {id: 'Task9', duration: 60, priority: 100}; // a fully customized task var t10 = { id: 'Task10', duration: 360, minLength: 60, dependsOn: ['Task1', 'Task5', 'Task9'], resources: [['A', 'B', 'C'], 'D', 'E'], available: later.parse.recur().on(2).dayOfWeek().after('9:00').time(), priority: 50 };
Often times the tasks that your application defines are not in the format that Schedule requires. To make the conversion process easier, Schedule includes a task generator that can be used on any array of objects to produce valid tasks.
// creating a default task generator var t = schedule.tasks();
Used to specify the value or function that should be called to
define the id
of the task. If a function is specified,
it will be passed in the object and index from the input data array.
Used to specify the value or function that should be called to
define the duration
of the task. If a function is specified,
it will be passed in the object and index from the input data array.
Used to specify the value or function that should be called to
define the minLength
of the task. If a function is specified,
it will be passed in the object and index from the input data array.
Used to specify the value or function that should be called to
define the dependsOn
array of the task. If a function is specified,
it will be passed in the object and index from the input data array.
Used to specify the value or function that should be called to
define the resources
array of the task. If a function is specified,
it will be passed in the object and index from the input data array.
Used to specify the value or function that should be called to
define the available
schedule of the task. If a function is specified,
it will be passed in the object and index from the input data array.
Used to specify the value or function that should be called to
define the priority
schedule of the task. If a function is specified,
it will be passed in the object and index from the input data array.
// the original reservations that we want to make into tasks var reservations = [ {name: 'Joe', length: 4, availability: 'after 12:00'}, {name: 'Mike', length: 2}, {name: 'Frank', length: 8}, {name: 'John', length: 3, availability: 'on Thurs and Fri'}, {name: 'Peter', length: 1, availability: 'before 10:00am'}, {name: 'Sam', length: 2}, {name: 'Alan', length: 2}, {name: 'James', length: 8}, {name: 'Steve', length: 1, availability: 'after 12:00 and before 1:00pm'}, {name: 'Mark', length: 2}, {name: 'Alex', length: 8} ]; // creating our task generator var t = schedule.tasks() // use the name as the id .id(function(d) { return d.name; }) // our length is in hours, convert to minutes .duration(function(d) { return d.length * 60; }) // use later.parse.text to parse text into a usable schedule .available(function(d) { return d.availability ? later.parse.text(d.availability) : undefined; }) // prioritize our reservations on first come first serve using index .priority(function(d, i) { return 100 - i; }) // reservations have to be contiguous .minSchedule(function(d) { return d.length * 60; }) // assume all reservations are using the same resource .resources(['E1']); // create Schedule tasks from our reservations var tasks = t(reservations);