Пример #1
0
        /// <summary>
        /// Suplementary method to assemble statistics CSV table.
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="headers"></param>
        /// <param name="title"></param>
        public void appendStatistics(string[,] dataTable, string[] headers, string title)
        {
            // Get the bounds.
            int num_cols = dataTable.GetUpperBound(1) + 1;

            // Adding headers
            sb.Append(title);
            // Add the other fields in this row separated by commas.
            for (int col = 0; col < num_cols; col++)
            {
                sb.Append("," + headers[col]);
            }
            sb.AppendLine();

            // Adding body

            // Add MIN
            sb.Append("Min");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     min = currentColumnStatistics.getMin().ToString();
                sb.Append("," + min);
            }
            sb.AppendLine();

            // Add MAX
            sb.Append("Max");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     max = currentColumnStatistics.getMax().ToString();
                sb.Append("," + max);
            }
            sb.AppendLine();

            // Add Mean
            sb.Append("Mean");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     mean = currentColumnStatistics.getMean().ToString();
                sb.Append("," + mean);
            }
            sb.AppendLine();

            // Add HMean
            sb.Append("Hmean");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     hmean = currentColumnStatistics.getHmean().ToString();
                sb.Append("," + hmean);
            }
            sb.AppendLine();

            // Add GMean
            sb.Append("Gmean");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     gmean = currentColumnStatistics.getGmean().ToString();
                sb.Append("," + gmean);
            }
            sb.AppendLine();

            // Add Median
            sb.Append("Median");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     median = currentColumnStatistics.getMedian().ToString();
                sb.Append("," + median);
            }
            sb.AppendLine();

            // Add P10
            sb.Append("P10");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     p10 = currentColumnStatistics.getP10().ToString();
                sb.Append("," + p10);
            }
            sb.AppendLine();

            // Add P50
            sb.Append("P50");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     p50 = currentColumnStatistics.getP50().ToString();
                sb.Append("," + p50);
            }
            sb.AppendLine();

            // Add P90
            sb.Append("P90");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     p90 = currentColumnStatistics.getP90().ToString();
                sb.Append("," + p90);
            }
            sb.AppendLine();

            // Add Missing
            sb.Append("Missing");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     missing = currentColumnStatistics.getMissing().ToString();
                sb.Append("," + missing);
            }
            sb.AppendLine();

            // Add TotalSamples
            sb.Append("Total Samples");
            for (int col = 0; col < num_cols; col++)
            {
                string[]   dataColumn              = ucLoadFile.Instance.getDataColumn(col, dataTable);
                string     variableName            = headers[col];
                Statistics currentColumnStatistics = new Statistics(variableName, dataColumn);
                string     total = currentColumnStatistics.getTotalSamples().ToString();
                sb.Append("," + total);
            }
            sb.AppendLine();
        }