Пример #1
0
        public ResultsData ExpandAndReorderColumns(List <string> quandlCodeColumns, string dateColumn,
                                                   bool insertDateColumn)
        {
            // Expand the column header names
            var expandedHeaders = quandlCodeColumns.Select(qcc =>
            {
                var splitString = qcc.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                return(splitString.Length >= 3
                    ? new List <string> {
                    qcc
                }
                    : Headers.FindAll(x => x.StartsWith(qcc + '/')).ToList());
            }).SelectMany(i => i).ToList();

            expandedHeaders = SanitizeHeaders(expandedHeaders, dateColumn, insertDateColumn);

            // Re-order the columns appropriately
            var shuffledData = new List <List <object> >();

            for (var r = 0; r < Data.Count; r++)
            {
                shuffledData.Add(new List <object>());
            }

            foreach (var header in expandedHeaders)
            {
                var columnIndex = Headers.IndexOf(header);
                for (var r = 0; r < Data.Count; r++)
                {
                    if (columnIndex == -1)
                    {
                        shuffledData[r].Add(null);
                    }
                    else
                    {
                        shuffledData[r].Add(Data[r][columnIndex]);
                    }
                }
            }

            return(new ResultsData(shuffledData, expandedHeaders));
        }