Beispiel #1
0
        private void imperialbutton_Click(object sender, EventArgs e)

        //imperial button
        {
            double sum1          = 0;
            var    time          = Length.ToString(); //initiate variable for length of session
            double seconds       = TimeSpan.Parse(time).TotalSeconds;
            double secondslength = seconds / 3600;    //convert the time of session to seconds



            for (int i = 0; i < dataGridView1.Rows.Count; ++i)
            {
                sum1 += Convert.ToInt32(dataGridView1.Rows[i].Cells["speed"].Value);
            }

            int count_row = dataGridView1.Rows.Count;

            double avespeed;
            double distance;

            GetCalculations calc = new GetCalculations();

            avespeed = calc.CalculateAverage(sum1, count_row);
            distance = calc.CalculateDistance(secondslength, avespeed);

            var MaxID_1 = dataGridView1.Rows.Cast <DataGridViewRow>()
                          .Max(r => Convert.ToInt32(r.Cells["speed"].Value));

            var lines = File.ReadAllLines(openFileDialog1.FileName);

            foreach (var line in lines)
            {
                if (line.StartsWith("SMode="))
                {
                    SMode = int.Parse(line.Replace("SMode=", " "));



                    string     unit_output;
                    string     ret = SMode.ToString();
                    SModeIndex n   = new SModeIndex();
                    unit_output = n.indexing(ret);

                    switch (unit_output)
                    {
                    case "0":     //Convert to miles using ConvertUnits class

                        double mphavg    = ConvertUnits.ConvertKilometersToMiles(avespeed);
                        double maxmph    = ConvertUnits.ConvertKilometersToMiles(MaxID_1);
                        double distmiles = ConvertUnits.ConvertKilometersToMiles(distance);


                        speedcal.Text = "Average Speed:" + mphavg.ToString("N2") + " mph" + System.Environment.NewLine
                                        + System.Environment.NewLine + "Max Speed:"
                                        + maxmph.ToString("N2") + " mph"
                                        + System.Environment.NewLine + System.Environment.NewLine
                                        + "Total Distance covered:" + distmiles.ToString("N2") + " Miles";

                        break;

                    case "1":     //convert to kilometres using ConvertUnits class

                        double kphave    = ConvertUnits.ConvertMilesToKilometers(avespeed);
                        double maxkph    = ConvertUnits.ConvertMilesToKilometers(MaxID_1);
                        double distkilos = ConvertUnits.ConvertMilesToKilometers(distance);


                        speedcal.Text = "Average Speed:" + kphave.ToString("N2") + " mph" + System.Environment.NewLine
                                        + System.Environment.NewLine + "Max Speed:"
                                        + maxkph.ToString("N2") + " mph"
                                        + System.Environment.NewLine + System.Environment.NewLine
                                        + "Total Distance covered:" + distkilos.ToString("N2") + " Miles";

                        break;
                    }

                    ConvertUnits unitsclass = new ConvertUnits("Distance and Speed units have been changed to Miles");
                }
            }
        }
