Skip to content

Commit

Permalink
Merge branch 'feature/procedures' of github.com:bigbrainenergy-org/ap…
Browse files Browse the repository at this point in the history
…i.tdl.app into feature/procedures
  • Loading branch information
kurt-apple committed Sep 22, 2024
2 parents 1704c8f + 177b6f6 commit 4290cc1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 44 deletions.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"forwardPorts": [3000],

"initializeCommand": "bash .devcontainer/init.sh",
"postCreateCommand": "bash .devcontainer/postcreate.sh",
"postStartCommand": "bash .devcontainer/poststart.sh"
}
5 changes: 5 additions & 0 deletions .devcontainer/postcreate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

bundle config set path vendor/bundle
bundle install --jobs=1
bundle exec rails db:reset
5 changes: 1 addition & 4 deletions .devcontainer/poststart.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/bin/bash

bundle config set path vendor/bundle
bundle install --jobs=1
bundle exec rails db:reset
rm -f ./tmp/pids/server.pid
# bundle exec rails s
bundle exec rails s
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 4290cc1

Please sign in to comment.