Skip to content

Commit

Permalink
Merge branch 'master' of github.com:daviddob/Autolab
Browse files Browse the repository at this point in the history
  • Loading branch information
David Dobmeier committed Aug 27, 2017
2 parents 9a10906 + 764a62a commit ed03711
Show file tree
Hide file tree
Showing 61 changed files with 1,162 additions and 103 deletions.
31 changes: 28 additions & 3 deletions app/assets/javascripts/initialize_datetimepickers.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
// Initialize all Bootstrap 3 Datetime Pickers on the page
// Initialize all Flatpicker Datetime Pickers on the page
;(function() {

$(document).ready(function() {
var datetimeElts = $('.datetimepicker');

for (var i = 0; i < datetimeElts.length; i++) {
var defaultDate = new Date(moment())
if ($(datetimeElts[i]).val()) {
defaultDate = new Date(moment($(datetimeElts[i]).val()))
}

$(datetimeElts[i]).flatpickr({
enableTime: true,
altInput: true,
defaultDate: new Date(datetimeElts[i].getAttribute("value"))
defaultDate: defaultDate
})
}

var dateElts = $('.datepicker');

for (var i = 0; i < dateElts.length; i++) {
var defaultDate = new Date(moment())
if ($(dateElts[i]).val()) {
defaultDate = new Date(moment($(dateElts[i]).val()).format("MMMM D YYYY"))
}

$(dateElts[i]).flatpickr({
altInput: true,
defaultDate: moment($(dateElts[i]).val()).format("MMMM D YYYY")
defaultDate: defaultDate
})
}


var timeElements = $('.timepicker');
for (var i = 0; i < timeElements.length; i++) {
$(timeElements[i]).flatpickr({
enableTime: true,
noCalendar: true,
enableSeconds: false,
time_24hr: true,
defaultHour: 12,
defaultMinute: 0,
defaultDate: "12:00"
});
}
});

})();
3 changes: 3 additions & 0 deletions app/assets/javascripts/sections.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sections.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the sections controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
4 changes: 2 additions & 2 deletions app/controllers/assessment/handin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def handin
if @assessment.embedded_quiz

contents = params[:submission]["embedded_quiz_form_answer"].to_s

out_file = File.new("out.txt", "w+")
tmp_uuid = SecureRandom.hex 32
out_file = File.new("/tmp/embedded_form_"+tmp_uuid, "w+")
out_file.puts(contents)

params[:submission]["file"] = out_file
Expand Down
120 changes: 119 additions & 1 deletion app/controllers/assessments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def create
@assessment.quiz = false
@assessment.quizData = ""
@assessment.max_submissions = params.include?(:max_submissions) ? params[:max_submissions] : -1

@assessment.base_section_day = params["sectionDependant"].nil? ? nil : Time.now + (60 * 60 * 24 * 7)
if @assessment.embedded_quiz
begin
@assessment.embedded_quiz_form_data = params[:assessment][:embedded_quiz_form].read
Expand Down Expand Up @@ -389,6 +389,9 @@ def destroy

action_auth_level :show, :student
def show
if !@assessment.is_released_for_this_user?(@cud)
redirect_to course_assessments_path
end
set_handin
extend_config_module(@assessment, @submission, @cud)

Expand Down Expand Up @@ -513,6 +516,112 @@ def reload
redirect_to(action: :show) && return
end

action_auth_level :viewAssigned, :course_assistant
def viewAssigned

redirect_to(action: "viewGradesheet") && return
end


action_auth_level :unassignCA, :instructor
def unassignCA
for submission in @assessment.submissions do
submission.set_grader("Unassigned")
end
@assessment.assignCA = false
@assessment.save!
flash[:success] = "Success: Submissions have no assigned graders."
redirect_to(action: :show) && return
end

