예제 #1
0
        public List <ColumnValueCounter> AssembleColumnValueCounters()
        {
            //columnValueCounters stores a ColumnValueCounter for every column in the data table.
            //This allows for storing the names and number of occurences of each unique data row value in relation to the column that it is a part of.
            List <ColumnValueCounter> columnValueCounters = new List <ColumnValueCounter>();
            //columnHeaders is a list of all of the column headers that we get from the importCSV function
            List <string> columnHeaders = _columnHeaders;

            //For every column, make a new ColumnValueCounter.
            //For each unique row value in the column, count the number of occurences of that value and store both the value and the count in the ColumnValueCounter UniqueRowValue attribute.

            for (int i = 0; i < _allData.Columns.Count; i++)
            {
                ColumnValueCounter currentColumn = new ColumnValueCounter {
                    columnName        = columnHeaders[i],
                    totalColumnValues = _allData.AsDataView().ToTable(false, columnHeaders[i]).Rows.Count
                };
                DataRowCollection uniqueRows = _allData.AsDataView().ToTable(true, columnHeaders[i]).Rows;
                //for each unique row value in this column
                UniqueRowValue unknownRowValue = new UniqueRowValue("Unknown", CountUniqueRows(_allData, currentColumn.columnName, ""));
                currentColumn.unknownCount = unknownRowValue.count;
                for (int j = 0; j < uniqueRows.Count; j++)
                {
                    //Gets the name of the unique row value
                    string uniqueRowName = uniqueRows[j].ItemArray[0].ToString();
                    //Exclude unique row values that we do not care about (the column header and any blank rows)

                    if (uniqueRowName != "" && uniqueRowName != currentColumn.columnName)
                    {
                        currentColumn.uniqueRowValues.Add(new UniqueRowValue(uniqueRowName, CountUniqueRows(_allData, currentColumn.columnName, uniqueRowName)));
                    }
                }
                //Get abbreviated string representation of the current column (i.e. AA or AF)
                currentColumn.abbreviatedRepresentation = GetExcelColumnName(i);
                //Sorts the row values alphabetically within the current column object.
                currentColumn.uniqueRowValues.Sort((x, y) => x.name.CompareTo(y.name));
                //store that entire column
                columnValueCounters.Add(currentColumn);
            }
            return(columnValueCounters);
        }
예제 #2
0
        /// <summary>
        /// Ensures that each column in the list of columnValueCounters has the same
        /// amount of unique row values as each other data column being graphed.
        /// If there is a column that does not have any occurence of one of the unique
        /// row values that shows up in one of the other columns then it is created in that column with a count of zero.
        /// </summary>
        /// <param name="usedColumns">List of ColumnValueCounters to normalize</param>
        public void NormalizeColumns(List <ColumnValueCounter> usedColumns)
        {
            int uniqueRowValueCount = 0;
            //Get the column that has the most unique row values to compare the other columns against.
            //The column with the most unique row values is treated as the optimal column that we will try to match the others to.
            ColumnValueCounter maxColumn = new ColumnValueCounter();

            foreach (ColumnValueCounter column in usedColumns)
            {
                if (column.uniqueRowValues.Count > uniqueRowValueCount)
                {
                    uniqueRowValueCount = column.uniqueRowValues.Count;
                    maxColumn           = column;
                }
            }
            if (usedColumns.Count > 1)
            {
                //For each used data column
                for (int i = 0; i < usedColumns.Count; i++)
                {
                    ColumnValueCounter currentColumn = usedColumns[i];
                    //If the number of unique row values of the current column is less than any of the others
                    if (currentColumn.uniqueRowValues.Count < uniqueRowValueCount)
                    {
                        //scan through each row value that is in the collumn with the most unique row values
                        for (int j = 0; j < maxColumn.uniqueRowValues.Count; j++)
                        {
                            //scan through each row value in the column with missing unique row values
                            for (int k = 0; k < maxColumn.uniqueRowValues.Count; k++)
                            {
                                //check to see if the unique row value that we are currently looking at from the list
                                //of intended unique row values is also in the column with the list of unique row values that is missing a row value.
                                if (currentColumn.uniqueRowValues[k].name == maxColumn.uniqueRowValues[j].name)
                                {
                                    break;
                                }
                                //If we did not find the unique row value in this column then add it to the column while ensuring that it is added at the correct index in the list.
                                //Making sure the index that it is at is important when we start creating chart data series using these columnValueCounters
                                if (k == (currentColumn.uniqueRowValues.Count - 1))
                                {
                                    List <UniqueRowValue> tempUniqueRowValues = new List <UniqueRowValue>();
                                    //Populate a list of temporary uniqueRowValues with the unique row values that we have already processes/looked at
                                    for (int l = 0; l < j; l++)
                                    {
                                        tempUniqueRowValues.Add(currentColumn.uniqueRowValues[l]);
                                    }
                                    //Add the unique row value that was excluded from this column in the correct position in the list
                                    tempUniqueRowValues.Add(new UniqueRowValue(maxColumn.uniqueRowValues[j].name, 0));
                                    //Fill the rest of the unique row values
                                    for (int l = j; l < currentColumn.uniqueRowValues.Count; l++)
                                    {
                                        tempUniqueRowValues.Add(currentColumn.uniqueRowValues[l]);
                                    }
                                    currentColumn.uniqueRowValues = tempUniqueRowValues;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }