Overview
The Assignment model represents a programming assignment or contest in Wecode. It manages assignment configuration, participant access, submission deadlines, late penalties, and relationships to problems and classes.Fillable Fields
The name/title of the assignment
Maximum number of submissions allowed per problem (0 for unlimited)
Whether the assignment is open for submissions
Whether to display the scoreboard for this assignment
Whether to enable Java exception handling
When the assignment starts and students can begin submittingCast:
datetimeWhen the assignment ends (before extra_time is applied)Cast:
datetimeAdditional time in seconds after finish_time (deadline = finish_time + extra_time)
Expression language formula for calculating late submission coefficientUses Symfony ExpressionLanguage with variables:
delay, extra_timeExample: 100 - (delay / extra_time) * 100Comma-separated list or description of participants
Assignment description and instructions (HTML supported)
ID of the user (instructor) who created this assignment
Comma-separated list of allowed programming language IDs
Relationships
problems()
Problems attached to this assignmentPivot fields:
score- Points awarded for this problemordering- Display order in assignmentproblem_name- Custom name for the problem in this assignment
user()
The instructor who created this assignment
submissions()
All submissions made to this assignment
lops()
Classes/groups that have access to this assignment
scoreboard()
The cached scoreboard for this assignment
Public Methods
assignment_info()
Static method to retrieve assignment information by ID.$assignment_id(integer) - Assignment ID to retrieve
can_submit()
Checks if a user can submit to this assignment.$user(User) - User attempting to submit$problem(Problem, optional) - Specific problem to check for practice assignments
can_submit(boolean) - Whether submission is allowederror_message(string) - Error message if submission is not allowed
- Guest users cannot submit
- Trial accounts must not be expired
- Practice problems require permission
- Assignment must be open (for students)
- Assignment must have started (for students)
- Assignment must not be finished
- User must be a participant
is_participant()
Checks if a user is registered as a participant.$user(User) - User to check
boolean
Logic:
- Practice assignments (id=0): Always returns
true - Admin users: Always returns
true - Other users: Checks if user belongs to any of the assignment’s lops (classes)
started()
Checks if the assignment has started.boolean - True if current time >= start_time
is_finished()
Checks if the assignment deadline has passed.boolean - True if current time > finish_time + extra_time
eval_coefficient()
Calculates the current late submission coefficient based on current time.float|string - Coefficient value (0-10000) or “error” if calculation fails
Example:
update_submissions_coefficient()
Recalculates and updates coefficients for all submissions in this assignment.late_rule formula
cannot_edit()
Checks if a user has permission to edit this assignment.$actor(User) - User attempting to edit
false if editing is allowed, or string error message if not
Permission rules:
- Admin: Can edit any assignment
- Head instructor: Can edit own assignments or assignments in their classes
- Others: Cannot edit
reset_final_submission_choices()
Recalculates which submissions are marked as final for scoring.- For each user-problem pair, selects the best submission
- Prioritizes submissions with
pre_score = 10000(full marks) - Among full-score submissions, chooses highest final score (considering coefficient)
- Updates
is_finalflag on all submissions
Expression Language Provider
Thelate_rule field uses Symfony ExpressionLanguage with custom math functions:
Available Functions
abs, acos, acosh, asin, asinh, atan, atan2, atanh, base_convert, bindec, ceil, cos, cosh, decbin, dechex, decoct, deg2rad, exp, expm1, fdiv, floor, fmod, hexdec, hypot, intdiv, is_finite, is_infinite, is_nan, log, log10, log1p, max, min, octdec, pi, pow, rad2deg, round, sin, sinh, sqrt, tan, tanh
Available Variables
delay(integer) - Seconds between finish_time and submission time (negative if early)extra_time(integer) - The assignment’s extra_time field

