public async Task <MatrixDTO> GetRotatedMatrixAsync(MatrixDTO matrixDto) { var matrix = matrixDto.Matrix; for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = i; j < matrix.GetLength(1); j++) { if (i != j) { matrix[i, j] ^= matrix[j, i]; matrix[j, i] ^= matrix[i, j]; matrix[i, j] ^= matrix[j, i]; } } } for (int i = 0; i < (matrix.GetLength(0)) / 2; i++) { for (int j = 0; j < matrix.GetLength(1); j++) { matrix[j, i] ^= matrix[j, matrix.GetLength(0) - 1 - i]; matrix[j, matrix.GetLength(0) - 1 - i] ^= matrix[j, i]; matrix[j, i] ^= matrix[j, matrix.GetLength(0) - 1 - i]; } } return(await Task.FromResult(matrixDto)); }
public async Task <MatrixDTO> Rotate(MatrixDTO matrix) { var array = matrix.MatrixType; for (int i = 0; i < array.GetLength(0); i++) { for (int j = i; j < array.GetLength(1); j++) { if (i != j) { array[i, j] ^= array[j, i]; array[j, i] ^= array[i, j]; array[i, j] ^= array[j, i]; } } } for (int i = 0; i < (array.GetLength(0)) / 2; i++) { for (int j = 0; j < array.GetLength(1); j++) { array[j, i] ^= array[j, array.GetLength(0) - 1 - i]; array[j, array.GetLength(0) - 1 - i] ^= array[j, i]; array[j, i] ^= array[j, array.GetLength(0) - 1 - i]; } } return(await Task.FromResult(matrix)); }
public async Task GetRotateMatrix_GetResult() { var matrixDto = new MatrixDTO { Matrix = new int[, ] { { 2, 3, 4 }, { 59, 17, 45 }, { 25, 33, 42 } } }; Assert.AreEqual(matrixDto.Matrix[0, 0], 2); var result = await _matrixEngine.GetRotatedMatrixAsync(matrixDto); Assert.IsTrue(result.Matrix.Length > 0); Assert.AreNotEqual(matrixDto.Matrix[0, 0], 2); }
public async Task ExportMatrixToCsvAsync(MatrixDTO matrixDto) { int[,] matrix = matrixDto.Matrix; var contents = new List <string>(); for (int i = 0; i < matrix.GetLength(0); i++) { var line = new List <int>(); for (int j = 0; j < matrix.GetLength(1); j++) { line.Add(matrix[i, j]); } contents.Add(string.Join(',', line)); } await _csvEngine.WriteAsync("Matrix.csv", contents); }
public async Task ExportMatrix_GetResult() { var matrixDto = new MatrixDTO { Matrix = new int[, ] { { 2, 3, 4 }, { 59, 17, 45 }, { 25, 33, 42 } } }; Assert.AreEqual(matrixDto.Matrix[0, 0], 2); await _matrixEngine.ExportMatrixToCsvAsync(matrixDto); Assert.IsTrue(matrixDto.Matrix.Length > 0); Assert.AreEqual(matrixDto.Matrix[0, 0], 2); }
public async Task GetRotateMatrix() { var matrixDto = new MatrixDTO { MatrixType = new int[, ] { { 10, 15, 20 }, { 30, 50, 70 }, { 40, 65, 90 } } }; Assert.AreEqual(matrixDto.MatrixType[1, 1], 50); Assert.AreEqual(matrixDto.MatrixType[0, 0], 10); var result = await _matrixService.Rotate(matrixDto); Assert.IsTrue(result.MatrixType.Length > 0); Assert.AreEqual(matrixDto.MatrixType[1, 1], 50); Assert.AreNotEqual(matrixDto.MatrixType[0, 0], 10); Assert.AreEqual(matrixDto.MatrixType[0, 0], 40); Assert.AreEqual(matrixDto.MatrixType[2, 1], 70); }
private static void FillMatrixRows(MatrixDTO grouped, FilterTransactionReport filter, int countTrans) { //firs create cols // CreateMatrixColumns(filter, grouped.Columns); CreatePage(filter, countTrans, grouped.Columns); bool lastElement = false; for (int i = 0; i < grouped.Rows.Count; i++) { if ((grouped.Rows.Count - 1) == i) { lastElement = true; } var row = grouped.Rows[i]; //the las row used only for Total, so we no need to use the first line in it if ((grouped.Rows.Count - 1) > i) { Row rowGp = _table.AddRow(); FillRow(rowGp, 0, row.Name, true, ParagraphAlignment.Left, VerticalAlignment.Center); //if we have some subgroup criterias< the forst line should contendted only name for subgroup if (string.Equals(filter.subtotalBy, "None", StringComparison.InvariantCultureIgnoreCase)) { for (int j = 0; j < row.Amounts.Count; j++) { var am = row.Amounts[j]; FillRow(rowGp, j + 1, am.ToMoneyString(), false, ParagraphAlignment.Left, VerticalAlignment.Center); } } else { for (int j = 0; j < row.Amounts.Count; j++) { FillRow(rowGp, j + 1, "", false, ParagraphAlignment.Left, VerticalAlignment.Center); } } } //subgrouping if (!string.Equals(filter.subtotalBy, "None", StringComparison.InvariantCultureIgnoreCase) && row.SubDetails != null) { foreach (TransactioMatrixSubDetails rw in row.SubDetails) { Row rowGp2 = _table.AddRow(); FillRow(rowGp2, 0, rw.Name, false, ParagraphAlignment.Left, VerticalAlignment.Center, marginLeft: 10); for (int y = 0; y < rw.Amounts.Count; y++) { var am = rw.Amounts[y]; FillRow(rowGp2, y + 1, am.ToMoneyString(), false, ParagraphAlignment.Left, VerticalAlignment.Center); } } //fill total Row totalRow = _table.AddRow(); FillRow(totalRow, 0, row.TotalName, true, ParagraphAlignment.Left, VerticalAlignment.Center); for (int j = 0; j < row.Amounts.Count; j++) { var am = row.Amounts[j]; FillRow(totalRow, j + 1, am.ToMoneyString(), false, ParagraphAlignment.Left, VerticalAlignment.Center); } AddEmptyRow(); } if (lastElement) { Row totalRow = _table.AddRow(); FillRow(totalRow, 0, row.TotalName, true, ParagraphAlignment.Left, VerticalAlignment.Center); for (int j = 0; j < row.Amounts.Count; j++) { var am = row.Amounts[j]; FillRow(totalRow, j + 1, am.ToMoneyString(), false, ParagraphAlignment.Left, VerticalAlignment.Center); } } } }
public async Task <IActionResult> RotateAsync(MatrixDTO matrixDto) { return(Ok(await _matrixEngine.GetRotatedMatrixAsync(matrixDto))); }
public async Task <IActionResult> ExportToCsvAsync(MatrixDTO matrixDto) { await _matrixEngine.ExportMatrixToCsvAsync(matrixDto); return(Created("GetMatrixFromCsv", matrixDto)); }
public async Task <JsonResult> GetRotatedMatrix(MatrixDTO matrix) { return(Json(new { matrix = await _actionsWithMatrix.Rotate(MatrixDTO.ConversionArray(matrix.ToArray)) })); }