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
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ GEM
thor
crass (1.0.6)
date (3.4.1)
debug (1.8.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
debug (1.10.0)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.0)
docile (1.4.0)
domain_name (0.6.20240107)
Expand All @@ -116,8 +116,8 @@ GEM
domain_name (~> 0.5)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-console (0.6.0)
irb (1.15.1)
io-console (0.8.0)
irb (1.15.2)
pp (>= 0.6.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
Expand Down Expand Up @@ -220,10 +220,10 @@ GEM
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.0.6)
rdoc (6.12.0)
rdoc (6.13.1)
psych (>= 4.0.0)
regexp_parser (2.8.1)
reline (0.6.0)
reline (0.6.1)
io-console (~> 0.5)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
Expand Down Expand Up @@ -281,7 +281,7 @@ GEM
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
spring (4.1.1)
stringio (3.1.4)
stringio (3.1.6)
sync (0.5.0)
term-ansicolor (1.11.2)
tins (~> 1.0)
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/api/v1/student_tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class Api::V1::StudentTasksController < ApplicationController

# List retrieves all student tasks associated with the current logged-in user.
def action_allowed?
has_privileges_of?('Student')
end

# Retrieves all tasks that belong to the current user.
def list
# Retrieves all tasks that belong to the current user.
@student_tasks = StudentTask.from_user(current_user)
# Render the list of student tasks as JSON.
render json: @student_tasks, status: :ok
Expand All @@ -24,5 +24,4 @@ def view
# Render the found student task as JSON.
render json: @student_task, status: :ok
end

end
42 changes: 40 additions & 2 deletions app/models/student_task.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
class StudentTask
attr_accessor :assignment, :current_stage, :participant, :stage_deadline, :topic, :permission_granted
attr_accessor :assignment, :course, :current_stage, :participant, :stage_deadline, :topic, :permission_granted, :deadlines, :review_grade

# Initializes a new instance of the StudentTask class
def initialize(args)
@assignment = args[:assignment]
@course = args[:course]
@current_stage = args[:current_stage]
@participant = args[:participant]
@stage_deadline = args[:stage_deadline]
@topic = args[:topic]
@permission_granted = args[:permission_granted]
@team_name = args[:team_name]
@deadlines = args[:deadlines]
@review_grade = args[:review_grade]
end

# create a new StudentTask instance from a Participant object.cccccccc
def self.create_from_participant(participant)
new(
assignment: participant.assignment.name, # Name of the assignment associated with the student task
course: participant.assignment.course.name,
topic: participant.topic, # Current stage of the assignment process
current_stage: participant.current_stage, # Participant object
stage_deadline: parse_stage_deadline(participant.stage_deadline), # Deadline for the current stage of the assignment
permission_granted: participant.permission_granted, # Topic of the assignment
deadlines: sample_deadlines,
review_grade: generate_review_grade(participant),
participant: participant # Boolean indicating if Publishing Rights is enabled
)
end
Expand All @@ -42,7 +49,38 @@ def self.from_participant_id(id)
def self.parse_stage_deadline(date_string)
Time.parse(date_string)
rescue StandardError
Time.now + 1.year
Time.now
end

# Generates a sample list of assignment deadlines relative to today's date.
# This is likely used for testing or placeholder UI data.
def self.sample_deadlines
today = Date.today
[
{ id: 1, date: (today - 15).to_s, description: "Submission deadline" },
{ id: 2, date: (today - 3).to_s, description: "Round 1 peer review" },
{ id: 2, date: (today - 3).to_s, description: "Round 2 peer review" },
{ id: 2, date: (today + 7).to_s, description: "Review deadline" },
]
end

# Generates a simulated review grade for a participant.
# This is likely placeholder logic for demonstration or testing purposes.
def self.generate_review_grade(participant)
# Randomly decide whether the participant has reviews or not
if [true, false].sample
reviews = rand(1..6)
base_score_per_review = 10
penalty_percent = [0, 10, 25, 50].sample
raw_score = reviews * base_score_per_review
final_score = (raw_score * (1 - penalty_percent / 100.0)).round

"Score: #{final_score}/100 \n" \
"Comment: #{reviews} reviews x #{base_score_per_review} pts/review x #{100 - penalty_percent}% = #{final_score} points \n" \
"Explanation penalty (-#{penalty_percent}%)"
else
"N/A"
end
end

end
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def self.preview_path=(_)
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)


module Reimplementation
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0
config.active_record.schema_format = :ruby

# Configuration for the application, engines, and railties goes here.
#
Expand Down
Loading