Class: Syctask::TaskScheduler
- Inherits:
-
Object
- Object
- Syctask::TaskScheduler
- Defined in:
- lib/syctask/task_scheduler.rb
Overview
The TaskScheduler creates a graphical representation of a working schedule with busy times visualized. A typical invokation would be
work_time = "8:00-18:00"
busy_time = "9:00-9:30,13:00-14:30"
scheduler = Syctask::TaskScheduler.new(work_time, busy_time)
scheduler.print_graph
The output would be
|---///-|---|---|---///////-|---|---|---|
8 9 10 11 12 13 14 15 16 17 18
To add tasks to the schedule tasks have to provided (see Task). A task has a duration which indicates the time it is planned to process a task. The duration is an Integer 1,2,.. where 1 is 15 minutes and 2 is 30 minutes and so on. Assuming we have 5 tasks with a duration of 2, 5, 3, 2 and 3 15 minute chunks. Then the invokation of
scheduler.schedule_tasks(tasks)
would output the schedule
|xx-///ooooo|xxx|oo-///////xxx--|---|---|
8 9 10 11 12 13 14 15 16 17 18
The tasks are added to the schedule dependent on the time chunks and the available free time gaps.
Constant Summary collapse
- TIME_PATTERN =
Time pattern that matches 24 hour times ‘12:30’
/(2[0-3]|[01]?[0-9]):([0-5]?[0-9])/
- WORK_TIME_PATTERN =
Work time pattern scans time like ‘8:00-18:00’
/#{TIME_PATTERN}-#{TIME_PATTERN}/
- BUSY_TIME_PATTERN =
Busy time pattern scans times like ‘9:00-9:30,11:00-11:45’
/#{TIME_PATTERN}-#{TIME_PATTERN}(?=,)|#{TIME_PATTERN}-#{TIME_PATTERN}$/
- ASSIGNMENT_PATTERN =
Scans assignments of tasks to meetings ‘A:0,2,4;B:3,4,5’
/([a-zA-Z]):(\d+(?:,\d+|\d+;)*)/
- WORK_DIR =
Working directory
Syctask::SYC_DIR
Instance Method Summary collapse
-
#initialize ⇒ TaskScheduler
constructor
Creates a new TaskScheduler.
-
#restore(value) ⇒ Object
Restores the value of a previous invokation.
-
#set_busy_times(busy_time) ⇒ Object
Set the busy times.
-
#set_meeting_titles(titles) ⇒ Object
Sets the titles of the meetings (busy times) Invokation: set_meeting_titles(“title1,title2,title3”).
-
#set_task_assignments(assignments) ⇒ Object
Add scheduled tasks to busy times Invokation: set_task_assignments([,[“B”,“2,5,6,7”]]).
-
#set_tasks(tasks) ⇒ Object
Sets the tasks for scheduling.
-
#set_work_time(work_time) ⇒ Object
Set the work time.
-
#show ⇒ Object
Prints the meeting list, timeline and task list.
Constructor Details
#initialize ⇒ TaskScheduler
Creates a new TaskScheduler.
44 45 46 47 48 49 |
# File 'lib/syctask/task_scheduler.rb', line 44 def initialize @work_time = [] @busy_time = [] @meetings = [] @tasks = [] end |
Instance Method Details
#restore(value) ⇒ Object
Restores the value of a previous invokation. Posible values are :work_time, :busy_time, :meetings and :assignments Returns true if a value from a previous call is available otherwise false
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/syctask/task_scheduler.rb', line 125 def restore(value) work_time, busy_time, meetings, assignments = restore_state @work_time = work_time if value == :work_time @busy_time = busy_time if value == :busy_time @meetings = meetings if value == :meetings @assignments = assignments if value == :assignments return false if value == :work_time and (@work_time.nil? or @work_time.empty?) return false if value == :busy_time and (@busy_time.nil? or @busy_time.empty?) return false if value == :meetings and (@busy_time.nil? or @meetings.empty?) return false if value == :assignments and (@assignments.nil? or @assignments.empty?) true end |
#set_busy_times(busy_time) ⇒ Object
Set the busy times. Raises an exception if one begin time is after start time Invokation: set_busy_times([,[“12”,“0”,“13”,“45”]])
64 65 66 67 68 69 70 71 72 |
# File 'lib/syctask/task_scheduler.rb', line 64 def set_busy_times(busy_time) @busy_time = process_busy_time(busy_time) @busy_time.each do |busy| unless sequential?(busy) raise Exception, "Begin time has to be before end time" end end Syctask::log_meetings("meeting", @busy_time, @meetings) end |
#set_meeting_titles(titles) ⇒ Object
Sets the titles of the meetings (busy times) Invokation: set_meeting_titles(“title1,title2,title3”)
76 77 78 79 |
# File 'lib/syctask/task_scheduler.rb', line 76 def set_meeting_titles(titles) @meetings = titles.split(",") if titles Syctask::log_meetings("meeting", @busy_time, @meetings) end |
#set_task_assignments(assignments) ⇒ Object
Add scheduled tasks to busy times Invokation: set_task_assignments([,[“B”,“2,5,6,7”]])
88 89 90 91 |
# File 'lib/syctask/task_scheduler.rb', line 88 def set_task_assignments(assignments) @assignments = assignments.scan(ASSIGNMENT_PATTERN) raise "No valid assignment" if @assignments.empty? end |
#set_tasks(tasks) ⇒ Object
Sets the tasks for scheduling
82 83 84 |
# File 'lib/syctask/task_scheduler.rb', line 82 def set_tasks(tasks) @tasks = tasks end |
#set_work_time(work_time) ⇒ Object
Set the work time. Raises an exception if begin time is after start time Invokation: set_work_time()
53 54 55 56 57 58 59 |
# File 'lib/syctask/task_scheduler.rb', line 53 def set_work_time(work_time) @work_time = process_work_time(work_time) unless sequential?(@work_time) raise Exception, "Begin time has to be before end time" end Syctask::log_work_time("work", @work_time) end |
#show ⇒ Object
Prints the meeting list, timeline and task list
139 140 141 142 143 144 145 |
# File 'lib/syctask/task_scheduler.rb', line 139 def show schedule = Syctask::Schedule.new(@work_time, @busy_time, @meetings, @tasks) schedule.assign(@assignments) if @assignments schedule.graph.each {|output| puts output} save_state @work_time, @busy_time, @meetings, @assignments true end |