public ColumnViewModel GetColoredColumnViewModel() { Int32 categoricalCount = this.CategoricalCount; if (1 <= categoricalCount && categoricalCount <= 2) { return(CategoricalColumnViewModels.Last()); } return(null); }
/// <summary> /// 현재 viewStatus와 sheetViewModel을 이용하여 grouepdRows와 groupedRowViewModels를 생성함 /// 문제는 columnViewModel의 /// </summary> /// <param name="sheetViewModel"></param> public void Generate(SheetViewModel sheetViewModel) { List <ColumnViewModel> orderedColumnViewModels = sheetViewModel.ColumnViewModels; Int32 index = 0; if (IsEmpty) { // 어차피 allRow가 보일 것이므로 RowViewModel 을 만들어 줄 필요는 없음 } else if (IsN) // 이 경우는 뉴메리컬 하나만 선택되어 비닝 된 결과가 보이는 경우이다. { ColumnViewModel selected = FirstColumn; GroupedRows = Bin(selected, sheetViewModel.FilteredRows); GroupedRowViewModels = new List <RowViewModel>(); // 여기서 groupedRows가 소팅되어야함 // 그런데 여기서는 선택되지 않은 컬럼의 경우에는 어차피 어그리게이션되므로 소팅 순서가 의미가 없음 따라서 선택된 컬럼에 대해서만 소팅하면 된다 GroupedRows.Sort(new GroupedRowComparer(sheetViewModel, this)); foreach (GroupedRows groupedRows in GroupedRows) { if (groupedRows.Rows.Count == 0) { continue; } RowViewModel rowViewModel = new RowViewModel(sheetViewModel.MainPageViewModel) { Index = index++, Rows = groupedRows.Rows }; foreach (ColumnViewModel columnViewModel in orderedColumnViewModels) { Cell cell = new Cell(); cell.ColumnViewModel = columnViewModel; if (columnViewModel == selected) { Bin bin = groupedRows.Keys[selected] as Bin; String content = bin.ToString() + $" ({groupedRows.Rows.Count})"; cell.RawContent = content; cell.Content = content; } else if (columnViewModel.Type == ColumnType.Categorical) { Int32 uniqueCount = groupedRows.Rows.Select(r => r.Cells[columnViewModel.Index].Content).Distinct().Count(); cell.Content = $"({uniqueCount})"; cell.RawContent = $"({uniqueCount})"; } else //numerical { Object aggregated = columnViewModel.AggregativeFunction.Aggregate(groupedRows.Rows.Select(r => (Double)r.Cells[columnViewModel.Index].Content)); String formatted = Formatter.FormatAuto4((Double)aggregated); cell.RawContent = formatted; cell.Content = Double.Parse(formatted); } rowViewModel.Cells.Add(cell); } GroupedRowViewModels.Add(rowViewModel); } } else if (IsNN) { GroupedRowViewModels = new List <RowViewModel>(); RowViewModel rowViewModel = new RowViewModel(sheetViewModel.MainPageViewModel) { Index = 0, Rows = sheetViewModel.FilteredRows }; foreach (ColumnViewModel columnViewModel in orderedColumnViewModels) { Cell cell = new Cell(); cell.ColumnViewModel = columnViewModel; if (columnViewModel.Type == ColumnType.Categorical) { Int32 uniqueCount = sheetViewModel.FilteredRows.Select(r => r.Cells[columnViewModel.Index].Content).Distinct().Count(); cell.Content = $"({uniqueCount})"; cell.RawContent = $"({uniqueCount})"; } else if (columnViewModel.Type == ColumnType.Numerical) { Object aggregated = columnViewModel.AggregativeFunction.Aggregate(sheetViewModel.FilteredRows.Select(r => (Double)r.Cells[columnViewModel.Index].Content)); String formatted = Formatter.FormatAuto4((Double)aggregated); cell.RawContent = formatted; cell.Content = Double.Parse(formatted); } rowViewModel.Cells.Add(cell); } GroupedRowViewModels.Add(rowViewModel); } else if (CategoricalCount > 0)// 이 경우는 categorical이든 datetime이든 뭔가로 그룹핑이 된 경우 { GroupedRows = GroupRecursive( sheetViewModel.FilteredRows, CategoricalColumnViewModels.ToList(), 0); GroupedRows.Sort(new GroupedRowComparer(sheetViewModel, this)); GroupedRowViewModels = new List <RowViewModel>(); foreach (GroupedRows groupedRows in GroupedRows) { RowViewModel rowViewModel = new RowViewModel(sheetViewModel.MainPageViewModel) { Index = index++, Rows = groupedRows.Rows }; foreach (ColumnViewModel columnViewModel in orderedColumnViewModels) { Cell cell = new Cell(); cell.ColumnViewModel = columnViewModel; if (groupedRows.Keys.ContainsKey(columnViewModel)) { Object content = groupedRows.Keys[columnViewModel]; cell.Content = content; cell.RawContent = cell.Content.ToString(); } else if (columnViewModel.Type == ColumnType.Categorical) { Int32 uniqueCount = groupedRows.Rows.Select(r => r.Cells[columnViewModel.Index].Content).Distinct().Count(); cell.Content = $"({uniqueCount})"; cell.RawContent = $"({uniqueCount})"; } else if (columnViewModel.Type == ColumnType.Numerical) { Object aggregated = columnViewModel.AggregativeFunction.Aggregate(groupedRows.Rows.Select(r => (Double)r.Cells[columnViewModel.Index].Content)); String formatted = Formatter.FormatAuto4((Double)aggregated); cell.RawContent = formatted; cell.Content = Double.Parse(formatted); } rowViewModel.Cells.Add(cell); } GroupedRowViewModels.Add(rowViewModel); } } else { ; } }