public List <Subscription> Generate(SubscriptionConfiguration subscriptionconfiguration, int noOfGenerated)
        {
            noOfMessages = noOfGenerated;
            Percent();
            MinNumbers currentMinNumbers = new MinNumbers()
            {
                PatientNameMinNumber = 0,
                EyeColorMinNumber    = 0,
                DateOfBirthMinNumber = 0,
                HeightMinNumber      = 0,
                HeartRateMinNumber   = 0
            };

            MinEqualNumbers currentMinEqualNumbers = new MinEqualNumbers()
            {
                MinDateOfBirthEquals = 0,
                MinHeartRateEquals   = 0,
                MinHeightEquals      = 0
            };

            subscriptions = new List <Subscription>();

            ///////// generate all subscriptions with one field completed, to avoid empty subscriptions
            string   patientName = "", eyeColor = "";
            DateTime?dateOfBirth = DateTime.Parse("01.01.1900");
            double?  height = 0;
            int?     heartRate = 0;
            Option   dateOfBirthOption = new Option(), heightOption = new Option(), heartRateOption = new Option();
            var      numberOfDaysInDateInterval = (subscriptionconfiguration.MaxDateValue - subscriptionconfiguration.MinDateValue).Days;


            while (minNumbers.PatientNameMinNumber > currentMinNumbers.PatientNameMinNumber)
            {
                // Generate subscription with field "PatientName"
                patientName = subscriptionconfiguration.PatientNames[rnd.Next(subscriptionconfiguration.PatientNames.Count)];

                currentMinNumbers.PatientNameMinNumber++;
                nonEmptySubscriptions += 1;
                var subscription = new Subscription
                {
                    PatientName = patientName,

                    EyeColor = eyeColor,

                    DateOfBirth = dateOfBirthOption,

                    Height = heightOption,

                    HeartRate = heartRateOption
                };

                subscriptions.Add(subscription);
            }

            while (nonEmptySubscriptions < noOfMessages && minNumbers.EyeColorMinNumber > currentMinNumbers.EyeColorMinNumber)
            {
                // Generate subscription with field "EyeColor"
                eyeColor = subscriptionconfiguration.EyeColors[rnd.Next(subscriptionconfiguration.EyeColors.Count)];

                currentMinNumbers.EyeColorMinNumber++;
                nonEmptySubscriptions += 1;
                var subscription = new Subscription
                {
                    PatientName = "",

                    EyeColor = eyeColor,

                    DateOfBirth = dateOfBirthOption,

                    Height = heightOption,

                    HeartRate = heartRateOption
                };

                subscriptions.Add(subscription);
            }


            while (nonEmptySubscriptions < noOfMessages && minNumbers.DateOfBirthMinNumber > currentMinNumbers.DateOfBirthMinNumber)
            {
                // Generate subscription with field "DateOfBirth"
                dateOfBirth = subscriptionconfiguration.MinDateValue.AddDays(rnd.Next(0, numberOfDaysInDateInterval));

                // Generate subcription with option "DateOfBirth","=","..."
                if (dateOfBirth != DateTime.Parse("01.01.1900"))
                {
                    dateOfBirthOption = new Option
                    {
                        Field = "DateOfBirth",
                        Op    = equalOperator,
                        Value = dateOfBirth.ToString()
                    };

                    currentMinEqualNumbers.MinDateOfBirthEquals++;
                    currentMinNumbers.DateOfBirthMinNumber++;

                    nonEmptySubscriptions += 1;
                    var subscription = new Subscription
                    {
                        PatientName = "",

                        EyeColor = "",

                        DateOfBirth = dateOfBirthOption,

                        Height = heightOption,

                        HeartRate = heartRateOption
                    };

                    subscriptions.Add(subscription);
                }
            }


            while (nonEmptySubscriptions < noOfMessages && minNumbers.HeightMinNumber > currentMinNumbers.HeightMinNumber)
            {
                // Generate subscription with field "Height"
                height = Random(subscriptionconfiguration.MinHeightValue, subscriptionconfiguration.MaxHeightValue);


                // Generate subcription with option "Height","=","..."
                if (height != 0)
                {
                    heightOption = new Option
                    {
                        Field = "Height",
                        Op    = equalOperator,
                        Value = height.ToString()
                    };

                    currentMinEqualNumbers.MinHeightEquals++;
                    currentMinNumbers.HeightMinNumber++;
                    nonEmptySubscriptions += 1;
                    var subscription = new Subscription
                    {
                        PatientName = "",

                        EyeColor = "",

                        DateOfBirth = new Option(),

                        Height = heightOption,

                        HeartRate = heartRateOption
                    };

                    subscriptions.Add(subscription);
                }
            }

            while (nonEmptySubscriptions < noOfMessages && minNumbers.HeartRateMinNumber > currentMinNumbers.HeartRateMinNumber)
            {
                // Generate subscription with field "HeartRate"
                heartRate = Random(subscriptionconfiguration.MinHeartRateValue, subscriptionconfiguration.MaxHeartRateValue);

                // Generate subcription with option "HeartRate","=","..."
                if (height != 0)
                {
                    heartRateOption = new Option
                    {
                        Field = "HeartRate",
                        Op    = equalOperator,
                        Value = heartRate.ToString()
                    };

                    currentMinEqualNumbers.MinHeartRateEquals++;
                    currentMinNumbers.HeartRateMinNumber++;
                    nonEmptySubscriptions += 1;
                    var subscription = new Subscription
                    {
                        PatientName = "",

                        EyeColor = "",

                        DateOfBirth = new Option(),

                        Height = new Option(),

                        HeartRate = heartRateOption
                    };

                    subscriptions.Add(subscription);
                }
            }


            ////complete fields to reach percentage

            for (var i = 0; i < noOfMessages; i++)
            {
                patientName       = ""; eyeColor = "";
                dateOfBirth       = DateTime.Parse("01.01.1900");
                height            = 0;
                heartRate         = 0;
                dateOfBirthOption = new Option();
                heightOption      = new Option();
                heartRateOption   = new Option();

                #region Generate subscription with the required occurence percentage for each field

                numberOfDaysInDateInterval = (subscriptionconfiguration.MaxDateValue - subscriptionconfiguration.MinDateValue).Days;


                if (minNumbers.EyeColorMinNumber > currentMinNumbers.EyeColorMinNumber)
                {
                    // Generate subscription with field "EyeColor"
                    eyeColor = subscriptionconfiguration.EyeColors[rnd.Next(subscriptionconfiguration.EyeColors.Count)];

                    currentMinNumbers.EyeColorMinNumber++;
                    subscriptions[i].EyeColor = eyeColor;
                }
                if (minNumbers.DateOfBirthMinNumber > currentMinNumbers.DateOfBirthMinNumber)
                {
                    // Generate subscription with field "DateOfBirth"
                    dateOfBirth = subscriptionconfiguration.MinDateValue.AddDays(rnd.Next(0, numberOfDaysInDateInterval));
                }
                if (minNumbers.HeightMinNumber > currentMinNumbers.HeightMinNumber)
                {
                    // Generate subscription with field "Height"
                    height = Random(subscriptionconfiguration.MinHeightValue, subscriptionconfiguration.MaxHeightValue);
                }
                if (minNumbers.HeartRateMinNumber > currentMinNumbers.HeartRateMinNumber)
                {
                    // Generate subscription with field "HeartRate"
                    heartRate = Random(subscriptionconfiguration.MinHeartRateValue, subscriptionconfiguration.MaxHeartRateValue);
                }

                #endregion Generate subscription with the required occurence percentage for each field

                #region Generate subscription with the required occurence percentage of operator "="

                if (minEqualNumbers.MinDateOfBirthEquals > currentMinEqualNumbers.MinDateOfBirthEquals)
                {
                    // Generate subcription with option "DateOfBirth","=","..."
                    if (dateOfBirth != DateTime.Parse("01.01.1900"))
                    {
                        dateOfBirthOption = new Option
                        {
                            Field = "DateOfBirth",
                            Op    = equalOperator,
                            Value = dateOfBirth.ToString()
                        };

                        currentMinEqualNumbers.MinDateOfBirthEquals++;
                        currentMinNumbers.DateOfBirthMinNumber++;

                        subscriptions[i].DateOfBirth = dateOfBirthOption;
                    }
                }
                else if (minNumbers.DateOfBirthMinNumber > currentMinNumbers.DateOfBirthMinNumber)
                {
                    dateOfBirthOption = new Option
                    {
                        Field = "DateOfBirth",
                        Op    = operators[rnd.Next(operators.Count)],
                        Value = dateOfBirth.ToString()
                    };
                    currentMinNumbers.DateOfBirthMinNumber++;

                    subscriptions[i].DateOfBirth = dateOfBirthOption;
                }

                if (minEqualNumbers.MinHeightEquals > currentMinEqualNumbers.MinHeightEquals)
                {
                    // Generate subcription with option "Height","=","..."
                    if (height != 0)
                    {
                        heightOption = new Option
                        {
                            Field = "Height",
                            Op    = equalOperator,
                            Value = height.ToString()
                        };

                        currentMinEqualNumbers.MinHeightEquals++;
                        currentMinNumbers.HeightMinNumber++;

                        subscriptions[i].Height = heightOption;
                    }
                }
                else if (minNumbers.HeightMinNumber > currentMinNumbers.HeightMinNumber)
                {
                    heightOption = new Option
                    {
                        Field = "Height",
                        Op    = operators[rnd.Next(operators.Count)],
                        Value = height.ToString()
                    };
                    currentMinNumbers.HeightMinNumber++;

                    subscriptions[i].Height = heightOption;
                }
                if (minEqualNumbers.MinHeartRateEquals > currentMinEqualNumbers.MinHeartRateEquals)
                {
                    // Generate subcription with option "HeartRate","=","..."
                    if (height != 0)
                    {
                        heartRateOption = new Option
                        {
                            Field = "HeartRate",
                            Op    = equalOperator,
                            Value = heartRate.ToString()
                        };

                        currentMinEqualNumbers.MinHeartRateEquals++;
                        currentMinNumbers.HeartRateMinNumber++;
                        subscriptions[i].HeartRate = heartRateOption;
                    }
                }
                else if (minNumbers.HeartRateMinNumber > currentMinNumbers.HeartRateMinNumber)
                {
                    heartRateOption = new Option
                    {
                        Field = "HeartRate",
                        Op    = operators[rnd.Next(operators.Count)],
                        Value = heartRate.ToString()
                    };
                    currentMinNumbers.HeartRateMinNumber++;
                    subscriptions[i].HeartRate = heartRateOption;
                }
                #endregion Generate subscription with the required occurence percentage of operator "="
            }

            return(subscriptions);
        }
