Sha256: 3a1e6257febd6a8026173bad39c4d6379d814275f71dc021178e818a5470e1d8

Contents?: true

Size: 1.23 KB

Versions: 15

Compression:

Stored size: 1.23 KB

Contents

require_relative 'all_jobs_shared'

class AggregateJob
  include AllJobsShared

  define_source :source_data, Remi::DataSource::DataFrame
  define_target :target_data, Remi::DataTarget::DataFrame
  define_target :multigroup_target_data, Remi::DataTarget::DataFrame

  define_transform :main, sources: :source_data, targets: :target_data do
    mymin = lambda do |field, df, group_key, indicies|
      values = indicies.map { |idx| df.row[idx][field] }
      "Group #{group_key} has a minimum value of #{values.min}"
    end

    # Daru groups don't use the index of the dataframe when returning groups (WTF?).
    # Instead they return the position of the record in the dataframe.  Here, we
    # shift the indexes which causes a failure if this artifact is not handled
    # properly in the aggregate function
    source_data.df.index = Daru::Index.new(1.upto(source_data.df.size).to_a)

    target_data.df = source_data.df.aggregate(by: :alpha, func: mymin.curry.(:year)).detach_index
    target_data.df.vectors = Daru::Index.new([:alpha, :year])

    multigroup_target_data.df = source_data.df.aggregate(by: [:alpha,:beta], func: mymin.curry.(:year)).detach_index
    multigroup_target_data.df.vectors = Daru::Index.new([:alpha_beta, :year])



  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
remi-0.2.42 jobs/aggregate_job.rb
remi-0.2.41 jobs/aggregate_job.rb
remi-0.2.40 jobs/aggregate_job.rb
remi-0.2.39 jobs/aggregate_job.rb
remi-0.2.38 jobs/aggregate_job.rb
remi-0.2.37 jobs/aggregate_job.rb
remi-0.2.36 jobs/aggregate_job.rb
remi-0.2.35 jobs/aggregate_job.rb
remi-0.2.34 jobs/aggregate_job.rb
remi-0.2.33 jobs/aggregate_job.rb
remi-0.2.32 jobs/aggregate_job.rb
remi-0.2.31 jobs/aggregate_job.rb
remi-0.2.30 jobs/aggregate_job.rb
remi-0.2.29 jobs/aggregate_job.rb
remi-0.2.28 jobs/aggregate_job.rb