private void PowerTextBox_Enter(object sender, EventArgs e) { PowerTextBox.Clear(); }
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); //} }