views:

116

answers:

2

I'm looking for ideas/information about managing temporal data with Active Record (Rails). One example would be the emplyoment history (working 100% in january, but only 80% from february up to now). This proably would be easy to tackle with a traditional 'has-many :eployment_parts'. But there's another case where the user can plan something like a todo list, which the user can change over time (this todo is valid from Jan-March, another one is valid from Jan-April, and then with changed details from May to August).

I know, there's no silver bullet solution for these kind of requirements, but I'd like to collect here some ideas/docmentations/plugins about this topic. It looks like there hasn't been done much in this area for rails, at least nothing which got public.

Please, if you have an idea, link or thought, drop a short answer!

Links so far:

+1  A: 

You need to detail what you want to do a bit more.

For example, what "resolution" do you need? Do you plan to record every worked hour of every day? Or just the average montly workload? Per week, maybe?

Also, what do you want to do with holidays, and sick days?

(EDIT - answering to the comment below)

In your case I'd go with a model similar to this one:

class WorkSlice < ActiveRecord::Base
  belongs_to :employee
  validates_presence_of employee_id, start_date, end_date, percentage

  def calculate_hours
    #employees might have different hours per day (i.e. UK has 7, Spain has 8)
    employee.hours_per_day * self.calculate_days
  end

  def calculate_days
    #days between start_day and end_day that are not sick days, holidays or weekends
    workdays = ... #this depends on how you model holidays, etc
    return workdays * self.percentage
  end
end

The only association you need is with "employee", as far as I know. A method on employee would allow you to see, for example, how "free" that eployee is on a given date.

egarcia
You can ignore such things as sick days, holidays etc. The emplyoment_history says: 'start: 2009.01.01 end: 2009.04.30, pensum 100%', 'start: 2009.05.01 end: infinity, pensum: 80%' The problem is that these kind of 'temporal' data has to managed somehow, when can what timerange start and end, which is the current entry, etc.It even gets worse when there are assocations.
reto
edited my answer, showing one possible implementation
egarcia
A: 

"I know, there's no silver bullet solution for these kind of requirements,"

That does depend a bit on how silver you need your bullet to be.

Anyhow. You might find the following stuff interesting too :

(a) "An Overview and Analysis of TSQL2" by Hugh Darwen and C.J. Date. A link is on www.thethirdmanifesto.com in the "Papers" section at the bottom. (b) "Temporal Data and the Relational Model", a complete book by the same authors plus Nikos Lorentzos. Contains a different, complete, proposal plus very sound justifications why they believe that proposal to be better. (c) You can find an implementation called SIRA_PRISE, written by me, based on the ideas from (b), on shark.armchair.mb.ca/~erwin

Erwin Smout