Ejemplo n.º 1
0
        public RunResult Run(Assignment homework)
        {
            RunResult result    = new RunResult(homework);
            string    testsPath = string.Format("{0}/courses/{1}/tests/hw{2}/", Jarvis.Config.AppSettings.Settings["workingDir"].Value, homework.Course, homework.HomeworkId);

            if (File.Exists(testsPath + "config.xml"))
            {
                List <TestCase> testCases = Utilities.ReadTestCases(testsPath + "config.xml");

                // Style check
                Logger.Info("Running style check on {0} {1}", homework.StudentId, homework.HomeworkId);
                result.StyleMessage = StyleCheck(homework);

                // Compile
                Logger.Info("Compiling {0} {1}", homework.StudentId, homework.HomeworkId);
                result.CompileMessage = Compile(homework, testCases[0].ProvidedSourceFiles);

                // Run tests
                if (result.CompileMessage == "Success!!")
                {
                    Logger.Info("Running {0} {1}", homework.StudentId, homework.HomeworkId);
                    result.OutputMessage = RunAllTestCases(testCases, homework, result);

                    // Delete binary
                    File.Delete(homework.Path + homework.StudentId);
                }
                else
                {
                    result.OutputMessage = "<p>Didn't compile... :(</p>";
                }

                // Write result into results file, writes a new entry for each run
                RecordResult(homework, result);
            }
            else
            {
                result.OutputMessage = "<p>Sir, I cannot find any test case configurations for this assignment. Is your assignment number correct?<p>";
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static void UpdateStats(Assignment homework, RunResult result)
        {
            AssignmentStats stats = null;
            string          name  = homework.Course + " - hw" + homework.HomeworkId;

            if (!Jarvis.Stats.AssignmentData.ContainsKey(name))
            {
                stats      = new AssignmentStats();
                stats.Name = name;
                Jarvis.Stats.AssignmentData.Add(name, stats);
            }
            else
            {
                stats = Jarvis.Stats.AssignmentData[name];
            }

            stats.TotalSubmissions++;

            if (!stats.TotalUniqueStudentsSubmissions.ContainsKey(homework.StudentId))
            {
                stats.TotalUniqueStudentsSubmissions.Add(homework.StudentId, string.Empty);
            }

            if (result != null && !result.OutputMessage.Contains("Is your assignment number correct"))
            {
                stats.TotalUniqueStudentsSubmissions[homework.StudentId] = result.Grade.ToString();

                if (!result.CompileMessage.Contains("Success!!"))
                {
                    stats.TotalNonCompile++;
                }

                if (!result.StyleMessage.Contains("Total&nbsp;errors&nbsp;found:&nbsp;0"))
                {
                    stats.TotalBadStyle++;
                }
            }
            Jarvis.Stats.WriteStats();
        }
Ejemplo n.º 3
0
        public JarvisModules()
        {
            #region Gets
            Get["/"] = _ =>
            {
                Logger.Trace("Handling get for /");
                return(View["index"]);
            };

            Get["/help"] = _ =>
            {
                Logger.Trace("Handling get for /help");
                return(View["help"]);
            };

            Get["/grade"] = _ =>
            {
                Logger.Trace("Handling get for /grade");
                return(View["grade"]);
            };

            Get["/stats"] = _ =>
            {
                Logger.Trace("Handling get for /stats");
                return(View["stats", Jarvis.Stats]);
            };
            #endregion

            #region Posts
            Post["/run"] = _ =>
            {
                Logger.Trace("Handling post for /run");
                Runner    runner = new Runner();
                RunResult result = null;

                StringBuilder builder = new StringBuilder();

                FileUploadRequest request    = this.Bind <FileUploadRequest>();
                Assignment        assignment = uploadHandler.HandleStudentUpload(request.Files);

                Logger.Info("Received assignment from {0} for {1} HW#{2} with {3} header", assignment.StudentId, assignment.Course, assignment.HomeworkId, assignment.ValidHeader ? "true" : "false");

                if (assignment.ValidHeader)
                {
                    // Run grader
                    Logger.Debug("Assignment header was valid");
                    result = runner.Run(assignment);
                    builder.Append(result.ToHtml());

                    StatsManager.UpdateStats(assignment, result);
                }
                else
                {
                    builder.AppendLine("<p>");
                    builder.AppendLine("The uploaded files did not contain a valid header, sir. I suggest you review the <a href='/help'>help</a>.");
                    builder.AppendFormat("<br />Parser error message: {0}", assignment.ErrorMessage);
                    builder.AppendLine("</p>");

                    Jarvis.Stats.TotalBadHeaders++;
                }

                return(builder.ToString());
            };

            Post["/grade"] = _ =>
            {
                Logger.Trace("Handling post for /grade");
                Guid   temp       = Guid.NewGuid();
                string baseDir    = Jarvis.Config.AppSettings.Settings["workingDir"].Value;
                string gradingDir = baseDir + "/grading/" + temp.ToString() + "/";
                bool   runMoss    = this.Request.Form["runMoss"];
                bool   runCode    = this.Request.Form["runCode"];

                var request = this.Bind <FileUploadRequest>();
                List <Assignment> assignments = uploadHandler.HandleGraderUpload(gradingDir, request.Files);

                Grader grader = new Grader(runMoss, runCode);

                return(grader.Grade(gradingDir + "canvas.csv", baseDir, assignments));
            };
            #endregion
        }