Пример #2
0
        public List <Subscription> Generate(SubscriptionConfiguration subscriptionconfiguration, int noOfMessages)
        {
            MinNumbers currentMinNumbers = new MinNumbers()
            {
                PatientNameMinNumber = 0,
                EyeColorMinNumber    = 0,
                DateOfBirthMinNumber = 0,
                HeightMinNumber      = 0,
                HeartRateMinNumber   = 0
            };

            MinEqualNumbers currentMinEqualNumbers = new MinEqualNumbers()
            {
                MinDateOfBirthEquals = 0,
                MinHeartRateEquals   = 0,
                MinHeightEquals      = 0
            };

            subscriptions = new List <Subscription>();

            for (var i = 0; i < noOfMessages; i++)
            {
                string   patientName = "", eyeColor = "";
                DateTime?dateOfBirth = DateTime.Parse("01.01.1900");
                double?  height = 0;
                int?     heartRate = 0;
                Option   dateOfBirthOption = new Option(), heightOption = new Option(), heartRateOption = new Option();

                #region Generate subscription with the required occurence percentage for each field

                var numberOfDaysInDateInterval = (subscriptionconfiguration.MaxDateValue - subscriptionconfiguration.MinDateValue).Days;

                if (minNumbers.PatientNameMinNumber > currentMinNumbers.PatientNameMinNumber)
                {
                    // Generate subscription with field "PatientName"
                    patientName = subscriptionconfiguration.PatientNames[rnd.Next(subscriptionconfiguration.PatientNames.Count)];

                    currentMinNumbers.PatientNameMinNumber++;
                }
                if (minNumbers.EyeColorMinNumber > currentMinNumbers.EyeColorMinNumber)
                {
                    // Generate subscription with field "EyeColor"
                    eyeColor = subscriptionconfiguration.EyeColors[rnd.Next(subscriptionconfiguration.EyeColors.Count)];

                    currentMinNumbers.EyeColorMinNumber++;
                }
                if (minNumbers.DateOfBirthMinNumber > currentMinNumbers.DateOfBirthMinNumber)
                {
                    // Generate subscription with field "DateOfBirth"
                    dateOfBirth = subscriptionconfiguration.MinDateValue.AddDays(rnd.Next(0, numberOfDaysInDateInterval));

                    currentMinNumbers.DateOfBirthMinNumber++;
                }
                if (minNumbers.HeightMinNumber > currentMinNumbers.HeightMinNumber)
                {
                    // Generate subscription with field "Height"
                    height = Random(subscriptionconfiguration.MinHeightValue, subscriptionconfiguration.MaxHeightValue);

                    currentMinNumbers.HeightMinNumber++;
                }
                if (minNumbers.HeartRateMinNumber > currentMinNumbers.HeartRateMinNumber)
                {
                    // Generate subscription with field "HeartRate"
                    heartRate = Random(subscriptionconfiguration.MinHeartRateValue, subscriptionconfiguration.MaxHeartRateValue);

                    currentMinNumbers.HeartRateMinNumber++;
                }

                #endregion Generate subscription with the required occurence percentage for each field

                #region Generate subscription with the required occurence percentage of operator "="

                if (minEqualNumbers.MinDateOfBirthEquals > currentMinEqualNumbers.MinDateOfBirthEquals)
                {
                    // Generate subcription with option "DateOfBirth","=","..."
                    if (dateOfBirth != DateTime.Parse("01.01.1900"))
                    {
                        dateOfBirthOption = new Option
                        {
                            Field = "DateOfBirth",
                            Op    = equalOperator,
                            Value = dateOfBirth.ToString()
                        };

                        currentMinEqualNumbers.MinDateOfBirthEquals++;
                    }
                    else
                    {
                        dateOfBirthOption = new Option
                        {
                            Field = "DateOfBirth",
                            Op    = operators[rnd.Next(operators.Count)],
                            Value = dateOfBirth.ToString()
                        };
                    }
                }
                if (minEqualNumbers.MinHeightEquals > currentMinEqualNumbers.MinHeightEquals)
                {
                    // Generate subcription with option "Height","=","..."
                    if (height != 0)
                    {
                        heightOption = new Option
                        {
                            Field = "Height",
                            Op    = equalOperator,
                            Value = height.ToString()
                        };

                        currentMinEqualNumbers.MinHeightEquals++;
                    }
                    else
                    {
                        heightOption = new Option
                        {
                            Field = "Height",
                            Op    = operators[rnd.Next(operators.Count)],
                            Value = height.ToString()
                        };
                    }
                }
                if (minEqualNumbers.MinHeartRateEquals > currentMinEqualNumbers.MinHeartRateEquals)
                {
                    // Generate subcription with option "HeartRate","=","..."
                    if (height != 0)
                    {
                        heartRateOption = new Option
                        {
                            Field = "HeartRate",
                            Op    = equalOperator,
                            Value = heartRate.ToString()
                        };

                        currentMinEqualNumbers.MinHeartRateEquals++;
                    }
                    else
                    {
                        heartRateOption = new Option
                        {
                            Field = "HeartRate",
                            Op    = operators[rnd.Next(operators.Count)],
                            Value = heartRate.ToString()
                        };
                    }
                }

                #endregion Generate subscription with the required occurence percentage of operator "="

                var subscription = new Subscription
                {
                    PatientName = subscriptionconfiguration.PatientNames[rnd.Next(subscriptionconfiguration.PatientNames.Count)],

                    EyeColor = subscriptionconfiguration.EyeColors[rnd.Next(subscriptionconfiguration.EyeColors.Count)],

                    DateOfBirth = dateOfBirthOption,

                    Height = heightOption,

                    HeartRate = heartRateOption
                };

                subscriptions.Add(subscription);
            }

            return(subscriptions);
        }