action_auth_level :assignCA, :instructor
def assignCA
conflicts = {}
hours = {}
course_assistants = @course.course_assistants
for course_assistant in course_assistants do
if !course_assistant.conflictingstudents.nil?
conflicts[course_assistant] = course_assistant.conflictingstudents.split(/\s*,\s*/)
else
conflicts[course_assistant] = []
end
if !course_assistant.hours.nil?
hours[course_assistant] = course_assistant.hours
else
hours[course_assistant] = 0
end
end
bestSolution = -1
bestAssignment = {}
totalHours = 0
badnessAcrossSolutions = []
for course_assistant in course_assistants do
totalHours += hours[course_assistant]
end
if totalHours == 0
flash[:error] = "All the CAs work 0 hours per week. Aborting."
redirect_to([@course, @assessment, :submissions])
return;
end
for i in 0..30 do
r = Random.new
assignments = {}
for course_assistant in course_assistants do
assignments[course_assistant] = []
end
for submission in @assessment.submissions.latest do
canGrade = []
for course_assistant in course_assistants do
if !conflicts[course_assistant].include? submission.course_user_datum.user.email
canGrade.push(course_assistant)
end
end
probabilityBalancing = []
for course_assistant in canGrade do
for i in 1..hours[course_assistant] do
probabilityBalancing.push(course_assistant)
end
end
if probabilityBalancing.length != 0
choice = r.rand(0...probabilityBalancing.length)
assignments[probabilityBalancing[choice]].push(submission.course_user_datum)
end
end
badness = []
assignments.each do |course_assistant, assignments|
idealSubmissions = hours[course_assistant].to_f/totalHours
badnessta = ((idealSubmissions*@assessment.submissions.latest.count - assignments.count).round).abs
badness.push(badnessta)
end
badnessSolution = badness.max
badnessAcrossSolutions.push(badnessSolution)
if bestSolution == -1 || badnessSolution < bestSolution
bestSolution = badnessSolution
bestAssignment = assignments
end
end
s = {}
bestAssignment.each do |course_assistant, assignments|
s[course_assistant.user.email] = []
for student in assignments do
s[course_assistant.user.email].push(student.user.email)
end
end
studentGrader = {}
bestAssignment.each do |course_assistant, assignments|
for student in assignments do
studentGrader[student] = course_assistant
end
end
for submission in @assessment.submissions.latest do
submission.set_grader(studentGrader[submission.course_user_datum].user.email)
end
flash[:success] = badnessAcrossSolutions.to_s + " Badness: #{bestSolution}"
@assessment.assignCA = true
@assessment.save!
redirect_to([@course, @assessment, :submissions])
end

action_auth_level :edit, :instructor
def edit
# default to the basic tab
Expand All @@ -535,7 +644,16 @@ def update
@assessment.embedded_quiz_form_data = params[:assessment][:embedded_quiz_form].read
@assessment.save!
end
if @assessment.is_section_dependant
edit_assessment_params["base_section_day"] = params["assessment"]["start_at"]
edit_assessment_params["start_offset"] = params["startoffset"]
edit_assessment_params["end_offset"] = params["endoffset"]
edit_assessment_params["on_day"] = params["sameDay"].nil? ? 0 : 1
edit_assessment_params["lecture"] = params["lecture"].nil? ? 0 : 1
edit_assessment_params["start_at"] = Date.parse(edit_assessment_params["base_section_day"]).to_datetime
edit_assessment_params["due_at"] = edit_assessment_params["start_at"]+ 30.minutes

end
flash[:success] = "Saved!" if @assessment.update!(edit_assessment_params)

