Module: PredictabilityEngine::DataGenerator

Defined in:
lib/predictability_engine/data_generator.rb

Constant Summary collapse

PRESETS =
{
  small: { completed: 10, wip: 4 },
  medium: { completed: 40, wip: 10 },
  large: { completed: 150, wip: 50 },
  xl: { completed: 4000, wip: 400 }
}.freeze

Class Method Summary collapse

Class Method Details

.build_csv(completed_count, wip_count) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/predictability_engine/data_generator.rb', line 26

def self.build_csv(completed_count, wip_count)
  today = PredictabilityEngine.today
  CSV.generate do |csv|
    csv << %w[id title start_date end_date]
    write_completed(csv, completed_count, today)
    write_wip(csv, completed_count, wip_count, today)
  end
end

.content(size: :medium, completed: nil, wip: nil) ⇒ Object



19
20
21
22
23
24
# File 'lib/predictability_engine/data_generator.rb', line 19

def self.content(size: :medium, completed: nil, wip: nil)
  preset = PRESETS.fetch(size.to_sym) do
    raise ArgumentError, "Unknown size: #{size} (available: #{PRESETS.keys.join(', ')})"
  end
  build_csv(completed || preset[:completed], wip || preset[:wip])
end

.generate(output:, size: :medium, completed: nil, wip: nil) ⇒ Object



14
15
16
17
# File 'lib/predictability_engine/data_generator.rb', line 14

def self.generate(output:, size: :medium, completed: nil, wip: nil)
  File.binwrite(output, content(size: size, completed: completed, wip: wip))
  output
end

.write_completed(csv, count, today) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/predictability_engine/data_generator.rb', line 35

def self.write_completed(csv, count, today)
  (1..count).each do |i|
    start_date = today - rand(200..400)
    end_date   = start_date + rand(5..30)
    csv << ["PROJ-#{i}", "Task #{i}",
            PredictabilityEngine.format_date(start_date),
            PredictabilityEngine.format_date(end_date)]
  end
end

.write_wip(csv, offset, count, today) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/predictability_engine/data_generator.rb', line 45

def self.write_wip(csv, offset, count, today)
  ((offset + 1)..(offset + count)).each do |i|
    start_date = today - rand(1..100)
    csv << ["PROJ-#{i}", "In Progress Task #{i}",
            PredictabilityEngine.format_date(start_date), nil]
  end
end