Temporary data with Rails / Active Record

I am looking for ideas / information about managing time data with Active Record (Rails). One example would be history (over 100% in January), but only from February to 80%. This could easily be solved with the traditional "has-many: eployment_parts". But there is another case where the user can schedule something like a todo list that the user can change over time (this todo is valid from January to March, the other is valid from January to April, and then with modified data from May to August).

I know there is no such solution, but I would like to collect some ideas / additions / plugins on this topic here. It looks like a lot of effort hasn't been made in this area for rails, at least nothing public.

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

Links so far:

+2


source to share


3 answers


we needed to keep historical data about all changes in the database records and be able to query data in time mode without affecting the performance of queries of the current data.

The solution we assume is a slowly changing size type 2 with history tables. The implementation is a Ruby gem that requires PostgreSQL 9.3 and fits nicely into Active Record by extending it with a temporary structure (for example Foo.as_of(1.year.ago).bars

).



The code can be found here: https://github.com/ifad/chronomodel : -)

+2


source


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

For example, what "permission" do you need? Do you plan to record every working hour every day? Or just an average workload? A week, maybe?

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

(EDIT - Answer to comment below)



In your case, I would go with a model like this:

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 "employee" as far as I know. The employee method will allow you to see, for example, how "free" this eployee is on a specific date.

+1


source


"I know there is no silver bullet solution for this kind of solution."

It depends a little on how much silver your bullet needs.

Anyway. You may also find the following interesting:

(a) "TSQL2 Review and Analysis" by Hugh Darwen and CJ Date. The link is on www.thethirdmanifesto.com in the Documents section below. (b) Temporal Data and the Relational Model, a complete book by the same authors plus Nikos Lorenzos. Contains a different, complete proposal and very well-founded reasons why they think the proposal is better. (c) You can find an implementation I wrote called SIRA_PRISE based on ideas from (b) at shark.armchair.mb.ca/~erwin

0


source







All Articles