Beispiel #2
0
        public void averagemethod()
        {
            int sum  = 0;
            int sum1 = 0;
            int sum2 = 0;
            int sum3 = 0;
            int sum4 = 0;
            int sum5 = 0;

            //converts the rows to integers for the cells
            for (int i = 0; i < dataGridView1.Rows.Count; ++i)
            {
                sum  += Convert.ToInt32(dataGridView1.Rows[i].Cells["heartrate"].Value);
                sum1 += Convert.ToInt32(dataGridView1.Rows[i].Cells["speed"].Value);
                sum2 += Convert.ToInt32(dataGridView1.Rows[i].Cells["cadence"].Value);
                sum3 += Convert.ToInt32(dataGridView1.Rows[i].Cells["alt"].Value);
                sum4 += Convert.ToInt32(dataGridView1.Rows[i].Cells["power"].Value);
                sum5 += Convert.ToInt32(dataGridView1.Rows[i].Cells["pwrBal"].Value);
            }

            int count_row = dataGridView1.Rows.Count;



            GetCalculations calc = new GetCalculations(); //use Get Calculations to determine average

            double avg  = calc.CalculateAverage(sum, count_row);
            double avg1 = calc.CalculateAverage(sum1, count_row);
            double avg2 = calc.CalculateAverage(sum2, count_row);
            double avg3 = calc.CalculateAverage(sum3, count_row);
            double avg4 = calc.CalculateAverage(sum4, count_row);
            double avg5 = calc.CalculateAverage(sum5, count_row);


            ///<summary>
            ///initiates variable for min heartrate and max heartrate, speed, cadence, alt, power and power balance
            ///and converts it into an integer
            ///</summary>
            var MinID = dataGridView1.Rows.Cast <DataGridViewRow>()
                        .Min(r => Convert.ToInt32(r.Cells["heartrate"].Value));

            var MaxID = dataGridView1.Rows.Cast <DataGridViewRow>()
                        .Max(r => Convert.ToInt32(r.Cells["heartrate"].Value));

            var MaxID_1 = dataGridView1.Rows.Cast <DataGridViewRow>()
                          .Max(r => Convert.ToInt32(r.Cells["speed"].Value));

            var MaxID_2 = dataGridView1.Rows.Cast <DataGridViewRow>()
                          .Max(r => Convert.ToInt32(r.Cells["cadence"].Value));

            var MaxID_3 = dataGridView1.Rows.Cast <DataGridViewRow>()
                          .Max(r => Convert.ToInt32(r.Cells["alt"].Value));

            var MaxID_4 = dataGridView1.Rows.Cast <DataGridViewRow>()
                          .Max(r => Convert.ToInt32(r.Cells["power"].Value));

            var MaxID_5 = dataGridView1.Rows.Cast <DataGridViewRow>()
                          .Max(r => Convert.ToInt32(r.Cells["pwrBal"].Value));


            ///<summary>
            ///distance is seconds /3600 to convert to fraction of an hour.
            ///then times by the average speed per hour.
            ///then it divides by 10, as a temporary measure until speed can be displayed as a decimal
            ///</summary>

            var    time     = Length.ToString();                 //initiate variable for length of session
            double seconds  = TimeSpan.Parse(time).TotalSeconds; //convert the time of session to seconds
            double distance = (seconds / 3600 * avg1);

            //calculation to work out min HR
            double minheartrate = 500;

            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                string hr = dataGridView1.Rows[i].Cells["heartrate"].Value.ToString();
                minheartrate = Math.Min(minheartrate, int.Parse(hr));
            }

            //calculation to work out speed into decimal point
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                double miles = double.Parse(dataGridView1.Rows[i].Cells["speed"].Value.ToString()); //stores value of speed column
                miles = miles / 10;                                                                 //calclation into mph
                dataGridView1.Rows[i].Cells["speed"].Value = Math.Round(miles, 2);                  //dispays correct format of speed }
            }

            ///<summary>
            ///displays the columns of data that have been calculated into textboxes.
            ///N2 puts a decimal point into the desired number of decimal places which is 2.
            ///The system.environment.NewLine puts the calculation of each variable onto a new line.
            ///</summary>

            heartcal.Text = "Min Heart Rate:" + minheartrate.ToString() + System.Environment.NewLine
                            + System.Environment.NewLine + "Average Heart Rate:"
                            + avg.ToString("N0") + System.Environment.NewLine + System.Environment.NewLine +
                            "Max Heart Rate:" + MaxID.ToString();

            speedcal.Text = "Average Speed:" + avg1.ToString("N2") + " kph" + System.Environment.NewLine
                            + System.Environment.NewLine + "Max Speed:" + MaxID_1.ToString("N2") +
                            " kph" + System.Environment.NewLine + System.Environment.NewLine +
                            "Total Distance covered:" + distance.ToString("N2");

            var lines = File.ReadAllLines(openFileDialog1.FileName);

            foreach (var line in lines)
            {
                if (line.StartsWith("SMode="))
                {
                    SMode = int.Parse(line.Replace("SMode=", " "));

                    ///<summary>
                    /// the eighth character in SMode determines the units.. "0" is kilometres. "1" is miles.
                    ///after finding out which character using SModeIndex. uses a swith statement to display the appropriate units.
                    ///</summary>
                    string     unit_output;
                    string     ret = SMode.ToString();
                    SModeIndex n   = new SModeIndex();
                    unit_output = n.indexing(ret);

                    switch (unit_output)
                    {
                    case "0":

                        speedcal.Text = "Average Speed:" + avg1.ToString("N2") + " kph" + System.Environment.NewLine
                                        + System.Environment.NewLine + "Max Speed:"
                                        + MaxID_1.ToString("N2") + " kph"
                                        + System.Environment.NewLine + System.Environment.NewLine
                                        + "Total Distance covered:" + distance.ToString("N2") + " Kilometers";



                        break;

                    case "1":

                        speedcal.Text = "Average Speed:" + avg1.ToString("N2") + " mph" + System.Environment.NewLine
                                        + System.Environment.NewLine + "Max Speed:"
                                        + MaxID_1.ToString("N2") + " mph"
                                        + System.Environment.NewLine + System.Environment.NewLine
                                        + "Total Distance covered:" + distance.ToString("N2") + " Miles";

                        break;
                    }

                    cadencecal.Text = "Average Cadence:" + avg2.ToString("N0") + System.Environment.NewLine
                                      + System.Environment.NewLine + "Max Cadence:" + MaxID_2.ToString();

                    altcal.Text = "Average Altitude:" + avg3.ToString("N0")
                                  + System.Environment.NewLine + System.Environment.NewLine + "Max Altitude:"
                                  + MaxID_3.ToString();

                    powercal.Text = "Average Power:" + avg4.ToString("N0")
                                    + System.Environment.NewLine + System.Environment.NewLine + "Max Power:" + MaxID_4.ToString("");

                    pwrbalcal.Text = "Average Power Balance:" + avg5.ToString("N0")
                                     + System.Environment.NewLine + System.Environment.NewLine + "Max Power Balance:"
                                     + MaxID_5.ToString();
                }
            }
        }
