/// <summary> /// Loads Derived Custom Columns for a particular course /// </summary> /// <param name="courseId">The id of the course</param> /// <param name="table">The table to load the columns into</param> /// <returns>List<NumericDataColumn>: List of Derived columns in the Canvas gradebook</returns> public List <NumericDataColumn> GetDerivedColumns(int courseId, CourseDataTable table) { var derivedColumns = new List <NumericDataColumn>(); var custColsDb = _dbCtx.CustomDataColumns.Where(x => x.CourseId == courseId && x.ColumnType == ColumnType.Derived_Data).ToList(); foreach (var entry in custColsDb) { var newCol = new NumericDataColumn { Name = entry.Name, ColumnType = entry.ColumnType, RelatedDataId = entry.RelatedDataId, DataType = entry.DataType, CalcRule = entry.CalcRule, ColMaxValue = entry.ColMaxValue, ColMinValue = entry.ColMinValue, ColumnId = Guid.NewGuid(), Rows = new List <NumericDataRow>() }; var derivedColManager = new DerivedColumnManager(table); derivedColManager.LoadDerivedDataColumn(ref newCol); derivedColumns.Add(newCol); } return(derivedColumns); }
private void UpdateDiagram() { barchart.Size = size; List <string> days = new List <string>() { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" }; List <string> months = new List <string>() { "January", "February", "March", "April" }; DataSet dataSet = new DataSet(); List <string> xValues = new List <string>(); List <float> yValues = new List <float>(); List <string> zValues = new List <string>(); List <Color> colors = new List <Color>(); for (int i = 0; i < days.Count; i++) { for (int j = 0; j < months.Count; j++) { xValues.Add(days[i]); zValues.Add(months[j]); yValues.Add(Random.Range(0, 11)); colors.Add(Random.ColorHSV()); } } TextDataColumn xColumn = new TextDataColumn(xValues); NumericDataColumn yColumn = new NumericDataColumn(yValues); TextDataColumn zColumn = new TextDataColumn(zValues); dataSet.DataColumns.Add(xColumn); dataSet.DataColumns.Add(yColumn); dataSet.DataColumns.Add(zColumn); dataSet.DataPointColors = colors; barchart.DataSet = dataSet; barchart.UpdateDiagram(); }
/// <summary> /// Loads row data into a derived data column /// </summary> /// <param name="column">The dervied data column to load data into</param> public void LoadDerivedDataColumn(ref NumericDataColumn column) { var tableColumns = new List <NumericDataColumn>(); foreach (var col in _courseTable.AssignmentGradeColumns) { tableColumns.Add((NumericDataColumn)col); } foreach (var col in _courseTable.CustomDataColumns) { // Keep in mind that derived columns cannot derive data from other derived columns if (col.DataType == ColumnDataType.Number && !col.Name.Equals(column) && col.ColumnType != ColumnType.Derived_Data) { tableColumns.Add((NumericDataColumn)col); } } foreach (var student in _courseTable.Students) { var row = new NumericDataRow { ColumnId = column.ColumnId, ValueChanged = false, AssociatedUser = student, }; var expression = new Expression(column.CalcRule); foreach (var col in tableColumns) { expression.Parameters[col.Name] = ((NumericDataColumn)_courseTable[col.Name])[student.Id]; } try { row.Value = (double)expression.Evaluate(); } catch (Exception) { row.Value = 0; } column.Rows.Add(row); } }
/// <summary> /// Converts punch card data from GitHub to a generic data set which can be inserted into diagrams /// </summary> /// <returns>The async task which returns the data set containing the GitHub punch card data</returns> private async Task <DataSet> GitHubPunchCardToDataSet() { ApiResult <PunchCardEntry[]> res = await GitHub.GetGitHubPunchCard(Owner, Repository); if (res.HasError) { return(null); } DataSet dataset = new DataSet(); List <string> weekDayAxis = new List <string>(); List <float> hourAxis = new List <float>(); List <float> amountAxis = new List <float>(); List <Color> colors = new List <Color>(); for (int i = 0; i < res.Value.Length; i++) { weekDayAxis.Add(res.Value[i].DayOfWeek.ToString()); hourAxis.Add(res.Value[i].hour); amountAxis.Add(res.Value[i].numberOfCommits); colors.Add(UnityEngine.Random.ColorHSV()); } TextDataColumn weekDayColumn = new TextDataColumn(weekDayAxis); weekDayColumn.Title = "Weekday"; dataset.DataColumns.Add(weekDayColumn); NumericDataColumn amountColumn = new NumericDataColumn(amountAxis); amountColumn.Title = "Commits"; dataset.DataColumns.Add(amountColumn); NumericDataColumn hourColumn = new NumericDataColumn(hourAxis); hourColumn.Title = "Hour"; dataset.DataColumns.Add(hourColumn); dataset.DataPointColors = colors; return(dataset); }
public static NewColumnRequest GetRequestFromDynamicObject(dynamic request) { var newRequest = new NewColumnRequest(); if (request.newColumn.dataType == ColumnDataType.Number) { var newCol = new NumericDataColumn { Name = request.newColumn.name, ColumnId = request.newColumn.columnId, ColumnType = request.newColumn.columnType, DataType = request.newColumn.dataType, RelatedDataId = request.newColumn.relatedDataId, CalcRule = request.newColumn.calcRule, ColMaxValue = request.newColumn.colMaxValue, ColMinValue = request.newColumn.colMinValue, Rows = new List <NumericDataRow>() }; newRequest.NewColumn = newCol; } else { var newCol = new StringDataColumn { Name = request.newColumn.name, ColumnId = request.newColumn.columnId, ColumnType = request.newColumn.columnType, DataType = request.newColumn.dataType, RelatedDataId = request.newColumn.relatedDataId, CalcRule = request.newColumn.calcRule, ColMaxValue = request.newColumn.colMaxValue, ColMinValue = request.newColumn.colMinValue, Rows = new List <StringDataRow>() }; newRequest.NewColumn = newCol; } return(newRequest); }
/// <summary> /// Returns the list of custom data columns related with the Canvas Gradebook of a particular course /// </summary> /// <param name="accessToken">The Canvas Personal Access Token being used</param> /// <param name="courseId">The id of the course</param> /// <returns>List<CourseDataColumn>: Custom Columns of Canvas Gradebook</returns> public List <CourseDataColumn> GetCustomDataColumns(string accessToken, int courseId) { var custDataColumns = new List <CourseDataColumn>(); var canvasCustCols = _canvasDataAccess.GetCustomColumns(accessToken, courseId); var custColsDb = _dbCtx.CustomDataColumns.Where(x => x.CourseId == courseId).ToList(); foreach (var canvasCol in canvasCustCols) { var currDbCol = custColsDb.Where(x => x.RelatedDataId == canvasCol.Id).FirstOrDefault(); if (currDbCol != null) { // The derived data columns should be loaded last since they derive data from other columns // (hence it being called a "Dervied" column) if (currDbCol.ColumnType != ColumnType.Derived_Data) { CourseDataColumn newKnownCol; if (currDbCol.DataType == ColumnDataType.Number) { newKnownCol = new NumericDataColumn { Name = canvasCol.Title, DataType = currDbCol.DataType, ColumnType = currDbCol.ColumnType, RelatedDataId = canvasCol.Id, CalcRule = currDbCol.CalcRule, ColMaxValue = currDbCol.ColMaxValue, ColMinValue = currDbCol.ColMinValue, ColumnId = Guid.NewGuid() }; ((NumericDataColumn)newKnownCol).Rows = GetCustomDataRowsForNumberColumns(accessToken, courseId, newKnownCol); } else { newKnownCol = new StringDataColumn { Name = canvasCol.Title, DataType = currDbCol.DataType, ColumnType = currDbCol.ColumnType, RelatedDataId = canvasCol.Id, CalcRule = currDbCol.CalcRule, ColMaxValue = currDbCol.ColMaxValue, ColMinValue = currDbCol.ColMinValue, ColumnId = Guid.NewGuid() }; ((StringDataColumn)newKnownCol).Rows = GetCustomDataFromStringColumns(accessToken, courseId, newKnownCol); } custDataColumns.Add(newKnownCol); } } else { var newCol = new CourseDataColumn { Name = canvasCol.Title, RelatedDataId = canvasCol.Id, ColumnType = ColumnType.Custom_Canvas_Column, }; var newColRows = GetCustomColumnDataRowsForUnknownTypes(accessToken, courseId, newCol); newCol.DataType = GetColumnDataType(newColRows[0].Value); if (newColRows != null) { if (newColRows.Count > 0) { } } if (newCol.DataType == ColumnDataType.Number) { var numCol = (NumericDataColumn)newCol; numCol.Rows = new List <NumericDataRow>(); foreach (var row in newColRows) { numCol.Rows.Add(new NumericDataRow { ColumnId = Guid.NewGuid(), AssociatedUser = row.AssociatedUser, Value = double.Parse(row.Value), ValueChanged = false }); } custDataColumns.Add(numCol); } else { var strCol = (StringDataColumn)newCol; strCol.Rows = newColRows; custDataColumns.Add(strCol); } } } return(custDataColumns); }