Exemple #1
0
        public Double getAerobicCapacity(CurrentTest Data)
        ///Calculate the aerobic capacity
        {
            int           number_of_points = Data.takenHr.Count();
            List <double> coeficient       = new List <double>();

            for (int i = 0; i < number_of_points; i++)
            {
                for (int a = i + 1; a < number_of_points; a++)
                {
                    coeficient.Add((Data.takenHr[a] - Data.takenHr[i]) / (Data.takenX[a] - Data.takenX[i]));
                    ///calc all the coeficients bewteen all the points
                }
            }
            double average_coefficient = mathUtils.calcAverage(coeficient);
            ///calculate the average coefficient
            double averageX = mathUtils.calcAverage(Data.takenX);
            ///Calculate the average H
            double averageY = mathUtils.calcAverage(Data.takenHr);
            ///Calculate the average HR
            double origin = averageY - averageX * average_coefficient;

            ///calculate the origin (to have the equation of the right)
            return((Data.maxHR - origin) / average_coefficient);
            /// return the aerobic capacity
        }
        private void btn_newEmptyTest_Click(object sender, EventArgs e)
        /// Create an empty new test and open a form to edit it
        {
            var testData = new CurrentTest();

            // create a new empty test
            TestInAction.Add(testData);
            //add this new test to the list of test currently happening
            var TestForm = new FormTest(testData);

            //create the form to edit the new test
            updateList();
            //update the list of peope doing a test
            TestForm.Show();
            //Show the form
        }
        //area for the chart

        public FormTest(CurrentTest data)
        {
            InitializeComponent();
            /// import the data from main form to the interface
            Data = data;
            string Data_name = Data.Name;

            if (Data_name != "")
            {
                txt_name.Text = Data_name;
                nameOK        = true;
            }
            int Data_age = Data.Age;

            if (Data_age != 0)
            {
                txt_Age.Text = Data.Age.ToString();
                ageOK        = true;
            }
            ///both are needed to avoid issues dues to default false data
            if (Data.isFemale && !Data.isMale)
            {
                rbtn_female.Checked = true;
                sexOK = true;
            }
            if (Data.isMale && !Data.isFemale)
            {
                rbtn_male.Checked = true;
                sexOK             = true;
            }
            string Data_Step = Data.TestStepHigh.ToString();

            if (Data_Step != "0")
            {
                combo_stephight.Text = Data_Step.Remove(0, 1);
                ///remove the underscore in the StepHigh enum
                stepOK = true;
            }
            if (Data.stepOfTheTest != StepOfTheTest.init)
            {
                combo_stephight.Hide();
                lbl_stephigh.Text += Data.TestStepHigh.ToString().Remove(0, 1);
                txt_Age.Enabled    = false;
                /// if test has begun make components uneditable because it could cause issue to the test
            }
        }
Exemple #4
0
        public Double getAerobicCapacity(CurrentTest Data, int valid, int invalid, int Xvalid)
        ///get the aerobic capacity when only one data is valid
        {
            List <int> list = new List <int> {
                valid, invalid
            }.ToList();
            ///Create a list with both HR values
            int max = list.Max();
            int min = list.Min();
            ///get the highest and lowest
            int maxX = getY(Data, max);
            int minX = getY(Data, min);
            //get the associated X value

            double coeficient = (max - min) / (maxX - minX);
            ///Calculate the slope of the right

            double origin = valid - Xvalid * coeficient;

            ///get the origin of the right to have the equation
            return((Data.maxHR - origin) / coeficient);
        }
Exemple #5
0
        public void updateXList(CurrentTest Data)
        {
            /// retunr the list of X value associated with the step high
            switch (Data.TestStepHigh)
            {
            case StepHigh._15:
                Data.Xvalues.AddRange(new[] { 11, 14, 18, 21, 25 }.ToList());
                break;

            case StepHigh._20:
                Data.Xvalues.AddRange(new[] { 12, 17, 21, 25, 29 }.ToList());
                break;

            case StepHigh._25:
                Data.Xvalues.AddRange(new[] { 14, 19, 24, 28, 33 }.ToList());
                break;

            case StepHigh._30:
                Data.Xvalues.AddRange(new[] { 16, 21, 27, 32, 37 }.ToList());
                break;
            }
        }
Exemple #6
0
 public int getY(CurrentTest Data, int X)
 ///Search the Y value associates with one HR.
 {
     if (X == Data.HR1)
     {
         return(Data.Xvalues[0]);
     }
     else if (X == Data.HR2)
     {
         return(Data.Xvalues[1]);
     }
     else if (X == Data.HR3)
     {
         return(Data.Xvalues[2]);
     }
     else if (X == Data.HR4)
     {
         return(Data.Xvalues[3]);
     }
     else
     {
         return(Data.Xvalues[4]);
     }
 }
        private void btn_import_Click(object sender, EventArgs e)
        {
            string fileContent = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            ///Open the dialog to select the file
            {
                openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                //only accept txt files
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Read the contents of the file into a stream
                    var fileStream = openFileDialog.OpenFile();

                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        fileContent = reader.ReadToEnd();
                        //put the content to a string
                    }
                }
            }
            string[] Separators   = new string[] { "\n" };
            string[] participants = fileContent.Split(Separators, StringSplitOptions.None);
            //split all tge lines
            foreach (string line in participants)
            {
                string[] word = line.Split(char.Parse(";"));
                //split all the data
                CurrentTest Test = new CurrentTest();
                //create a new test
                //Save data from file to data
                Test.Name = word[0];
                int  num;
                bool result;
                result = int.TryParse(word[1], out num);
                if (result)
                {
                    Test.Age = num;
                }
                if (word[2] == "Male" || word[2] == "male" || word[2] == "M")
                {
                    Test.isFemale = false;
                    Test.isMale   = true;
                }
                else if (word[2] == "Female" || word[2] == "female" || word[2] == "F")
                {
                    Test.isFemale = true;
                    Test.isMale   = false;
                }
                result = int.TryParse(word[3], out num);
                if (result)
                {
                    if (num == 15 || num == 20 || num == 25 || num == 30)
                    {
                        Test.TestStepHigh = (StepHigh)num;
                    }
                }
                TestInAction.Add(Test);
            }
            updateList();
        }