コード例 #1
0
ファイル: Form1.cs プロジェクト: SPatterson91/PoppiesCSharp
        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();
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: SPatterson91/PoppiesCSharp
        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");
                }
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: SPatterson91/PoppiesCSharp
        private void Power_Click(object sender, EventArgs e)
        {
            int sum = 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);
            }



            int count_row = dataGridView1.Rows.Count;

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

            double avg = calc.CalculateAverage(sum, count_row);


            PowerTextBox.AppendText(Environment.NewLine);
            PowerTextBox.AppendText(Environment.NewLine + "Average heart rate: " + avg.ToString("N0"));



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

            foreach (var line in lines)
            {
                if (line.StartsWith("Lower3="))
                {
                    Lower3 = double.Parse(line.Replace("Lower3=", ""));
                    PowerTextBox.AppendText(Environment.NewLine);
                    PowerTextBox.AppendText(Environment.NewLine + "Threshhold Heartrate: " + Lower3);
                }

                if (line.StartsWith("Length="))
                {
                    Length = TimeSpan.Parse(line.Replace("Length=", ""));

                    var    time          = Length.ToString();    //initiate variable for length of session
                    double seconds       = TimeSpan.Parse(time).TotalSeconds;
                    double secondslength = seconds;              //convert the time of session to seconds
                    double dec_length    = secondslength / 3600; // time of session as a decimal



                    PowerTextBox.AppendText(Environment.NewLine);
                    PowerTextBox.AppendText(Environment.NewLine + "Length of Workout: " + dec_length.ToString("N2"));
                }

                if (line.StartsWith("RestHR="))
                {
                    RestHR = double.Parse(line.Replace("RestHR=", ""));
                    PowerTextBox.AppendText(Environment.NewLine);
                    PowerTextBox.AppendText(Environment.NewLine + "Resting heart rate: " + RestHR);

                    var    time          = Length.ToString();    //initiate variable for length of session
                    double seconds       = TimeSpan.Parse(time).TotalSeconds;
                    double secondslength = seconds;              //convert the time of session to seconds
                    double dec_length    = secondslength / 3600; // time of session as a decimal

                    double           TSS;
                    PowerCalculation powercalc = new PowerCalculation();
                    TSS = powercalc.CalculateTSS(avg, RestHR, Lower3, dec_length);
                    //TTS = powercalc.CalculateTSS(144, 46, 170, 1.1); these are actual figures from the file
                    PowerTextBox.AppendText(Environment.NewLine);
                    PowerTextBox.AppendText(Environment.NewLine + "Training Stress Score (TSS):" + "" + TSS.ToString("N2"));
                }
            }


            double           NP;                //normalised power
            double           nnp        = 168;; //in our case I used the average heart rate and not the rolling average heart rate
            PowerCalculation powercalc1 = new PowerCalculation();

            NP = powercalc1.CalculateNP(nnp);

            double IFF;         //Intensity Function
            double func = 320;; //function threshold as supplied by the client
            int    sum4 = 0;

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



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


            double avg4 = calc1.CalculateAverage(sum4, count_row);


            PowerCalculation powercalc2 = new PowerCalculation();

            IFF = powercalc2.CalculateIF(avg4, func);



            PowerTextBox.AppendText(Environment.NewLine);
            PowerTextBox.AppendText(Environment.NewLine + "Normalised Power (NP):" + NP);

            PowerTextBox.AppendText(Environment.NewLine);
            PowerTextBox.AppendText(Environment.NewLine + "Intensity Factor (IF):" + IFF.ToString("N2"));


            MovingAverageCalculator calculator = new MovingAverageCalculator(30);



            // loop through the values 1 to 10
            //for (int i = 1; i <= 10; i++)
            //{
            //    // write out the average
            //    Console.WriteLine(calculator.NextValue(i));
            //}



            //for (int i = 0; i < dataGridView1.Rows.Count; i++)
            //{

            //    float[] sumpower = new float[Convert.ToInt32(dataGridView1.Rows[i].Cells["power"].Value)];
            //    //PowerTextBox.AppendText(Environment.NewLine + calculator.NextValue(i));
            //    PowerTextBox.AppendText(Environment.NewLine + sumpower);
            //}
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: SPatterson91/PoppiesCSharp
        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;
                        }
                    }
                }
            }
        }