Esempio n. 1
0
        private void ImportTimesButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "Text (*.txt)|*.txt";
            dialog.Title  = "Load times";
            dialog.ShowDialog();
            string path      = dialog.FileName;
            string shortPath = Path.GetFileName(path);

            FileNameLabel.Text = shortPath;
            if (path.Equals(""))
            {
                return;
            }
            StreamReader reader     = new StreamReader(path);
            string       timeString = reader.ReadToEnd();

            reader.Close();
            var times = timeString.Split(',');

            Times       = new List <double>();
            SortedTimes = new List <double>();
            int i = 0;

            try
            {
                for (int k = 0; k < times.Length; k++)
                {
                    i = k;
                    string str = times[k].Trim();
                    if (str.EndsWith("+"))
                    {
                        str = str.Substring(0, str.Length - 1);
                    }
                    double d = double.Parse(str);
                    Times.Add(d);
                    SortedTimes.Add(d);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("File is in the wrong format " + i, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Times       = null;
                SortedTimes = null;
                return;
            }
            SortedTimes.Sort();

            TimesTable.SuspendLayout();
            SortedTimesTable.SuspendLayout();

            TimesTable.Controls.Clear();
            SortedTimesTable.Controls.Clear();

            TimesTable.RowCount       = Times.Count;
            SortedTimesTable.RowCount = Times.Count;
            for (int k = 0; k < Times.Count; k++)
            {
                TimesTable.Controls.Add(new Label()
                {
                    Text = (k + 1).ToString(), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 70
                }, 0, k);
                TimesTable.Controls.Add(new Label()
                {
                    Text = Times[k].ToString(), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 120
                }, 1, k);
                SortedTimesTable.Controls.Add(new Label()
                {
                    Text = (k + 1).ToString(), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 70
                }, 0, k);
                SortedTimesTable.Controls.Add(new Label()
                {
                    Text = SortedTimes[k].ToString(), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 120
                }, 1, k);
            }

            TimesTable.ResumeLayout();
            SortedTimesTable.ResumeLayout();
            Update();

            SummaryTable.SuspendLayout();
            SummaryTable.Controls.Clear();
            for (int k = 0; k < 5; k++)
            {
                SummaryTable.Controls.Add(new Label()
                {
                    Text = (20 * k + 10 + "%"), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 70
                }, k, 0);
                SummaryTable.Controls.Add(new Label()
                {
                    Text = CalcTime(20 * k + 10).ToString(), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 70
                }, k, 1);
            }
            SummaryTable.ResumeLayout();

            MeanLabel.Text    = calcMean().ToString("F2");
            AverageLabel.Text = calcAverage(0, Times.Count).ToString("F2");
            MedianLabel.Text  = SortedTimes[SortedTimes.Count / 2].ToString();
            CountLabel.Text   = Times.Count.ToString();

            ConsecutiveLabel.Text = "";

            // averages
            Ao5List   = new List <double>();
            Ao12List  = new List <double>();
            Ao100List = new List <double>();
            for (int k = 0; k + 5 <= Times.Count; k++)
            {
                Ao5List.Add(CalcAo5(k));
            }
            for (int k = 0; k + 12 <= Times.Count; k++)
            {
                Ao12List.Add(CalcAo12(k));
            }
            InitializeAo100List();

            if (Times.Count >= 5)
            {
                Ao5Label.Text = Ao5List.Min().ToString("F2");
            }
            else
            {
                Ao5Label.Text = "N/A";
            }
            if (Times.Count >= 12)
            {
                Ao12Label.Text = Ao12List.Min().ToString("F2");
            }
            else
            {
                Ao12Label.Text = "N/A";
            }
            if (Times.Count >= 100)
            {
                Ao100Label.Text = Ao100List.Min().ToString("F2");
            }
            else
            {
                Ao100Label.Text = "N/A";
            }
            StdDevLabel.Text = CalcStdDev().ToString("F2");
        }