/// <summary>
        /// Set lblResult text and color by Body Mass Index
        /// </summary>
        /// <param name="pNuBMI"></param>
        /// <param name="pBodyMassIndex"></param>
        private void SetLblResult(float pNuBMI, BodyMassIndex pBodyMassIndex)
        {
            this.view.lblResult.Text = $"Your BMI is {pNuBMI}.\nYou are {pBodyMassIndex}.";

            switch (pBodyMassIndex)
            {
            case (BodyMassIndex.Underweight):
                this.view.lblResult.ForeColor = Color.Blue;
                break;

            case (BodyMassIndex.Normal):
                this.view.lblResult.ForeColor = Color.Green;
                break;

            case (BodyMassIndex.Overweigth):
                this.view.lblResult.ForeColor = Color.Gold;
                break;

            case (BodyMassIndex.Obese):
                this.view.lblResult.ForeColor = Color.Orange;
                break;

            default:     // BodyMassIndex.ExtremellyObese
                this.view.lblResult.ForeColor = Color.Red;
                break;
            }
        }
コード例 #2
0
        public override GenRange Calculate(BodyMassIndex bmi, PersonAge age)
        {
            Range <Rating> rangeForSpeed;

            if (bmi.BMI > 22.8)
            {
                rangeForSpeed = MinRange;
            }
            else if (bmi.BMI < 21.2)
            {
                rangeForSpeed = MaxRange;
            }
            else
            {
                rangeForSpeed = MediumRange;
            }

            // take player age into account
            if (age > PersonAge.FromYears(30))
            {
                rangeForSpeed = new Range <Rating>(rangeForSpeed.Lower * 0.82, rangeForSpeed.Upper * 0.88);
            }
            else if (age < PersonAge.FromYears(23))
            {
                rangeForSpeed = new Range <Rating>(rangeForSpeed.Lower * 1.052, rangeForSpeed.Upper * 1.055);
            }
            return(new GenRange(FeatureType.Acceleration, rangeForSpeed));
        }
コード例 #3
0
 public void New_PassWeightOfZeroKilograms_ShouldThrowBusinessRuleValidationException()
 {
     Assert.ThrowsException <BusinessRuleValidationException>(() =>
     {
         var bmi = new BodyMassIndex(new Length(1, LengthUnit.Meter), new Mass());
     });
 }
コード例 #4
0
        /// <summary>
        /// Validates this MeasurementInformation
        /// </summary>
        /// <param name="path">The path to this object as a string</param>
        /// <param name="messages">the validation messages to date, these may be added to within this method</param>
        public void Validate(string path, List <ValidationMessage> messages)
        {
            var vb = new ValidationBuilder(path, messages);

            if (HeadCircumference == null && BodyHeight == null && BodyMassIndex == null && BodyWeight == null)
            {
                vb.AddValidationMessage("MeasurementInformation", null, "Please provide an entry for MeasurementInformation");
            }

            if (HeadCircumference != null)
            {
                HeadCircumference.Validate(path, messages);
            }

            if (BodyHeight != null)
            {
                BodyHeight.Validate(path, messages);
            }

            if (BodyMassIndex != null)
            {
                BodyMassIndex.Validate(path, messages);
            }

            if (BodyWeight != null)
            {
                BodyWeight.Validate(path, messages);
            }
        }
コード例 #5
0
 public void New_PassHeightOfZeroCentimeters_ShouldThrowBusinessRuleValidationException()
 {
     Assert.ThrowsException <BusinessRuleValidationException>(() =>
     {
         var bmi = new BodyMassIndex(new Length(), new Mass(50, MassUnit.Kilogram));
     });
 }
コード例 #6
0
        public override GenRange Calculate(BodyMassIndex bmi, PersonAge age)
        {
            Range <Rating> rangeForPower;

            if (bmi.BMI > 23 && bmi.Height.Centimeters >= 185)
            {
                rangeForPower = MaxRange;
            }
            else if (bmi.BMI < 22)
            {
                rangeForPower = MinRange;
            }
            else
            {
                rangeForPower = MediumRange;
            }

            // take player's age into account
            if (age > PersonAge.FromYears(25))
            {
                rangeForPower = new Range <Rating>(rangeForPower.Lower * 1.05, rangeForPower.Upper * 1.05);
            }
            else if (age < PersonAge.FromYears(20))
            {
                rangeForPower = new Range <Rating>(rangeForPower.Lower * 0.8, rangeForPower.Upper * 0.9);
            }
            return(new GenRange(FeatureType.Power, rangeForPower));
        }