Beispiel #3
0
        private void Metricbutton_click(object sender, EventArgs e)
        {
            //metric button
            {
                double sum1          = 0;
                var    time          = Length.ToString(); //initiate variable for length of session
                double seconds       = TimeSpan.Parse(time).TotalSeconds;
                double secondslength = seconds / 3600;    //convert the time of session to seconds



                for (int i = 0; i < dataGridView1.Rows.Count; ++i)
                {
                    sum1 += Convert.ToInt32(dataGridView1.Rows[i].Cells["speed"].Value);
                }

                int count_row = dataGridView1.Rows.Count;

                double avespeed;
                double distance;

                GetCalculations calc = new GetCalculations();
                avespeed = calc.CalculateAverage(sum1, count_row);
                distance = calc.CalculateDistance(secondslength, avespeed);

                var MaxID_1 = dataGridView1.Rows.Cast <DataGridViewRow>()
                              .Max(r => Convert.ToInt32(r.Cells["speed"].Value));

                var lines = File.ReadAllLines(openFileDialog1.FileName);
                foreach (var line in lines)
                {
                    if (line.StartsWith("SMode="))
                    {
                        SMode = int.Parse(line.Replace("SMode=", " ")); //find out if the eight character in SMode from the input file is a "0"  or a "1"



                        string     unit_output;
                        string     ret = SMode.ToString();
                        SModeIndex n   = new SModeIndex();
                        unit_output = n.indexing(ret);

                        switch (unit_output)
                        {
                        case "0":     //if "0" then units are displayed in kilometres

                            speedcal.Text = "Average Speed:" + avespeed.ToString("N2") + " kph" + System.Environment.NewLine
                                            + System.Environment.NewLine + "Max Speed:"
                                            + MaxID_1.ToString("N2") + " kph"
                                            + System.Environment.NewLine + System.Environment.NewLine
                                            + "Total Distance covered:" + distance.ToString("N2") + " kilometres";



                            break;

                        case "1":     //if "1" units are displayed in miles

                            double mphavg    = ConvertUnits.ConvertKilometersToMiles(avespeed);
                            double maxmph    = ConvertUnits.ConvertKilometersToMiles(MaxID_1);
                            double distmiles = ConvertUnits.ConvertKilometersToMiles(distance);


                            speedcal.Text = "Average Speed:" + mphavg.ToString("N2") + " mph" + System.Environment.NewLine
                                            + System.Environment.NewLine + "Max Speed:"
                                            + maxmph.ToString("N2") + " mph"
                                            + System.Environment.NewLine + System.Environment.NewLine
                                            + "Total Distance covered:" + distmiles.ToString("N2") + " Miles";

                            break;
                        }
                    }
                }
            }
        }