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
8 changes: 8 additions & 0 deletions app/api/entities/task_definition_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ def staff?(my_role)
expose :overseer_image_id, if: ->(unit, options) { staff?(options[:my_role]) }
expose :assessment_enabled, if: ->(unit, options) { staff?(options[:my_role]) }
expose :moss_language, if: ->(unit, options) { staff?(options[:my_role]) }

expose :estimated_days do |task_def, _options|
task_def.estimated_days
end

expose :estimated_hours do |task_def, _options|
task_def.estimated_hours
end
end
end
20 changes: 18 additions & 2 deletions app/api/task_definitions_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class TaskDefinitionsApi < Grape::API
optional :assessment_enabled, type: Boolean, desc: 'Enable or disable assessment'
optional :overseer_image_id, type: Integer, desc: 'The id of the Docker image for overseer'
optional :moss_language, type: String, desc: 'The language to use for code similarity checks'
optional :estimated_days, type: Integer, desc: 'Estimated time to complete task, measured in days'
optional :estimated_hours, type: Integer, desc: 'Estimated time to complete task, measured in hours'
end
end
post '/units/:unit_id/task_definitions/' do
Expand Down Expand Up @@ -61,12 +63,18 @@ class TaskDefinitionsApi < Grape::API
:max_quality_pts,
:assessment_enabled,
:overseer_image_id,
:moss_language
:moss_language,
:estimated_days,
:estimated_hours
)

task_params[:unit_id] = unit.id
task_params[:upload_requirements] = JSON.parse(params[:task_def][:upload_requirements]) unless params[:task_def][:upload_requirements].nil?

days = task_params.delete(:estimated_days).to_i
hours = task_params.delete(:estimated_hours).to_i
task_params[:estimated_time_minutes] = (days * 24 * 60) + (hours * 60)

task_def = TaskDefinition.new(task_params)

# Set the tutorial stream
Expand Down Expand Up @@ -111,6 +119,8 @@ class TaskDefinitionsApi < Grape::API
optional :assessment_enabled, type: Boolean, desc: 'Enable or disable assessment'
optional :overseer_image_id, type: Integer, desc: 'The id of the Docker image name for overseer'
optional :moss_language, type: String, desc: 'The language to use for code similarity checks'
optional :estimated_days, type: Integer, desc: 'Estimated time to complete task, measured in days'
optional :estimated_hours, type: Integer, desc: 'Estimated time to complete task, measured in hours'
end
end
put '/units/:unit_id/task_definitions/:id' do
Expand Down Expand Up @@ -138,11 +148,17 @@ class TaskDefinitionsApi < Grape::API
:max_quality_pts,
:assessment_enabled,
:overseer_image_id,
:moss_language
:moss_language,
:estimated_days,
:estimated_hours
)

task_params[:upload_requirements] = JSON.parse(params[:task_def][:upload_requirements]) unless params[:task_def][:upload_requirements].nil?

days = task_params.delete(:estimated_days).to_i
hours = task_params.delete(:estimated_hours).to_i
task_params[:estimated_time_minutes] = (days * 24 * 60) + (hours * 60)

# Ensure changes to a TD defined as a "draft task definition" are validated
if unit.draft_task_definition_id == params[:id]
if params[:task_def][:upload_requirements]
Expand Down
8 changes: 8 additions & 0 deletions app/models/task_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,14 @@ def read_file_from_resources(filename)
nil
end

def estimated_days
estimated_time_minutes.to_i / 60 / 24
end

def estimated_hours
(estimated_time_minutes.to_i / 60) % 24
end

private

def delete_associated_files()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddEstimatedTimeMinutesToTaskDefinitions < ActiveRecord::Migration[7.1]
def up
add_column :task_definitions, :estimated_time_minutes, :integer, null: true, default: 0, comment: "Estimated time to complete task, measured in minutes"
end

def down
remove_column :task_definitions, :estimated_time_minutes
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_05_28_223908) do
ActiveRecord::Schema[7.1].define(version: 2026_03_26_104829) do
create_table "activity_types", charset: "utf8", collation: "utf8_unicode_ci", force: :cascade do |t|
t.string "name", null: false
t.string "abbreviation", null: false
Expand Down Expand Up @@ -250,6 +250,7 @@
t.bigint "overseer_image_id"
t.string "tii_group_id"
t.string "moss_language"
t.integer "estimated_time_minutes", default: 0, comment: "Estimated time to complete task, measured in minutes"
t.index ["group_set_id"], name: "index_task_definitions_on_group_set_id"
t.index ["overseer_image_id"], name: "index_task_definitions_on_overseer_image_id"
t.index ["tutorial_stream_id"], name: "index_task_definitions_on_tutorial_stream_id"
Expand Down
18 changes: 15 additions & 3 deletions test/api/units/task_definitions_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def all_task_def_keys
'restrict_status_updates',
'plagiarism_warn_pct',
'is_graded',
'max_quality_pts'
'max_quality_pts',
'estimated_days',
'estimated_hours'
]
end

Expand All @@ -49,7 +51,9 @@ def test_task_definition_cud
upload_requirements: '[ { "key": "file0", "name": "Shape Class", "type": "document" } ]',
plagiarism_warn_pct: 80,
is_graded: false,
max_quality_pts: 0
max_quality_pts: 0,
estimated_days: 1,
estimated_hours: 0
}
}

Expand All @@ -65,6 +69,9 @@ def test_task_definition_cud
assert_json_matches_model td, last_response_body, all_task_def_keys
assert_equal unit.tutorial_streams.first.id, td.tutorial_stream_id
assert_equal 4, td.weighting
assert_equal (24 * 60), td.estimated_time_minutes
assert_equal 1, last_response_body['estimated_days']
assert_equal 0, last_response_body['estimated_hours']


data_to_put = {
Expand All @@ -83,7 +90,9 @@ def test_task_definition_cud
upload_requirements: [ { "key": "file0", "name": "Other Class", "type": "document" } ].to_json,
plagiarism_warn_pct: 80,
is_graded: false,
max_quality_pts: 0
max_quality_pts: 0,
estimated_days: 2,
estimated_hours: 3
}
}

Expand All @@ -98,6 +107,9 @@ def test_task_definition_cud
assert_json_matches_model td, last_response_body, all_task_def_keys
assert_equal unit.tutorial_streams.last.id, td.tutorial_stream_id
assert_equal 2, td.weighting
assert_equal 3060, td.estimated_time_minutes
assert_equal 2, last_response_body['estimated_days']
assert_equal 3, last_response_body['estimated_hours']
end

def test_post_invalid_file_tasksheet
Expand Down