Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source 'https://rubygems.org'
# heroku tools
gem 'rails_12factor'
# ruby version
ruby '2.2.5'
ruby '2.3.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0'
# Super fast rails server
Expand Down Expand Up @@ -49,6 +49,9 @@ gem 'redis'
gem 'colorize'
gem 'rack-cors', :require => 'rack/cors'

# Worker Gems
gem 'deep_clone', '~> 0.0.1'

group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ GEM
compass (~> 1.0.0)
concurrent-ruby (1.0.2)
debug_inspector (0.0.2)
deep_clone (0.0.1)
devise (4.2.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -237,6 +238,7 @@ DEPENDENCIES
byebug
coffee-rails (~> 4.1.0)
colorize
deep_clone (~> 0.0.1)
devise
factory_girl_rails
ffaker
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/api/v1/courses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class Api::V1::CoursesController < ApiController
require 'pry'
class Api::V1::CoursesController < Api::V1::ReqTreeController
end
2 changes: 1 addition & 1 deletion app/controllers/api/v1/degree_majors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class Api::V1::DegreeMajorsController < ApiController
class Api::V1::DegreeMajorsController < Api::V1::ReqTreeController
end
2 changes: 1 addition & 1 deletion app/controllers/api/v1/degree_minors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class Api::V1::DegreeMinorsController < ApiController
class Api::V1::DegreeMinorsController < Api::V1::ReqTreeController
end
21 changes: 21 additions & 0 deletions app/controllers/api/v1/req_tree_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Api::V1::ReqTreeController < ApiController
before_action :remove_req_tree
before_action :clean_req_tree

# Remove tree from incoming request if current_user is not admin
def remove_req_tree
unless current_user.type == 'Admin'
if params[:data]
if params[:data][:attributes][:tree]
Rails.logger.debug("COURSE: ".green + "Removed tree param")
params[:data][:attributes].delete(:tree)
end
end
end
end

# Clean the tree on every request
def clean_req_tree
params[:data] = Worker::Maintain.clean_req_tree(current_user, params[:data])
end
end
36 changes: 30 additions & 6 deletions app/controllers/api/v1/timelines_controller.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
require 'pry'
# require 'lib/worker'
class Api::V1::TimelinesController < ApiController

# TODO: implement map function in the create timeline action on this controller
def update
if params[:data][:attributes][:sync]
Rails.logger.debug("MAPPER: ".green + "Syncing timeline...")
# Set sync back to false
params[:data][:attributes][:sync] = false
# Modify the contents of quarters back calling mapping functions
map
# Create and set decision tree for jsonapi-resources to save
decision_tree_raw = create_decision_tree.tree
params[:data][:attributes][:tree] = decision_tree_raw.to_json
end
# Call default action
super
end

# TODO: implement map function in the create timeline action on this controller
# @desc Assumes that every node in each record's tree has up-to-date id
# information, allowing the corresponding records to fetched.
# TODO: Current problem is that recursively fetching every record for a
# decision tree is both inefficient and slow. It would be better to
# fetch all neccessary records in bulk, but that would require prior
# knowledge of the nested associations. One possiblity is creating an
# associated records hash on degree majors/minors that's updated
# whenever their req tree changes. For now, opting into the slow and
# inefficient method to save dev time.
def create_decision_tree
Rails.logger.debug("TIMELINE: ".green + "Creating decision tree...")
# get all records containing req trees
req_tree_records = []
req_tree_records << current_user.timelines.where(is_current: true).first.degree_majors
req_tree_records << current_user.timelines.where(is_current: true).first.degree_minors
req_tree_records.flatten!
# get all completed course records
completed_course_records = current_user.courses

return Worker::Prepare::DecisionTree.new(current_user, req_tree_records, completed_course_records)
end

def map
Rails.logger.debug("MAPPER: ".green + "Performing map...")
Rails.logger.debug("TIMELINE: ".green + "Performing map...")

# perform the steps detailed in previously determined algorithms
# binding.pry
end

end
Loading