1

I run discrete event simulations which cover more than a year. All events need to be tracked on a second time scale.
Now, I want to schedule the events according to a timetable, calculate overtime, ... and compare it to the real labor time in the end. I thought whether there is an elegant way to implement schedules in R such that the following tasks/questions can be answered within one line of code:

  • Schedule work according to a timetable.
  • Given a timetable, how many labor hours do we expect per day/week/month/... Calculate the overtime per day/week/month/...
  • Create simple plots to visualize working time, overtime, ... and compare it to the planned work load.

On an abstract level, assume all of the timetables are given more or less in the following way:

Name   Days_of_year     Available                             Time  
Name1  Jan-07 – Oct-18  Mon, Tues, Wed, Thurs, Fri, Sat, Sun  8:45 - 18:00  
Name2  Jan-01 – Dec-31  Mon, Tues, Wed, Thurs, Fri            20:00 - 7:00  

I am not looking for obvious answers like "create an arry and somehow you get everything out of that" but an implementation that:

  • Makes schedules independent of time resolution (days, hours, minutes, seconds).
  • Schedules/timetables are not stored with redundant information.
  • Any result (e.g. total year labor, ...) should be easily transferred to any given unit.
  • Easy filter possibilities by month, wday, ...
  • Ideally, calendar functionalities (holidays, ...) can be easily used.
  • Perhaps as part of lubridate?

Use case view ("schedule functions" indicated by s_):

  • Time: s_hm(„7:45“), s_md(„Jan-23“) or s_md(„01-23“). Please note that those "times" do not make sence as dates or date-times, but in the framework of schedules they perfectly make sence!
  • Interval: s_interval. See first thoughts below.
  • Duration: s_interval/dhours(1) => Duration in hours
  • Functions:
    • Max(), Min() on any s_interval
    • %s_in%
      • Given a date, when does somebody work: date(s) %s_in% s_interval
        => return TRUE/FALSE (array)
      • Given a schedule, when is somebody available in an interval: s_interval %s_in% interval
        => return class interval - a subset of interval!
      • Given an interval, was the labor according to schedule? Calculate the idle-, over- and working time: interval %s_in% s_interval
        => return class s_interval
    • Given two schedules, consider them as one unit. How is idle-, over- and working time distributed: (s_interval1 %+% s_interval2)
      => return class s_interval

Some thoughts:

schedule in case of planning labor time:

s_interval $tzone   UTC
    $daysofyear 286 days        (Better alternative: format month-day e.g. Jan-07 – Oct-18) 
    $wday           Mon, Tues, ... Sun  (According to the start time of a shift/lecture...)
    $time           12 h            (Better alternative: format time span* e.g. 8:00 – 18:00. NOT period which results in hours)
    $overtime       0 h         (A priori, a schedule does not plan overtime)
    $idle           0 h         (A priori, a schedule only plans labor time)

schedule when real time-data is available:

s_interval$tzone    UTC
    $daysofyear 286 days                (Better alternative: format month-day e.g. Jan-07 – Oct-18) 
    $wday           c(Mon, Tues, Wed, ...)      (According to the start time of a shift/lecture...)
    $time           c(12 h, 1 h, 0.5 h, ...)        (Better alternative: format time span* e.g. 8:00 – 18:00. NOT period which results in hours)
    $overtime       c(2 h, 0 h, -1 h, ...)      total time = time + overtime. Array of lubridate intervals*?
    $idle           c(4 h, 8 h, 0h, ...)        pure working_time = time – idle + overtime. Array of lubridate intervals*?

* Use intervals not periods such that interval/dhours(1) possible.

If the tzone is the same we could calculate e.g.

s_interval1 %+% s_interval2 =  
s_interval$tzone    UTC
    $daysofyear    286 days,            123 days        
    $wday           c(Mon, Tues, Wed, ...),     c(Sat, Sun)
    $time          c(12 h, 1 h, 0.5 h, ...),    c(-1 h, 2.5 h)
    $overtime      c(2 h, 0 h, -1 h, ...),      c(0 h, 5 h)
    $idle          c(4 h, 8 h, 0h, ...),        c(4 h, 8 h)

There are related posts about this topic visualization of schedules with some interesting answers concerning timeline and gantt packages and how to filter dates. However, they are not very conclusive.

As I am quite new to R, I don't know, how to start such a task the best way and understanding the structure of a package like lubridate is quite advanced...

Community
  • 1
  • 1
Christoph
  • 6,841
  • 4
  • 37
  • 89

1 Answers1

0

I developed a package which gives the desired functionality (even with plots). At the moment, the package is private, but let me know if you are interested.

Christoph
  • 6,841
  • 4
  • 37
  • 89