public IHttpActionResult PutCluster(int id, Cluster cluster) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != cluster.Id) { return(BadRequest()); } db.Entry(cluster).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ClusterExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
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); }
public IHttpActionResult FindClustersByTransformation() { db.Clusters.RemoveRange(db.Clusters); RefazerOnline refazerOnline = RefazerOnline.Instance; Dictionary <String, List <Example> > allExamples = GetExamplesByKeyPoint(); foreach (var keypoint in allExamples.Keys) { List <Models.Cluster> clustersList = refazerOnline. LearnClusteredTransformations(keypoint, allExamples[keypoint]); db.Clusters.AddRange(clustersList); } db.SaveChanges(); return(Ok("Refazer is ready!")); }
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); } }
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 })); }