Beispiel #1
0
        public IEnumerable <Fix> GetFixes(int SessionId, int FixId)
        {
            Trace.TraceWarning("GetFixes request accepted for session: {0} on Instance: {1}", SessionId,
                               "");
            var refazerDb2 = new RefazerDbContext();

            return(refazerDb2.Fixes.Include("Transformation").Where(x => x.SessionId == SessionId && x.ID >= FixId));
        }
Beispiel #2
0
 private static void FixSubmission(Tuple <ProgramNode, Models.Transformation> transformationTuple, int experiementId, int questionId,
                                   Tuple <Submission, State> submission)
 {
     try
     {
         if (!submission.Item1.IsFixed)
         {
             var manager = new TestManager();
             var mistake = new Mistake();
             mistake.before = submission.Item1.Code;
             var fixer     = new SubmissionFixer();
             var unparser  = new Unparser();
             var fixedCode = fixer.TryFix(manager.GetTests(questionId), transformationTuple.Item1, submission.Item2, unparser);
             if (fixedCode != null)
             {
                 var refazerDb2 = new RefazerDbContext();
                 submission.Item1.IsFixed = true;
                 var updatedSub = refazerDb2.Submissions.SingleOrDefault(e => e.ID == submission.Item1.ID);
                 if (updatedSub != null)
                 {
                     updatedSub.IsFixed = true;
                 }
                 var trans = refazerDb2.Transformations.First(x => x.ID == transformationTuple.Item2.ID);
                 var fix   = new Fix()
                 {
                     FixedCode      = fixedCode,
                     SessionId      = experiementId,
                     SubmissionId   = submission.Item1.SubmissionId,
                     QuestionId     = questionId,
                     Transformation = trans
                 };
                 refazerDb2.Fixes.Add(fix);
                 refazerDb2.SaveChanges();
                 Trace.TraceWarning(string.Format("Submission fixed: {0}, Session: {1}, Transformation: {2}, Time: {3}",
                                                  submission.Item1.SubmissionId, transformationTuple.Item2.SessionId, transformationTuple.Item2.ID, DateTime.Now));
             }
         }
     }
     catch (Exception e)
     {
         Trace.TraceError("Exception was thrown when applying fixes.");
         Trace.TraceError(e.Message);
     }
 }
Beispiel #3
0
        public int Start(StartInput startInput)
        {
            var refazerDb = new RefazerDbContext();
            //First, create an experiment for this grading section
            var session = new Session();

            refazerDb.Sessions.Add(session);
            refazerDb.SaveChanges();

            //associate the submissions to this experiment and save
            startInput.Submissions.ForEach(s => s.SessionId = session.ID);
            foreach (var submission in startInput.Submissions)
            {
                refazerDb.Submissions.Add(submission);
            }
            refazerDb.SaveChanges();

            return(session.ID);
        }
Beispiel #4
0
        public dynamic ApplyFixFromExample(ApplyFixFromExampleInput exampleInput)
        {
            Trace.TraceWarning("ApplyFixFromExample request accepted for submission: {0} on Instance: {1}. Total jobs in this instance: {2}",
                               exampleInput.SubmissionId, "", ++numberOfJobs);
            var exceptions = new List <string>();

            try
            {
                var refazer         = BuildRefazer();
                var example         = Tuple.Create(exampleInput.CodeBefore, exampleInput.CodeAfter);
                var transformations = refazer.LearnTransformations(new List <Tuple <string, string> >()
                {
                    example
                },
                                                                   exampleInput.SynthesizedTransformations, exampleInput.Ranking);

                var refazerDb          = new RefazerDbContext();
                var newTransformations = FilterExistingTransformations(
                    transformations.Select(e => e.GetSynthesizedProgram()),
                    refazerDb.Transformations.Where(x => x.SessionId == exampleInput.SessionId));
                var transformationTuples = new List <Tuple <ProgramNode, Models.Transformation> >();

                var rank = 1;
                foreach (var programNode in newTransformations)
                {
                    var transformation = new Models.Transformation()
                    {
                        SessionId = exampleInput.SessionId,
                        Program   = programNode.ToString(),
                        Rank      = rank++,
                        RankType  = (exampleInput.Ranking.Equals("specific")) ? 1 : 2,
                        Examples  = "[{'submission_id': " + exampleInput.SubmissionId
                                    + ", 'code_before': " + exampleInput.CodeBefore
                                    + ", 'fixed_code': " + exampleInput.CodeAfter + "}]"
                    };
                    refazerDb.Transformations.Add(transformation);
                    transformationTuples.Add(Tuple.Create(programNode, transformation));
                }
                refazerDb.SaveChanges();
                transformationTuples.ForEach(e => Trace.TraceWarning(string.Format("Transformation created: {0}", e.Item2.ID)));

                var submissions = refazerDb.Submissions.Where(s => s.SessionId == exampleInput.SessionId).ToList();

                var submissionTuples = new List <Tuple <Submission, State> >();
                var exList           = new List <Exception>();
                foreach (var submission in submissions)
                {
                    try
                    {
                        var tuple = Tuple.Create(submission, refazer.CreateInputState(submission.Code));
                        submissionTuples.Add(tuple);
                    }
                    catch (Exception e)
                    {
                        exList.Add(e);
                    }
                }
                if (exList.Any())
                {
                    Trace.TraceError("Total of submissions that could not be parsed: {0}", exList.Count);
                }

                if (transformationTuples.Any())
                {
                    Task.Run(() => TryToFixAsync(transformationTuples, exampleInput.SessionId,
                                                 exampleInput.QuestionId, submissionTuples));
                }
            }
            catch (Exception e)
            {
                Trace.TraceError("Exception was throw");
                Trace.TraceWarning(e.StackTrace);
                Trace.TraceWarning(e.Message);
                exceptions.Add(e.Message);
            }
            return(Json(new { id = 0, exceptions }));
        }