コード例 #1
0
        private void Calculate_Click(object sender, EventArgs e)
        {
            //Declare Swimmer's Label, so we can write the Swimmer's Name, and store it with his/her proper Data

            string swimmerName;

            swimmerName = Console.ReadLine();

            swimmerName = lblSwimerName.ToString();

            //Declarations

            double longDistance;
            double longTime;
            double shortDistance;
            double shortTime;

            double workoutDistance;
            double workingTime;

            double CSS; //Critical Swim Speed
            double NSS; //Normalized Swim Speed
            double IF;  //Intensity Factor
            double TSS; //Training Stress Score

            //Inputs
            //This 4 lines (with code) are used to calculate the CSS
            longDistance = double.Parse(lblLongerDistance.Text);
            longTime     = double.Parse(lblLongerTime.Text);

            shortDistance = double.Parse(lblShorterDistance.Text);
            shortTime     = double.Parse(lblShorterTime.Text);

            //This 2 lines of code are used to calculate the NSS
            workoutDistance = double.Parse(lblWorkoutDistance.Text);
            workingTime     = double.Parse(lblWorkingTime.Text);

            //Processing

            CSS = (longDistance - shortDistance) / (longTime - shortTime); //Calculates the CSS
            NSS = (workoutDistance / workingTime);                         //Calculates tge NSS
            IF  = (NSS / CSS);                                             //Calculates the IF
            TSS = ((Math.Pow(IF, 3)) * (workingTime / 3600) * 100);        //Calculates the TSS

            //OutPut

            lblCSS.Text = CSS.ToString();
            lblNSS.Text = NSS.ToString();
            lblIF.Text  = IF.ToString();
            lblTSS.Text = TSS.ToString();
        }
コード例 #2
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);
            //}
        }