public XElement ComputeFeedbackXML(XElement dfaCorrectDesc, XElement dfaAttemptDesc, XElement maxGrade, XElement feedbackLevel, XElement enabledFeedbacks) { #region Check if item is in cache StringBuilder key = new StringBuilder(); key.Append("feed"); key.Append(dfaCorrectDesc.ToString()); key.Append(dfaAttemptDesc.ToString()); key.Append(feedbackLevel.ToString()); key.Append(enabledFeedbacks.ToString()); string keystr = key.ToString(); var cachedValue = HttpContext.Current.Cache.Get(key.ToString()); if (cachedValue != null) { HttpContext.Current.Cache.Remove(keystr); HttpContext.Current.Cache.Add(keystr, cachedValue, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(30), System.Web.Caching.CacheItemPriority.Normal, null); return((XElement)cachedValue); } #endregion CharSetSolver solver = new CharSetSolver(BitWidth.BV64); //Read input var dfaCorrectPair = DFAUtilities.parseDFAFromXML(dfaCorrectDesc, solver); var dfaAttemptPair = DFAUtilities.parseDFAFromXML(dfaAttemptDesc, solver); var level = (FeedbackLevel)Enum.Parse(typeof(FeedbackLevel), feedbackLevel.Value, true); var enabList = (enabledFeedbacks.Value).Split(',').ToList <String>(); //bool dfaedit = enabList.Contains("dfaedit"), moseledit = enabList.Contains("moseledit"), density = enabList.Contains("density"); bool dfaedit = true, moseledit = true, density = true; var maxG = int.Parse(maxGrade.Value); //Compute feedback var feedbackGrade = DFAGrading.GetGrade(dfaCorrectPair.Second, dfaAttemptPair.Second, dfaCorrectPair.First, solver, 1500, maxG, level, dfaedit, density, moseledit); //Pretty print feedback var feedString = "<ul>"; foreach (var feed in feedbackGrade.Second) { feedString += string.Format("<li>{0}</li>", feed); break; } feedString += "</ul>"; //var output = string.Format("<result><grade>{0}</grade><feedString>{1}</feedString></result>", feedbackGrade.First, feedString); var outXML = new XElement("result", new XElement("grade", feedbackGrade.First), new XElement("feedString", XElement.Parse(feedString))); //XElement outXML = XElement.Parse(output); //Add this element to chace and return it HttpContext.Current.Cache.Add(key.ToString(), outXML, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(30), System.Web.Caching.CacheItemPriority.Normal, null); return(outXML); }
public XElement ComputeFeedbackNfaToDfa(XElement nfaCorrectDesc, XElement dfaAttemptDesc, XElement maxGrade) { #region Check if item is in cache StringBuilder key = new StringBuilder(); key.Append("feedNFADFA"); key.Append(nfaCorrectDesc.ToString()); key.Append(dfaAttemptDesc.ToString()); string keystr = key.ToString(); var cachedValue = HttpContext.Current.Cache.Get(key.ToString()); if (cachedValue != null) { HttpContext.Current.Cache.Remove(keystr); HttpContext.Current.Cache.Add(keystr, cachedValue, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(30), System.Web.Caching.CacheItemPriority.Normal, null); return((XElement)cachedValue); } #endregion CharSetSolver solver = new CharSetSolver(BitWidth.BV64); //Read input var nfaCorrectPair = DFAUtilities.parseNFAFromXML(nfaCorrectDesc, solver); var dfaCorrect = nfaCorrectPair.Second.RemoveEpsilons(solver.MkOr).Determinize(solver).Minimize(solver); var dfaAttemptPair = DFAUtilities.parseDFAFromXML(dfaAttemptDesc, solver); var level = FeedbackLevel.Hint; var maxG = int.Parse(maxGrade.Value); //Compute feedback var feedbackGrade = DFAGrading.GetGrade(dfaCorrect, dfaAttemptPair.Second, nfaCorrectPair.First, solver, 1500, maxG, level); //Pretty print feedback var feedString = "<ul>"; foreach (var feed in feedbackGrade.Second) { feedString += string.Format("<li>{0}</li>", feed); } feedString += "</ul>"; var output = string.Format("<div><grade>{0}</grade><feedString>{1}</feedString></div>", feedbackGrade.First, feedString); XElement outXML = XElement.Parse(output); //Add this element to chace and return it HttpContext.Current.Cache.Add(key.ToString(), outXML, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(30), System.Web.Caching.CacheItemPriority.Normal, null); return(outXML); }
public void DileepTest3() { //XElement dfaCorrectDesc = XElement.Parse("<automaton xmlns=\"http://automatagrader.com/\"> <alphabet type=\"basic\"> <symbol>a</symbol><symbol>b</symbol> </alphabet> <stateSet> <state sid=\"0\"><label>0</label></state><state sid=\"1\"><label>1</label></state> </stateSet> <transitionSet> <transition tid=\"0\"> <from>0</from> <to>0</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"1\"> <from>0</from> <to>1</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"2\"> <from>1</from> <to>1</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"3\"> <from>1</from> <to>0</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition> </transitionSet> <acceptingSet> <state sid=\"1\"></state> </acceptingSet> <initState> <state sid=\"0\"></state> </initState> </automaton>"); XElement dfaCorrectDesc = XElement.Parse("<automaton xmlns=\"http://automatagrader.com/\"> <alphabet type=\"basic\"> <symbol>a</symbol><symbol>b</symbol> </alphabet> <stateSet> <state sid=\"0\"><label>0</label></state><state sid=\"1\"><label>1</label></state><state sid=\"2\"><label>2</label></state><state sid=\"3\"><label>3</label></state><state sid=\"4\"><label>4</label></state><state sid=\"5\"><label>5</label></state><state sid=\"6\"><label>6</label></state> </stateSet> <transitionSet> <transition tid=\"0\"> <from>0</from> <to>0</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"1\"> <from>0</from> <to>1</to> <read>a</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"2\"> <from>1</from> <to>1</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"3\"> <from>1</from> <to>2</to> <read>b</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"4\"> <from>2</from> <to>2</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"5\"> <from>2</from> <to>3</to> <read>a</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"6\"> <from>3</from> <to>3</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"7\"> <from>3</from> <to>4</to> <read>b</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"8\"> <from>4</from> <to>4</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"9\"> <from>4</from> <to>5</to> <read>a</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"10\"> <from>5</from> <to>5</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"11\"> <from>5</from> <to>6</to> <read>b</read> <edgeDistance>0</edgeDistance> </transition><transition tid=\"12\"> <from>6</from> <to>6</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"13\"> <from>6</from> <to>6</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition> </transitionSet> <acceptingSet> <state sid=\"4\"></state><state sid=\"5\"></state> </acceptingSet> <initState> <state sid=\"0\"></state> </initState> </automaton>"); XElement dfaAttemptDesc = XElement.Parse("<automaton xmlns=\"http://automatagrader.com/\"> <alphabet type=\"basic\"> <symbol>a</symbol><symbol>b</symbol> </alphabet> <stateSet> <state sid=\"0\"><label>0</label></state> </stateSet> <transitionSet> <transition tid=\"0\"> <from>0</from> <to>0</to> <read>a</read> <edgeDistance>30</edgeDistance> </transition><transition tid=\"1\"> <from>0</from> <to>0</to> <read>b</read> <edgeDistance>30</edgeDistance> </transition> </transitionSet> <acceptingSet> </acceptingSet> <initState> <state sid=\"0\"></state> </initState> </automaton>"); XElement feedbackLevel = XElement.Parse("<level xmlns=\"http://automatagrader.com/\">smallhint</level>"); XElement enabledFeedbacks = XElement.Parse("<metrics xmlns=\"http://automatagrader.com/\">dfaedit,moseledit,density</metrics>"); CharSetSolver solver = new CharSetSolver(BitWidth.BV64); //XElement dfaAttemptDesc = dfaAttemptHint.Element("Automaton"); //FeedbackLevel level = (FeedbackLevel)Convert.ToInt32(dfaAttemptHint.Element("FeedbackLevel").Value); var dfaCorrectPair = DFAUtilities.parseDFAFromXML(dfaCorrectDesc, solver); Console.WriteLine(feedbackLevel); Console.WriteLine(enabledFeedbacks); var dfaAttemptPair = DFAUtilities.parseDFAFromXML(dfaAttemptDesc, solver); //var sb = new StringBuilder(); var level = (FeedbackLevel)Enum.Parse(typeof(FeedbackLevel), feedbackLevel.Value, true); var enabList = (enabledFeedbacks.Value).Split(',').ToList <String>(); bool dfaedit = enabList.Contains("dfaedit"), moseledit = enabList.Contains("moseledit"), density = enabList.Contains("density"); var feedbackGrade = DFAGrading.GetGrade(dfaCorrectPair.Second, dfaAttemptPair.Second, dfaCorrectPair.First, solver, 2000, 10, level, dfaedit, moseledit, density); var feedString = "<ul>"; foreach (var feed in feedbackGrade.Second) { feedString += string.Format("<li>{0}</li>", feed); } feedString += "</ul>"; Console.WriteLine(string.Format("<div>Grade: {0} <br /> Feedback: {1}</div>", feedbackGrade.First, feedString)); }