コード例 #7
0
ファイル: BMICalculator.cs プロジェクト: rdw100/AMESample
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            BodyMassIndex bmi = new BodyMassIndex((double)numWeight.Value, (double)numHeight.Value);

            bmi.CalculateBMI();
            lblBMI.Text = bmi.getBMI().ToString();
        }
コード例 #8
0
ファイル: BodyMassIndexTests.cs プロジェクト: ssfcultra/Katas
 public void BodyMassIndex_Bmi_SampleTest()
 {
     Assert.AreEqual("Normal", BodyMassIndex.Bmi(80, 1.80));
     Assert.AreEqual("Normal", BodyMassIndex.Bmi(80, 1.80));
     Assert.AreEqual("Overweight", BodyMassIndex.Bmi(90, 1.80));
     Assert.AreEqual("Obese", BodyMassIndex.Bmi(110, 1.80));
 }
コード例 #9
0
        public void New_PassValidValues_ShouldReturnNewBmiWithUnderweightRange()
        {
            BodyMassIndex bmi = new BodyMassIndex(new Length(2, LengthUnit.Meter), new Mass(60, MassUnit.Kilogram));

            Assert.IsNotNull(bmi);
            Assert.IsNotNull(bmi.BmiRange);
            Assert.AreEqual(BodyMassIndex.Underweight, bmi.BmiRange);
            Assert.AreEqual(BmiType.Underweight, bmi.BmiType);
        }
コード例 #10
0
 public void mapToTableAttribute()
 {
     this.bmi = new BodyMassIndex();
     this.bmi.setDateBmi(DateTime.Now.Date);
     this.bmi.setWeight(FormUtils.convertDouble(txtWeight.Text));
     this.bmi.setHeight(FormUtils.convertDouble(txtHeight.Text));
     this.bmi.setResult(FormUtils.convertDouble(labResult.Text));
     this.bmi.setEvaluation(bmi.evaluate());
 }
コード例 #11
0
        public Dictionary <String, Object> singleParam(BodyMassIndex bmi)
        {
            Dictionary <String, Object> d = new Dictionary <string, object>()
            {
                { "@DateBmi", bmi.getDateBmi() }
            };

            return(d);
        }
コード例 #12
0
        public PhysicalFeatureSet Generate(PlayerPosition position, BodyMassIndex bmi, Country country, PersonAge playerAge)
        {
            PlayerPositionGenerationRangeDefinition playerPositionGenRange = PlayerPositionGenerationRangeDefinition.GetFromPosition(position);

            ReadOnlyCollection <GenRange> positionGenRanges = playerPositionGenRange.GetGenerationRangeDefinitions();
            ReadOnlyCollection <GenRange> bmiGenRanges      = BodyMassIndexGenerationRangeDefinition.Generate(bmi, playerAge);

            // plages de génération différentes en fonction de
            // - la position du joueur
            // - du BMI
            // - du pays (à voir plus tard)
            // - [TODO] de l'âge du joueur

            PhysicalFeatureSet set = PhysicalFeatureSet.CreateFeatureSet(position.PositionCategory);

            Parallel.ForEach(set.PhysicalFeatures, feature =>
            {
                //	foreach (PhysicalFeature feature in set.PhysicalFeatures)
                //{
                Rating rating;

                GenRange genRangeFromPosition = positionGenRanges.FirstOrDefault(c => c.FeatureType == feature.FeatureType);
                GenRange genRangeFromBmi      = bmiGenRanges.FirstOrDefault(c => c.FeatureType == feature.FeatureType);

                if (genRangeFromBmi != null && genRangeFromPosition != null)
                {
                    Range <Rating> range = Range <Rating> .MergeRanges(new Range <Rating>[]
                    {
                        genRangeFromBmi.RatingRange,
                        genRangeFromPosition.RatingRange
                    });
                    rating = _randomiser.Randomise(range);
                }
                else
                {
                    if (genRangeFromPosition != null)
                    {
                        rating = _randomiser.Randomise(genRangeFromPosition.RatingRange);
                    }
                    else
                    {
                        //if (feature.FeatureType == FeatureType.Morale)
                        //{
                        //	rating = _randomiser.Randomise();
                        //}
                        //else
                        //{
                        rating = _randomiser.Randomise(_youngPlayerFeatureRatingRange);
                        //}
                    }
                }
                feature.ChangeRating(rating);
                //}
            });
            return(set);
        }