redirect_to(action: :edit) && return
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/course_user_data_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ def add_users_breadcrumb
def cud_params
if @cud.administrator?
params.require(:course_user_datum).permit(:school, :major, :year,
:lecture, :section, :instructor, :dropped, :nickname, :course_assistant,
:lecture, :section, :instructor, :dropped, :nickname, :course_assistant, :conflictingstudents, :hours,
user_attributes: [:first_name, :last_name, :email],
tweak_attributes: [:_destroy, :kind, :value])
elsif @cud.instructor?
params.require(:course_user_datum).permit(:school, :major, :year,
:lecture, :section, :instructor, :dropped, :nickname, :course_assistant,
:lecture, :section, :instructor, :dropped, :nickname, :course_assistant, :conflictingstudents, :hours,
user_attributes: [:email, :first_name, :last_name],
tweak_attributes: [:_destroy, :kind, :value])
else
Expand All @@ -224,12 +224,12 @@ def cud_params
def edit_cud_params
if @cud.administrator?
params.require(:course_user_datum).permit(:school, :major, :year,
:lecture, :section, :instructor, :dropped, :nickname, :course_assistant,
:lecture, :section, :instructor, :dropped, :nickname, :course_assistant, :conflictingstudents, :hours,
user_attributes: [:id, :email, :first_name, :last_name],
tweak_attributes: [:_destroy, :kind, :value])
elsif @cud.instructor?
params.require(:course_user_datum).permit(:school, :major, :year,
:lecture, :section, :instructor, :dropped, :nickname, :course_assistant,
:lecture, :section, :instructor, :dropped, :nickname, :course_assistant, :conflictingstudents, :hours,
user_attributes: [:id, :email, :first_name, :last_name],
tweak_attributes: [:_destroy, :kind, :value])
else
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ def create
redirect_to(root_path) && return
end


re = /[^A-Za-z0-9._~:\.\/\[\]@!$&'()*+,;=`\-_]/

# Check for matches
new_course_params['name'].scan(re) do |match|
flash[:error] = "Invalid character \'" + match + "\' detected"
redirect_to(new_course_path) && return
end

@newCourse = Course.new(new_course_params)
@newCourse.display_name = @newCourse.name

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/section_user_data_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class SectionUserDataController < ApplicationController


end
101 changes: 101 additions & 0 deletions app/controllers/sections_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
class SectionsController < ApplicationController

@@days_lookup = {"0" => '2016-05-01',"1" => '2016-05-02',"2" => '2016-05-03',"3" => '2016-05-04',"4" => '2016-05-05',"5" => '2016-05-06',"6" => '2016-05-07'}
def index
end

action_auth_level :show, :instructor
def show

end
action_auth_level :users, :instructor
def users

end

def create
# check for permission
unless current_user.instructor?
flash[:error] = "Permission denied."
redirect_to(course_assessments_path) && return
end

data = params["sections"]

# basic data verifcation
if data['name'] == ""
flash[:error] = "please provide a valid name"
redirect_to(course_sections_path) && return
end
if data['day'] == ""
flash[:error] = "please provide a valid day"
redirect_to(course_sections_path) && return
end

if data["start time"] >= data["end time"]
flash[:error] = "please make sure the end time is after the start time"
redirect_to(course_sections_path) && return
end


# see if we want to delete the record
if(params["commit"] == "Delete")
delete
return
end

# see if we want to edit an existing record
@old_section = Sections.where("course_id = ? && name = ?", @course.id, data["name"])
if(@old_section.exists?)
edit
return
end

# we must want to create one then so do it

@new_section = Sections.new
@new_section.name = data["name"]
@new_section.course_id = @course.id
@new_section.start = @@days_lookup[data["day"]] + " " + data["start time"] + ":00"
@new_section.end = @@days_lookup[data["day"]] + " " + data["end time"] + ":00"
@new_section.save

flash[:success] = "saved"
redirect_to(course_sections_path) && return
end

def manage
end

def edit
data = params["sections"]
@old_section = @old_section.first
@old_section.start = @@days_lookup[data["day"]] + " " + data["start time"] + ":00"
@old_section.end = @@days_lookup[data["day"]] + " " + data["end time"] + ":00"
@old_section.save
flash[:success] = "edit complete"
redirect_to(course_sections_path) && return
end


def delete
data = params["sections"]
Sections.where("course_id = ? && name = ?", @course.id, data["name"]).first.destroy
flash[:success] = "deletion complete"
redirect_to(course_sections_path) && return
end

action_auth_level :editusers, :instructor
def editusers
user = CourseUserDatum.find(params['id'])

if params['lecture']
user.lecture = params["sectionName"]
else
user.section = params["sectionName"]
end
user.save
render :json => { :success => true}
end

end
Loading

0 comments on commit ed03711

Please sign in to comment.