public static GroupBy ( IList |
||
facts | IList |
|
pivot | string | |
return | string>.Tuple |
private void ProcessReport(StatisticsPackagesReport report, string[] groupby, string[] dimensions, string id, CultureInfo clientCulture) { if (report == null) { return; } string[] pivot = new string[4]; if (groupby != null) { // process and validate the groupby query. unrecognized fields are ignored. others fields regarded for existance int dim = 0; foreach (string dimension in dimensions) { CheckGroupBy(groupby, dimension, pivot, ref dim, report); } if (dim == 0) { // no recognized fields so just fall into the null logic groupby = null; } else { // the pivot array is used as the Columns in the report so we resize because this was the final set of columns Array.Resize(ref pivot, dim); } Tuple <StatisticsPivot.TableEntry[][], string> result = StatisticsPivot.GroupBy(report.Facts, pivot, clientCulture); if (id != null) { int col = Array.FindIndex(pivot, (s) => s.Equals("Version", StringComparison.Ordinal)); if (col >= 0) { for (int row = 0; row < result.Item1.GetLength(0); row++) { StatisticsPivot.TableEntry entry = result.Item1[row][col]; if (entry != null) { entry.Uri = Url.Package(id, entry.Data); } } } } report.Table = result.Item1; report.Total = result.Item2; report.Columns = pivot.Select(GetDimensionDisplayName); } if (groupby == null) { // degenerate case (but still logically valid) foreach (string dimension in dimensions) { report.Dimensions.Add(new StatisticsDimension { Value = dimension, DisplayName = GetDimensionDisplayName(dimension), IsChecked = false }); } report.Table = null; report.Total = report.Facts.Sum(fact => fact.Amount).ToString("n0", clientCulture); } }
private void ProcessReport(StatisticsPackagesReport report, string[] groupby, string[] dimensions, string id) { if (report == null) { return; } var pivot = new string[4]; if (groupby != null) { // process and validate the groupby query. unrecognized fields are ignored. others fields regarded for existence var dim = 0; foreach (var dimension in dimensions) { CheckGroupBy(groupby, dimension, pivot, ref dim, report); } if (dim == 0) { // no recognized fields so just fall into the null logic groupby = null; } else { // the pivot array is used as the Columns in the report so we resize because this was the final set of columns Array.Resize(ref pivot, dim); } } if (groupby != null) { Tuple <StatisticsPivot.TableEntry[][], int> result = StatisticsPivot.GroupBy(report.Facts, pivot); if (id != null) { var col = Array.FindIndex(pivot, s => s.Equals("Version", StringComparison.Ordinal)); if (col >= 0) { for (var row = 0; row < result.Item1.GetLength(0); row++) { var entry = result.Item1[row][col]; if (entry != null) { entry.Uri = Url.Package(id, entry.Data); } } } } // We do this here to try to order the result by the Version if available. // Since Version might not be available, don't sort if it isn't. // If Version is available, we need the following empty version rows to be moved with it (rowspan) NuGetVersion prevVersion = null; report.Table = result.Item1 .Select(e => { if (NuGetVersion.TryParse(e[0]?.Data, out NuGetVersion versionOut)) { prevVersion = versionOut; return(new { version = versionOut, e }); } return(new { version = prevVersion, e }); }) .OrderByDescending(e => e.version) .Select(e => e.e).ToList(); report.Total = result.Item2; report.Columns = pivot.Select(GetDimensionDisplayName); } if (groupby == null) { // degenerate case (but still logically valid) foreach (string dimension in dimensions) { if (!report.Dimensions.Any(d => d.Value == dimension)) { report.Dimensions.Add(new StatisticsDimension { Value = dimension, DisplayName = GetDimensionDisplayName(dimension), IsChecked = false }); } } report.Table = null; report.Total = report.Facts.Sum(fact => fact.Amount); } }