コード例 #13
0
        /// <summary>
        /// Validates this PhysicalMeasurementBodyMassIndex item
        /// </summary>
        /// <param name="path">The path to this object as a string</param>
        /// <param name="messages">the validation messages to date, these may be added to within this method</param>
        public void Validate(string path, List <ValidationMessage> messages)
        {
            var vb = new ValidationBuilder(path, messages);

            if (vb.ArgumentRequiredCheck("BodyMassIndex", BodyMassIndex))
            {
                BodyMassIndex.Validate(vb.Path + "BodyMassIndex", vb.Messages);
            }

            if (BodyMassIndexReferenceRangeDetails != null)
            {
                for (var x = 0; x < BodyMassIndexReferenceRangeDetails.Count; x++)
                {
                    BodyMassIndexReferenceRangeDetails[x].Validate(vb.Path + string.Format("BodyMassIndexReferenceRangeDetails[{0}]", x), vb.Messages);
                }
            }

            if (Method != null)
            {
                Method.Validate(vb.Path + "Method", vb.Messages);
            }

            if (InformationProvider != null)
            {
                if (InformationProvider is Device)
                {
                    var device = InformationProvider as Device;
                    device.Validate(vb.Path + "Device", vb.Messages);
                }

                // Both types are of type Participation so use the Participant to determin the type
                if (InformationProvider is Participation)
                {
                    var informationProviderHealthcareProvider = InformationProvider as IParticipationInformationProviderHealthcareProvider;

                    if (informationProviderHealthcareProvider.Participant != null)
                    {
                        informationProviderHealthcareProvider.Validate(vb.Path + "IParticipationInformationProviderHealthcareProvider", vb.Messages);
                    }

                    var informationProviderNonHealthcareProvider = InformationProvider as IParticipationInformationProviderNonHealthcareProvider;

                    if (informationProviderNonHealthcareProvider.Participant != null)
                    {
                        informationProviderNonHealthcareProvider.Validate(vb.Path + "IParticipationInformationProviderNonHealthcareProvider", vb.Messages);
                    }
                }
            }

            vb.ArgumentRequiredCheck("BodyMassIndexDateTime", BodyMassIndexDateTime);

            if (vb.ArgumentRequiredCheck("BodyMassIndexInstanceIdentifier", BodyMassIndexInstanceIdentifier))
            {
                BodyMassIndexInstanceIdentifier.Validate(vb.Path + "BodyMassIndexInstanceIdentifier", vb.Messages);
            }
        }
コード例 #14
0
        private void BtnCalculate_Click(object sender, EventArgs e)
        {
            if (this.ValidateControls())
            {
                float         nuBMI         = this.CalculateBMI(Convert.ToSingle(this.view.txtNuMass.Text), Convert.ToSingle(this.view.txtNuHeight.Text.Replace('.', ',')));
                BodyMassIndex bodyMassIndex = this.GetBodyMassIndex(nuBMI);

                this.SetLblResult(nuBMI, bodyMassIndex);
            }
        }
コード例 #15
0
        public static ReadOnlyCollection <GenRange> Generate(BodyMassIndex bmi, PersonAge age)
        {
            var list = new List <GenRange>();

            list.Add(new BmiRangeForPowerCalculator().Calculate(bmi, age));
            list.Add(new BmiRangeForHeaderCalculator().Calculate(bmi, age));
            list.Add(new BmiRangeForSpeedCalculator().Calculate(bmi, age));
            list.Add(new BmiRangeForAccelerationCalculator().Calculate(bmi, age));

            return(list.AsReadOnly());
        }
コード例 #16
0
ファイル: BodyMassIndexTests.cs プロジェクト: ssfcultra/Katas
 public void BodyMassIndex_Bmi_RandomTest()
 {
     for (int i = 0; i < 100; ++i)
     {
         double weight   = rnd.NextDouble() * 250 + 50;
         double height   = rnd.NextDouble() * 2.5 + 0.5;
         string expected = Solution(weight, height);
         string actual   = BodyMassIndex.Bmi(weight, height);
         Assert.AreEqual(expected, actual);
     }
 }
