Overview
Themoss_controller integrates with Stanford’s MOSS (Measure of Software Similarity) system to detect code plagiarism in assignment submissions. It provides interfaces for configuring MOSS, submitting code for analysis, and viewing results.
Constructor
auth- Requires user authentication
Methods
index()
Assignment ID to view MOSS results for
- Admin and head_instructor only
- Aborts with 403 for other roles
- All assignments list
- Current MOSS user ID from settings
- Selected assignment information
- Last MOSS update timestamp
- MOSS results for each problem:
- Problem data
- MOSS report URL (if available)
- “submission submitted” message (if processing)
- NULL (if not yet analyzed)
/moss/{id?} (GET)
Example from controller:
update()
Assignment ID (for redirect after update)
MOSS user ID obtained from Stanford
- Admin and head_instructor only (implied from route)
- Saves MOSS user ID to settings
- Reads original MOSS script template
- Replaces placeholder with actual user ID
- Writes configured script to tester path
- Makes script executable
/moss/{id} (POST)
Example from controller:
detect()
Assignment ID to analyze
Trigger parameter (must be present)
detect: required
- Admin and head_instructor only (implied from form submission)
/moss/detect/{id} (POST)
Private Methods
_detect()
Assignment ID to analyze
-
Get Final Submissions
- Fetches all final submissions for the assignment
- Groups submissions by problem ID
-
For Each Problem:
- Builds list of submission file paths
- Submits files to MOSS via command line
- Redirects MOSS output to
moss_link.txt - Creates
moss_runningflag file
-
Update Timestamp
- Records MOSS update time in assignment record
MOSS Integration Workflow
1. Initial Setup
-
Obtain MOSS Account
- Register at Stanford MOSS website
- Receive MOSS user ID via email
-
Configure Wecode
- Navigate to MOSS page for any assignment
- Enter MOSS user ID in configuration form
- Submit to save and configure MOSS script
2. Running Detection
-
Select Assignment
- Navigate to
/moss/{assignment_id} - View current MOSS status for all problems
- Navigate to
-
Trigger Detection
- Click “Detect” button
- System collects all final submissions
- Submissions grouped by problem
- Files submitted to MOSS in background
-
Processing States
- Not Analyzed: No MOSS results yet (NULL)
- Processing: “submission submitted to moss, awaiting response”
- Complete: MOSS report URL displayed
3. Viewing Results
-
Check Status
- Refresh MOSS page to check for completion
- Once complete, MOSS URL appears
-
Access Report
- Click on MOSS URL
- Opens Stanford MOSS report in new tab
- Report shows similarity percentages and matches
MOSS Script Configuration
Template Structure
The system uses a template filemoss_original with placeholder:
Configuration Process
- Read
moss_originaltemplate from tester path - Replace
MOSS_USER_IDwith actual user ID - Write to
mossfile in tester path - Make executable with
chmod +x
Paths
- Template:
{tester_path}/moss_original - Configured Script:
{tester_path}/moss - Results:
{assignments_root}/assignment_{id}/problem_{id}/moss_link.txt
MOSS Result Files
moss_link.txt
Contains MOSS output including the report URL:tail -n1) contains the report URL.
moss_running
Flag file indicating MOSS submission is in progress:- Created when MOSS detection starts
- Deleted when results are retrieved
- Presence indicates “awaiting response” state
Settings
moss_userid
Type: String Description: MOSS user ID obtained from Stanford registration Storage: System settings table Usage: Injected into MOSS script for authenticationNotes
Supported Languages
MOSS supports various programming languages. The script automatically detects language based on file extension:- C/C++ (.c, .cpp, .cc, .h)
- Java (.java)
- Python (.py, .py2, .py3)
- Pascal (.pas)
- And many more
Background Processing
MOSS detection runs in background using shell redirection:& allows the web request to complete while MOSS processes asynchronously.
Result Persistence
MOSS results are stored in the filesystem per problem, not in the database. This allows:- Independent analysis per problem
- Easy re-analysis without data loss
- Direct file access for debugging
Related Models
- Assignment: Assignment being analyzed
- Submission: Student submissions to compare
- Language: Programming language detection
- Setting: MOSS configuration storage

