async public static Task <AbstractMark[]> GetGroupMarks(Group group) { HttpResponseMessage response = await WebRequestHandler.GET(markRoute + "/" + "?group=" + group.id.ToString()); AbstractMark[] marks = AbstractMark.CreateFromJsonString(await response.Content.ReadAsStringAsync()); return(marks); }
public static Color ScoreGrade(AbstractMark mark, int maxScore, Student student) { /// <summary> /// Returns a cell colour for a `mark`. The ALPS grade of `student` is used. /// </summary> // Get prerequesites float percentage = (float)mark.GetScore() / (float)maxScore; // Convert to floats to avoid integer division - https://stackoverflow.com/questions/37641472/how-do-i-calculate-a-percentage-of-a-number-in-c float adjustedAlps = (float)student.alps / 100f; float diff = adjustedAlps - percentage; if (diff > 0.4) { return(Color.Red); } else if (diff > 0.25) { return(Color.Orange); } else { return(Color.Green); } }
private void CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (!this.dataGridInitialised || e.ColumnIndex <= -1 || e.RowIndex <= -1) { return; } DataGridViewCell cell = dataGrid[e.ColumnIndex, e.RowIndex]; AbstractMark mark = this.markGrid[e.ColumnIndex, e.RowIndex]; Assignment task = this.taskIdToTask[mark.GetTaskId()]; Student student = this.studentIdToStudent[mark.GetStudentId()]; string newValue = cell.EditedFormattedValue.ToString(); int newScore = 0; bool isDigit = Int32.TryParse(newValue, out newScore); if (!isDigit || newScore < 0 || newScore > task.maxScore) { return; } // Changed mark from N/A if (mark.GetFeedback() == null) { mark.UpdateFeedback("No feedback given."); // NO API CALLS MADE IN THIS METHOD } mark.UpdateScore(newScore); // NO API CALLS MADE IN THIS METHOD this.markGrid[e.ColumnIndex, e.RowIndex] = mark; // Update cell data cell.Style.BackColor = ScoreGrade(mark, task.maxScore, student); APIHandler.GiveFeedback(student, task, newScore, mark.GetFeedback()); }
private void CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e) { if (e.RowIndex <= -1 || e.ColumnIndex <= -1) { return; } AbstractMark mark = this.markGrid[e.ColumnIndex, e.RowIndex]; if (mark != null) { Assignment assignment = taskIdToTask[mark.GetTaskId()]; Student student = studentIdToStudent[mark.GetStudentId()]; e.ToolTipText = "Score: " + mark.GetScore().ToString() + "\nOut of: " + assignment.maxScore + "\nALPs grade: " + student.GetAlpsString() + "\nFeedback provided: " + mark.GetFeedback(); } else { e.ToolTipText = "Feedback not yet provided"; } }
public static AbstractMark[] CreateFromJsonString(string json) { dynamic jsonObj = JsonConvert.DeserializeObject(json); AbstractMark[] marks = new AbstractMark[jsonObj.data.Count]; // The provided JSON may be an array of marks for (int i = 0; i < jsonObj.data.Count; i++) { dynamic markObj = jsonObj.data[i]; // Get the mark bool hasMarked = markObj.has_marked; string feedback = markObj.feedback; int score = markObj.score; int studentId = markObj.student.reference.id; int taskId = markObj.task.reference.id; marks[i] = new AbstractMark(studentId, taskId, feedback, score, hasMarked); } return(marks); }
private void CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) { if (e.RowIndex <= -1 || e.ColumnIndex <= -1) { return; } AbstractMark mark = this.markGrid[e.ColumnIndex, e.RowIndex]; DataGridViewCell cell = dataGrid[e.ColumnIndex, e.RowIndex]; if (mark.HasMarked()) { e.Value = mark.GetScoreString(); int maxScore = this.taskIdToTask[mark.GetTaskId()].maxScore; Student student = this.studentIdToStudent[mark.GetStudentId()]; cell.Style.BackColor = ScoreGrade(mark, maxScore, student); } else { cell.Style.BackColor = Color.Gray; e.Value = "N/A"; } }