Skip to content

Commit

Permalink
Update neo seeds to be more realistic
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbuker committed Sep 22, 2024
1 parent 2b78424 commit 177b6f6
Showing 1 changed file with 78 additions and 40 deletions.
118 changes: 78 additions & 40 deletions db/seeds/neo_seeds.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
TASK_COMPLETION_CHANCE = 0.2
MINIMUM_LAYER_RATIO = 0.0
MAXIMUM_LAYER_RATIO = 1.2
MAXIMUM_TOTAL_LAYERS = 5
MINIMUM_PRES = 1
MAXIMUM_PRES = 5

neo = User.create!(
username: 'neo',
given_name: 'Thomas',
Expand Down Expand Up @@ -44,55 +51,86 @@ def random_title
].sample
end

#################
## Inbox Items ##
#################

25.times do |n|
def create_task(user:, list:, title_key:, completed:)
Task.create!(
user: neo,
list: inbox_list,
title: "#{random_title} - #{n}",
notes: random_notes
user: user,
list: list,
title: "#{random_title} - #{title_key}",
notes: random_notes,
completed: completed
)
end

##################
## Next Actions ##
##################
def random_completed_chance
rand < TASK_COMPLETION_CHANCE
end

20.times do |n|
Task.create!(
user: neo,
list: next_action_list,
title: "#{random_title} - #{n}",
notes: random_notes
)
def calculate_next_layer_count(total_layers:, tasks_count:)
random_count = (tasks_count * rand(MINIMUM_LAYER_RATIO..MAXIMUM_LAYER_RATIO)).ceil
falloff = 1-(((total_layers-1)/(MAXIMUM_TOTAL_LAYERS-1).to_f) ** 2)
(random_count * falloff).floor
end

#################
## Waiting For ##
#################
def generate_task_tree(user:, list:, layer_zero_count:)
puts "Generating tree for #{list.title} with a layer zero of #{layer_zero_count} incomplete tasks."
current_layer = generate_layer_zero(user: user, list: list, count: layer_zero_count)
total_layers = 1
loop do
next_layer_count = calculate_next_layer_count(
total_layers: total_layers,
tasks_count: current_layer.count
)
break if next_layer_count <= 0
total_layers += 1
puts "Generating layer of size: #{next_layer_count}"
next_layer = generate_layer(user: user, list: list, count: next_layer_count)
entangle_layers(tasks: current_layer, posts: next_layer)
current_layer = next_layer
end
puts "Tree generation completed for #{list.title}!"
end

15.times do |n|
Task.create!(
user: neo,
list: waiting_for_list,
title: "#{random_title} - #{n}",
notes: random_notes
# delegated_to: Faker::Name.name
)
def generate_layer_zero(user:, list:, count:)
layer = []
# Ensure we have exactly the desired layer zero count
count.times do |n|
layer.push(create_task(user: user, list: list, title_key: n, completed: false))
end

# Create some completed tasks in layer zero to feed off of
(TASK_COMPLETION_CHANCE*count).ceil.times do |n|
layer.push(create_task(user: user, list: list, title_key: n, completed: true))
end

layer
end

##############
## Projects ##
##############
def generate_layer(user:, list:, count:)
layer = []
count.times do |n|
layer.push(create_task(user: user, list: list, title_key: n, completed: random_completed_chance))
end
layer
end

10.times do |n|
Task.create!(
user: neo,
list: project_list,
title: "#{random_title} - #{n}",
notes: random_notes
)
def entangle_layers(tasks:, posts:)
posts.each do |post|
pres_count = rand(MINIMUM_PRES..MAXIMUM_PRES).ceil
tasks.shuffle.first(pres_count).each do |task|
TaskHardRequisite.create!(
pre: task,
post: post
)
post.update!(completed: true) if task.completed?
end
end
end

####################
## Generate Tasks ##
####################

generate_task_tree(user: neo, list: inbox_list, layer_zero_count: 8)
generate_task_tree(user: neo, list: next_action_list, layer_zero_count: 165)
generate_task_tree(user: neo, list: waiting_for_list, layer_zero_count: 5)
generate_task_tree(user: neo, list: project_list, layer_zero_count: 127)

0 comments on commit 177b6f6

Please sign in to comment.