public static string AddAssignment(String ListConstraints, String ListQuestions) { //create a String array of the answers submitted from the user page //splits by space string[] lines = ListConstraints.Split('|'); string[] questions = ListQuestions.Split('|'); //create instance of AssignComponent through which to assign the assignment AssignComponent.Assigner entry = new AssignComponent.Assigner(); //fetch our assignment parameters to pass with our array of questions strings String title = lines[0]; String dueDate = lines[1]; //pass fetched parameters to instance of AssignComponent, return string indicating //success of assignment creation return entry.Assign(title, dueDate, questions); }
public static string AddAssignment(String ListConstraints, String ListQuestions) { //create a String array of the answers submitted from the user page //splits by space string[] lines = ListConstraints.Split('|'); string[] questions = ListQuestions.Split('|'); //create instance of AssignComponent through which to assign the assignment AssignComponent.Assigner entry = new AssignComponent.Assigner(); //fetch our assignment parameters to pass with our array of questions strings String title = lines[0]; String dueDate = lines[1]; //pass fetched parameters to instance of AssignComponent, return string indicating //success of assignment creation return(entry.Assign(title, dueDate, questions)); }
public static string Grade(String MatrixMapJSON, String AnswerJSON, String question, String assignment) { //initialize floats for total point value and their grade so far on assignment float questionValue = 0; float currentGrade = 0; //Get session variables float[,] sessionMatrix = (float[,]) HttpContext.Current.Session["matrix"]; float[] sessionActualAnswer = (float[]) HttpContext.Current.Session["actualAnswer"]; //int sessionMinNumOfRowsOps = (int) HttpContext.Current.Session["minNumOfRowOps"]; Boolean sessionInconsistent = (Boolean) HttpContext.Current.Session["inconsistent"]; int sessionNumOfFreeVars = (int) HttpContext.Current.Session["numOfFreeVars"]; String assignId = (String) HttpContext.Current.Session["assignment"]; string feedback = ""; //first we need to check if the homework assignment is in the database AssignComponent.Assigner check = new AssignComponent.Assigner(); int theresanassignment = check.checkAssignmentExists(assignId); if (theresanassignment==1) { //query to fetch question's point value and their current grade on the assignment string connStr = ConfigurationManager.ConnectionStrings["linearhmwkdb"].ConnectionString; MySqlConnection msqcon = new MySqlConnection(connStr); try { msqcon.Open(); String query = "SELECT q.pointValue, ha.grade FROM question AS q JOIN hmwkassignment AS ha WHERE ha.homeworkId=q.homeworkId AND ha.assignmentId = " + assignment + " AND q.number = " + question; MySqlCommand msqcmd = new MySqlCommand(query, msqcon); MySqlDataReader points = msqcmd.ExecuteReader(); points.Read(); questionValue = points.GetFloat(0); currentGrade = points.GetFloat(1); points.Close(); } catch (Exception) { throw; } Dictionary<int, float[,]> MatrixMap = JsonConvert.DeserializeObject<Dictionary<int, float[,]>>(MatrixMapJSON); MatrixBuilder.MatrixOperations mb = new MatrixBuilder.MatrixOperations(); //get the amount to deduct by dividing the total points by our approximate number of steps to solve (+1 for first matrix) (+1 for copying the answer correctly) //shifted then rounded to keep it to 2 decimal points, then shifted back float deductValue = (float)Math.Round((questionValue / ((float)mb.countOperationsNeeded(sessionMatrix) + 2F)) * 100F) / 100F; //if above gives a value of 0 (a rediculously large number of steps), correct to .01 so points are actually deducted if (deductValue == 0) deductValue = .01F; //should probably check if the first matrix is the actual first matrix float[,] augMatrix = null; MatrixMap.TryGetValue(0, out augMatrix); //Not sure if this if works if (!mb.checkMatrixEquality(sessionMatrix, augMatrix)) { feedback += "<div>The first matrix does not match the augmented matrix.<div>"; } if (AnswerJSON.Contains("I")) { feedback += mb.checkSingleRowOperation(MatrixMap); if (!sessionInconsistent) { feedback += "<div>The matrix is actually consistent.<div>"; } } else if (AnswerJSON.Contains("F")) { feedback += mb.checkSingleRowOperation(MatrixMap); if (sessionNumOfFreeVars > 0) { Dictionary<int, String> AnswersConverted = JsonConvert.DeserializeObject<Dictionary<int, String>>(AnswerJSON); String[] Answers = new String[AnswersConverted.Count()]; AnswersConverted.Values.CopyTo(Answers, 0); feedback += mb.checkFreeVariableAnswers(sessionMatrix, Answers); } else { feedback += "<div>The solution actually contains no free variables.<div>"; } } else { Dictionary<int, float> AnswersConverted = JsonConvert.DeserializeObject<Dictionary<int, float>>(AnswerJSON); float[] Answers = new float[AnswersConverted.Count()]; AnswersConverted.Values.CopyTo(Answers, 0); feedback += mb.checkSingleRowOperation(MatrixMap); //Will need to also check answers here feedback += mb.checkAnswers(sessionActualAnswer, Answers); } float grade = questionValue; //ensure there was feedback, if not, will retain value of the question's total points if (!feedback.Equals("")) { //Run through feedback, create array of statements based on . to count number of point deductions String[] deductionStrings = feedback.Split('.'); //set grade to the total minus the deduct amount times number of mistakes grade = questionValue - deductValue * (deductionStrings.Length - 1); //correct any odd values from results close to 0 by re-rounding to 2 decimal points grade = (float)Math.Round(grade * 100F) / 100F; } //make their grade go no lower than 0 (no negative points) if (grade < 0) grade = 0; //create grade to write back to database float updatedGrade = grade + currentGrade; //Need to display points somehow if (grade == 1) { feedback += "<!-- -->"; } feedback += "<div><strong>Points Earned: </strong>" + grade + " / " + questionValue + "</div>"; //Update grade in database msqcon = new MySqlConnection(connStr); try { msqcon.Open(); String query = "UPDATE hmwkassignment AS ha SET ha.grade = " + updatedGrade + " WHERE assignmentId = " + assignment; MySqlCommand msqcmd = new MySqlCommand(query, msqcon); msqcmd.ExecuteNonQuery(); } catch (Exception) { throw; } } else if (theresanassignment == 0) { feedback += "<-!- -->"; } return String.IsNullOrEmpty(feedback) ? null : feedback; }
public static string Grade(String MatrixMapJSON, String AnswerJSON, String question, String assignment) { //initialize floats for total point value and their grade so far on assignment float questionValue = 0; float currentGrade = 0; //Get session variables float[,] sessionMatrix = (float[, ])HttpContext.Current.Session["matrix"]; float[] sessionActualAnswer = (float[])HttpContext.Current.Session["actualAnswer"]; //int sessionMinNumOfRowsOps = (int) HttpContext.Current.Session["minNumOfRowOps"]; Boolean sessionInconsistent = (Boolean)HttpContext.Current.Session["inconsistent"]; int sessionNumOfFreeVars = (int)HttpContext.Current.Session["numOfFreeVars"]; String assignId = (String)HttpContext.Current.Session["assignment"]; string feedback = ""; //first we need to check if the homework assignment is in the database AssignComponent.Assigner check = new AssignComponent.Assigner(); int theresanassignment = check.checkAssignmentExists(assignId); if (theresanassignment == 1) { //query to fetch question's point value and their current grade on the assignment string connStr = ConfigurationManager.ConnectionStrings["linearhmwkdb"].ConnectionString; MySqlConnection msqcon = new MySqlConnection(connStr); try { msqcon.Open(); String query = "SELECT q.pointValue, ha.grade FROM question AS q JOIN hmwkassignment AS ha WHERE ha.homeworkId=q.homeworkId AND ha.assignmentId = " + assignment + " AND q.number = " + question; MySqlCommand msqcmd = new MySqlCommand(query, msqcon); MySqlDataReader points = msqcmd.ExecuteReader(); points.Read(); questionValue = points.GetFloat(0); currentGrade = points.GetFloat(1); points.Close(); } catch (Exception) { throw; } Dictionary <int, float[, ]> MatrixMap = JsonConvert.DeserializeObject <Dictionary <int, float[, ]> >(MatrixMapJSON); MatrixBuilder.MatrixOperations mb = new MatrixBuilder.MatrixOperations(); //get the amount to deduct by dividing the total points by our approximate number of steps to solve (+1 for first matrix) (+1 for copying the answer correctly) //shifted then rounded to keep it to 2 decimal points, then shifted back float deductValue = (float)Math.Round((questionValue / ((float)mb.countOperationsNeeded(sessionMatrix) + 2F)) * 100F) / 100F; //if above gives a value of 0 (a rediculously large number of steps), correct to .01 so points are actually deducted if (deductValue == 0) { deductValue = .01F; } //should probably check if the first matrix is the actual first matrix float[,] augMatrix = null; MatrixMap.TryGetValue(0, out augMatrix); //Not sure if this if works if (!mb.checkMatrixEquality(sessionMatrix, augMatrix)) { feedback += "<div>The first matrix does not match the augmented matrix.<div>"; } if (AnswerJSON.Contains("I")) { feedback += mb.checkSingleRowOperation(MatrixMap); if (!sessionInconsistent) { feedback += "<div>The matrix is actually consistent.<div>"; } } else if (AnswerJSON.Contains("F")) { feedback += mb.checkSingleRowOperation(MatrixMap); if (sessionNumOfFreeVars > 0) { Dictionary <int, String> AnswersConverted = JsonConvert.DeserializeObject <Dictionary <int, String> >(AnswerJSON); String[] Answers = new String[AnswersConverted.Count()]; AnswersConverted.Values.CopyTo(Answers, 0); feedback += mb.checkFreeVariableAnswers(sessionMatrix, Answers); } else { feedback += "<div>The solution actually contains no free variables.<div>"; } } else { Dictionary <int, float> AnswersConverted = JsonConvert.DeserializeObject <Dictionary <int, float> >(AnswerJSON); float[] Answers = new float[AnswersConverted.Count()]; AnswersConverted.Values.CopyTo(Answers, 0); feedback += mb.checkSingleRowOperation(MatrixMap); //Will need to also check answers here feedback += mb.checkAnswers(sessionActualAnswer, Answers); } float grade = questionValue; //ensure there was feedback, if not, will retain value of the question's total points if (!feedback.Equals("")) { //Run through feedback, create array of statements based on . to count number of point deductions String[] deductionStrings = feedback.Split('.'); //set grade to the total minus the deduct amount times number of mistakes grade = questionValue - deductValue * (deductionStrings.Length - 1); //correct any odd values from results close to 0 by re-rounding to 2 decimal points grade = (float)Math.Round(grade * 100F) / 100F; } //make their grade go no lower than 0 (no negative points) if (grade < 0) { grade = 0; } //create grade to write back to database float updatedGrade = grade + currentGrade; //Need to display points somehow if (grade == 1) { feedback += "<!-- -->"; } feedback += "<div><strong>Points Earned: </strong>" + grade + " / " + questionValue + "</div>"; //Update grade in database msqcon = new MySqlConnection(connStr); try { msqcon.Open(); String query = "UPDATE hmwkassignment AS ha SET ha.grade = " + updatedGrade + " WHERE assignmentId = " + assignment; MySqlCommand msqcmd = new MySqlCommand(query, msqcon); msqcmd.ExecuteNonQuery(); } catch (Exception) { throw; } } else if (theresanassignment == 0) { feedback += "<-!- -->"; } return(String.IsNullOrEmpty(feedback) ? null : feedback); }