コード例 #17
0
        public Dictionary <String, Object> parametres(BodyMassIndex bmi)
        {
            Dictionary <String, object> d = new Dictionary <String, Object>()
            {
                { "@Date_Bmi", DateTime.Now.Date },
                { "@Weight", bmi.getWeight() },
                { "@Height", bmi.getHeight() },
                { "@Value", bmi.getResult() },
                { "@Evaluation", bmi.getEvaluation() },
            };

            return(d);
        }
コード例 #18
0
        public string Bmi()
        {
            var bmi = new BodyMassIndex(this.weight, this.height);

            if (bmi.UnderWeight())
            {
                return("You are under weight. You should see your doctor.");
            }
            else if (bmi.OverWeight())
            {
                return("You are over weight. You should see your doctor.");
            }

            return("You are in the correct weight range.");
        }
コード例 #19
0
        public void Classification_GivenDemographicsAndBmiInfo_ReturnsCorrectBmiClassification(
            double bmi, Race race, BodyMassIndex expectecBodyMassIndex)
        {
            var bodyComposition = BodyCompositionBuilder.Initialize()
                                  .SetHeight(LengthConversion.CentimetersToInches(100))
                                  .SetWeight(MassConversion.KilogramsToLbs(bmi))
                                  .BuildWithoutModelValidation();

            var patient = PatientBuilder.Initialize()
                          .SetRace(race)
                          .BuildWithoutModelValidation();

            var result =
                new BodyMassIndexClassification(new BodyCompositionClassificationParameters(bodyComposition, patient))
                .Classification;

            Assert.Equal(expectecBodyMassIndex, result);
        }
コード例 #20
0
        public override GenRange Calculate(BodyMassIndex bmi, PersonAge age)
        {
            Range <Rating> rangeForHeader;

            if (bmi.Height >= _minimuHeightForMaxRange)
            {
                rangeForHeader = MaxRange;
            }
            else if (bmi.Height < _minimuHeightForMinRange)
            {
                rangeForHeader = MinRange;
            }
            else
            {
                rangeForHeader = MediumRange;
            }
            return(new GenRange(FeatureType.Header, rangeForHeader));
        }
        /// <summary>
        /// Validates this MeasurementEntry
        /// </summary>
        /// <param name="path">The path to this object as a string</param>
        /// <param name="messages">the validation messages to date, these may be added to within this method</param>
        public void Validate(string path, List <ValidationMessage> messages)
        {
            var vb = new ValidationBuilder(path, messages);

            if (DocumentLink != null)
            {
                if (DocumentLink != null)
                {
                    DocumentLink.Validate(path, messages);
                }
            }

            if (BodyHeightMeasure != null)
            {
                BodyHeightMeasure.Validate(path, messages);
            }

            if (BodyWeightMeasure != null)
            {
                BodyWeightMeasure.Validate(path, messages);
            }

            if (HeadCircumferenceMeasure != null)
            {
                HeadCircumferenceMeasure.Validate(path, messages);
            }

            if (BodyMassIndex != null)
            {
                BodyMassIndex.Validate(path, messages);
            }

            //if (BodyHeightMeasure == null && BodyWeightMeasure == null && HeadCircumferenceMeasure == null && BodyMassIndex == null)
            //{
            //  vb.AddValidationMessage("Measurement component", null, "Please provide one of the following BodyHeightMeasure or BodyWeightMeasure or HeadCircumferenceMeasure or BodyMassIndex");
            //}

            if (BodyMassIndex != null)
            {
                BodyMassIndex.Validate(path, messages);
            }

            vb.ArgumentRequiredCheck("ObservationDate", ObservationDate);
        }
コード例 #22
0
ファイル: Player.cs プロジェクト: kwentinn/Footballista
 private Player
 (
     PersonId id,
     PersonName name,
     Gender gender,
     BirthInfo birthInfo,
     Foot favouriteFoot,
     BodyMassIndex bmi,
     Percentile percentile,
     PhysicalFeatureSet physicalFeatureSet,
     PlayerPosition playerPosition,
     params Country[] nationalities
 ) : base(id, name, gender, birthInfo, nationalities)
 {
     FavouriteFoot      = favouriteFoot;
     Bmi                = bmi;
     Percentile         = percentile;
     PhysicalFeatureSet = physicalFeatureSet;
     PlayerPosition     = playerPosition;
 }
