private static void PopulateAssignmentRows(ref CourseDataTable table, string accessToken, int courseId) { var config = SystemConfig.LoadConfig(); var dataAccess = new CanvasDataAccess(config); foreach (var student in table.Students) { var data = dataAccess.GetAnalysisData(accessToken, courseId, student.Id); foreach (var col in table.AssignmentGradeColumns) { var colData = data.Where(x => x.AssignmentId == col.RelatedDataId).ToList(); foreach (var cdata in colData) { var row = new NumericDataRow { Value = (cdata.Submission.Score != null) ? (double)cdata.Submission.Score : 0, ColumnId = col.ColumnId, AssociatedUser = student, ValueChanged = false }; ((NumericDataColumn)col).Rows.Add(row); } } } }
/// <summary> /// Loads an instance of the Course Data Table from a dynamic JSON representation of the table /// </summary> /// <param name="table">The dynamic JSON representation of the table</param> /// <returns>CourseDataTable: A re-representation of the Canvas Gradebook for the purposes of this system</returns> public static CourseDataTable LoadDataTableFromDynamicObject(dynamic table) { var newTable = new CourseDataTable { CourseId = table.courseId, AssignmentGradeColumns = new List <CourseDataColumn>(), CustomDataColumns = new List <CourseDataColumn>(), Students = new List <DataTableStudent>() }; foreach (var col in table.assignmentGradeColumns) { var newCol = new NumericDataColumn { Name = col.name, DataType = col.dataType, ColumnId = col.columnId, ColumnType = col.columnType, CalcRule = col.calcRule, RelatedDataId = col.relatedDataId, ColMaxValue = col.colMaxValue, ColMinValue = col.colMinValue, Rows = new List <NumericDataRow>() }; foreach (var row in col.rows) { var newRow = new NumericDataRow { ColumnId = row.columnId, AssociatedUser = new DataTableStudent { Id = row.associatedUser.id, Name = row.associatedUser.name }, ValueChanged = row.valueChanged, Value = row.value, NewValue = row.newValue }; newCol.Rows.Add(newRow); } newTable.AssignmentGradeColumns.Add(newCol); } foreach (var col in table.customDataColumns) { if (col.dataType == ColumnDataType.Number) { var newCol = new NumericDataColumn { Name = col.name, DataType = col.dataType, ColumnId = col.columnId, ColumnType = col.columnType, CalcRule = col.calcRule, RelatedDataId = col.relatedDataId, ColMaxValue = col.colMaxValue, ColMinValue = col.colMinValue, Rows = new List <NumericDataRow>() }; foreach (var row in col.rows) { var newRow = new NumericDataRow { ColumnId = row.columnId, AssociatedUser = new DataTableStudent { Id = row.associatedUser.id, Name = row.associatedUser.name }, ValueChanged = row.valueChanged, Value = row.value, NewValue = row.newValue }; newCol.Rows.Add(newRow); } newTable.AssignmentGradeColumns.Add(newCol); } else { var newCol = new StringDataColumn { Name = col.name, DataType = col.dataType, ColumnId = col.columnId, ColumnType = col.columnType, CalcRule = col.calcRule, RelatedDataId = col.relatedDataId, ColMaxValue = col.colMaxValue, ColMinValue = col.colMinValue, Rows = new List <StringDataRow>() }; foreach (var row in col.rows) { var newRow = new StringDataRow { ColumnId = row.columnId, AssociatedUser = new DataTableStudent { Id = row.associatedUser.id, Name = row.associatedUser.name }, ValueChanged = row.valueChanged, Value = row.value, NewValue = row.newValue }; newCol.Rows.Add(newRow); } newTable.AssignmentGradeColumns.Add(newCol); } } foreach (var student in table.students) { newTable.Students.Add(new DataTableStudent { Id = student.id, Name = student.name }); } return(newTable); }