Esempio n. 1
0
        static void Main(string[] args)
        {
            var population = new List <DataObject>();

            for (int i = 0; i < 10000; i++)
            {
                var obj = DataObject.CreateRandomObject();
                population.Add(obj);
            }

            var verifier = new GenericDataProcessor <DataObject>();

            // adding contraints the list
            Predicate <DataObject> nameIsNotNull = NameIsNotNull;
            Predicate <DataObject> genderIsKnown = GenderIsKnown;

            verifier.AddDataConstraint(nameIsNotNull);
            verifier.AddDataConstraint(genderIsKnown);

            // filtering the population
            verifier.AddDataFiltered(population);
            double unhealthyWomen = verifier.Execute(fracktionOfUnhealthyFemalesAgedBtween30_50);

            Console.WriteLine("fraction of unhealthy women As double: " + unhealthyWomen + "\tAs an approximate fraction: " + unhealthyWomen.ToFractions(2000));
            double healthyMen = verifier.Execute(fractionOfHealthyMalesAgedBetween75_90);

            Console.WriteLine("\nfraction of healthy men As double: " + healthyMen + "\tAs an approximate fraction: " + healthyMen.ToFractions(2000));
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var population = new List <DataObject>();

            for (int i = 0; i < 10000; i++)
            {
                var obj = DataObject.CreateRandomObject();
                population.Add(obj);
            }

            var verifier = new GenericDataProcessor <DataObject>();

            // Add valid population data.

            verifier.AddDataConstraint(new Predicate <DataObject>(d => d.Gender != null && d.Gender != EGender.Unknown));
            verifier.AddDataConstraint(new Predicate <DataObject>(d => d.Name != null && d.Name != ""));

            verifier.AddDataFiltered(population);

            var countOfValids = verifier.Execute <int>(data => data.Count);

            Console.WriteLine($"Of these 10000 people, {countOfValids} people have valid data available.");

            // Unhealthy females in the age group of 30 – 50.

            var femaleVerifier = new GenericDataProcessor <DataObject>();

            femaleVerifier.AddDataConstraint(new Predicate <DataObject>(d => d.Gender == EGender.Female));
            femaleVerifier.AddDataConstraint(new Predicate <DataObject>(d => d.Name != null && d.Name != ""));
            femaleVerifier.AddDataConstraint(new Predicate <DataObject>(d => !d.IsHealthy));
            femaleVerifier.AddDataConstraint(new Predicate <DataObject>(d => d.Age >= 30 && d.Age <= 50));

            femaleVerifier.AddDataFiltered(population);

            var countOfFilteredListFemale = femaleVerifier.Execute <int>(data => data.Count);

            Console.WriteLine($"Of these 10000 people, {countOfFilteredListFemale} are females (with valid data) between the age of 30 and 50 are unhealthy.");

            // Healthy males in the age group 75 - 90.

            var maleVerifier = new GenericDataProcessor <DataObject>();

            maleVerifier.AddDataConstraint(new Predicate <DataObject>(d => d.Gender == EGender.Male));
            maleVerifier.AddDataConstraint(new Predicate <DataObject>(d => d.Name != null && d.Name != ""));
            maleVerifier.AddDataConstraint(new Predicate <DataObject>(d => d.IsHealthy));
            maleVerifier.AddDataConstraint(new Predicate <DataObject>(d => d.Age >= 75 && d.Age <= 90));

            maleVerifier.AddDataFiltered(population);

            var countOfFilteredListMale = maleVerifier.Execute <int>(data => data.Count);

            Console.WriteLine($"Of these 10000 people, {countOfFilteredListMale} are males (with valid data) between the age of 75 and 90 are healthy.");
            Console.ReadKey();
        }