コード例 #23
0
        public async Task <Player> GenerateAsync(Gender?playerGender = null, Country[] countries = null, PlayerPosition playerPosition = null)
        {
            if (playerGender == null)
            {
                playerGender = _genderGenerator.Generate();
            }

            if (countries == null)
            {
                countries = _countriesGenerator.Generate().Value;
            }

            PersonName playerName = await _nameGenerator.GenerateAsync(
                playerGender.Value,
                countries.FirstOrDefault());

            Date dob = _dobGenerator.Generate();

            PersonAge playerAge = PersonAge.FromDate(dob, _game.CurrentDate);

            Location birthLocation = await _birthLocationGenerator.GenerateAsync(countries.FirstOrDefault());

            Foot               playerFoot       = _favouriteFootGenerator.Generate();
            Percentile         percentile       = _percentileGenerator.Generate();
            BodyMassIndex      bmi              = _bmiGenerator.Generate(countries.FirstOrDefault(), playerGender.Value, percentile, dob);
            PlayerPosition     position         = _playerPositionGenerator.Generate();
            PhysicalFeatureSet playerFeatureSet = _physicalFeatureSetGenerator.Generate(position, bmi, countries.FirstOrDefault(), playerAge);

            // first name & last name => according to the player's country
            return(new PlayerBuilder()
                   .WithName(playerName)
                   .WithGender(playerGender.Value)
                   .WithBirthInfo(new BirthInfo(dob, birthLocation))
                   .WithFoot(playerFoot)
                   .WithPercentile(percentile)
                   .WithBodyMassIndex(bmi)
                   .WithPlayerPosition(position)
                   .WithFeatureSet(playerFeatureSet)
                   .WithCountries(countries)
                   .Build());
        }
コード例 #24
0
ファイル: Player.cs プロジェクト: kwentinn/Footballista
 public static Player CreatePlayer
 (
     PersonName name,
     Gender gender,
     BirthInfo birthInfo,
     Foot favouriteFoot,
     BodyMassIndex bmi,
     Percentile percentile,
     PhysicalFeatureSet physicalFeatureSet,
     PlayerPosition playerPosition,
     params Country[] nationalities
 ) => new Player
 (
     PersonId.CreateNew(),
     name,
     gender,
     birthInfo,
     favouriteFoot,
     bmi,
     percentile,
     physicalFeatureSet,
     playerPosition,
     nationalities
 );
コード例 #25
0
        public void ChangeRating(BodyMassIndex bmi, Rating newRating)
        {
            _bmi = bmi;

            ChangeRating(newRating);
        }
コード例 #26
0
        public void New_PassValidValues_ShouldReturnNewBmi()
        {
            BodyMassIndex bmi = new BodyMassIndex(new Length(1.5, LengthUnit.Meter), new Mass(50, MassUnit.Kilogram));

            Assert.IsNotNull(bmi);
        }
コード例 #27
0
 public BodyFatPercentage(decimal weight, int height, int age, string gender)
 {
     BMI         = new BodyMassIndex(weight, height);
     this.age    = age;
     this.gender = gender == "m" ? 1 : 0;
 }
コード例 #28
0
 public PlayerBuilder WithBodyMassIndex(BodyMassIndex bmi)
 {
     _bmi = bmi;
     return(this);
 }
コード例 #29
0
        public string Bmi()
        {
            var bmi = new BodyMassIndex(this.weight, this.height);
            
            if (bmi.UnderWeight())
            {
                return "You are under weight. You should see your doctor.";
            }
            else if (bmi.OverWeight())
            {
                return "You are over weight. You should see your doctor.";
            }

            return "You are in the correct weight range.";
        }
コード例 #30
0
 public TopSpeedFeature(BodyMassIndex bmi = null, Rating rating = null)
     : base(FeatureType.TopSpeed, rating)
 {
     _bmi = bmi;
 }
コード例 #31
0
        public bool delete(BodyMassIndex bmi)
        {
            bool index = createSQLDelete(FormUtils.loadConfigs("TABLE_BMI"), singleParam(bmi));

            return(index);
        }