Ejemplo n.º 1
0
        private void CreateNewAccount()
        {
            using (BrainGameDBEntities3 context = new BrainGameDBEntities3())
            {
                try
                {
                    bool usernameIsUnique = true;
                    CheckIfTheUsernameIsUnique(context, out usernameIsUnique);
                    if (usernameIsUnique)
                    {
                        Users currentUser = new Users();
                        currentUser.Username = tbxUsername.Text;
                        currentUser.Password = tbxPassword.Text;

                        context.Users.Add(currentUser);
                        context.SaveChanges();
                        MessageBox.Show("Your account has been successfully created.");
                        OpenGame(currentUser.Id);
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage(ex);
                }
            }
        }
Ejemplo n.º 2
0
        private void btnDemoAccount_Click(object sender, EventArgs e)
        {
            MessageBox.Show("The account with the username = \"aaaaaa\" and with the password = \"aaaaaa\" will be oppened from the database.\nYou can also connect to this game manually, using this account.\nPlease make sure that you have already created the database by using the Sql query given in the file \"BrainGameDB.sql\".");
            int id = 1;

            try
            {
                using (BrainGameDBEntities3 context = new BrainGameDBEntities3())
                {
                    var selected = context.Users
                                   .Where(x => x.Username == "aaaaaa")
                                   .Select(x => x.Id).ToList();

                    foreach (int item in selected)
                    {
                        id = item;
                    }
                }
                OpenGame(id);
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }
 private void CreateTheDailyRateLists(BrainGameDBEntities3 context)
 {
     AsignTheDailyRatesAtIndexZero(context);
     CreateTheDatesAndTheRatesAtOperator(context);
     CreateTheDatesAndTheRatesAtDigit(context);
     CompleteTheDayDifferenceBetweenDates();
 }
        private void EndGame()
        {
            btnEndGame.Text = "Restart";
            this.Sw.Stop();
            tbxResult.Enabled     = false;
            btnStatistics.Enabled = true;
            tbxOne.Text           = "";
            tbxTwo.Text           = "";
            tbxSeconds.Text       = "";
            tbxResult.Text        = "";
            tbxEqual.Text         = "";
            tbxSign.Text          = "";

            try
            {
                using (BrainGameDBEntities3 context = new BrainGameDBEntities3())
                {
                    foreach (Results item in this.ResultsList)
                    {
                        context.Results.Add(item);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show("We are sorry, but there was a problem saving your results in the database");
            }

            this.ResultsList = new List <Results>();
        }
        private void CreateTheDatesAndTheRatesAtDigit(BrainGameDBEntities3 context)
        {
            for (int i = 1; i <= numberOfDigits; i++) // 4 signs >> + , - , x , /
            {
                var selectDirect =
                    from results in context.Results
                    where results.UserId == this.userId
                    select new
                {
                    FirstNumber  = results.FirstNumber,
                    SecondNumber = results.SecondNumber,
                    Date         = results.Date
                };

                var selected =
                    from results in selectDirect.AsEnumerable()
                    where NumberOfDigitsEqualsWith(Math.Max((int)results.FirstNumber, (int)results.SecondNumber), i)
                    select results.Date;

                List <DateTime> currentDateTimeList = selected.ToList();
                currentDateTimeList = currentDateTimeList.Distinct().ToList();
                currentDateTimeList = currentDateTimeList.OrderBy(x => x.Date).ToList();

                List <int> currentRateList = new List <int>();
                foreach (DateTime currentDay in currentDateTimeList)
                {
                    var selectedTwoDirect =
                        from results in context.Results
                        where results.Date == currentDay
                        where results.UserId == this.userId
                        select new
                    {
                        FirstNumber  = results.FirstNumber,
                        SecondNumber = results.SecondNumber,
                        Succeeded    = results.Succeeded
                    };


                    var selectedTwo =
                        from results in selectedTwoDirect.AsEnumerable()
                        where NumberOfDigitsEqualsWith(Math.Max((int)results.FirstNumber, (int)results.SecondNumber), i)
                        select results.Succeeded;

                    List <bool> currentBoolList = new List <bool>();
                    foreach (bool currentBool in selectedTwo)
                    {
                        currentBoolList.Add(currentBool);
                    }
                    int currentRate = GetTheRate(currentBoolList);
                    currentRateList.Add(currentRate);
                }
                DailyRate currentDailyRateDigit = new DailyRate();
                currentDailyRateDigit.Dates = currentDateTimeList;
                currentDailyRateDigit.Rates = currentRateList;

                this.DailyRateDigit.Add(currentDailyRateDigit);
            }
        }
Ejemplo n.º 6
0
        private void ExecuteSignIn()
        {
            bool heEnteredAUsernameAndAPassword =
                tbxUsername.Text != "Username" && tbxUsername.Text != "" &&
                tbxPassword.Text != "Password" && tbxPassword.Text != "";

            if (!heEnteredAUsernameAndAPassword)
            {
                MessageBox.Show("Please enter your Username and your Password.", "Sign in");
            }
            else
            {
                using (BrainGameDBEntities3 context = new BrainGameDBEntities3())
                {
                    List <Users> users = context.Users.ToList();

                    if (users.Count == 0)
                    {
                        MessageBox.Show("You have no account. Please create a new account.");
                    }
                    else
                    {
                        bool userFound = false;
                        foreach (Users item in users)
                        {
                            if (item.Username == tbxUsername.Text)
                            {
                                userFound = true;
                                if (item.Password == tbxPassword.Text)
                                {
                                    try
                                    {
                                        OpenGame(item.Id);
                                    }
                                    catch (Exception ex)
                                    {
                                        ShowErrorMessage(ex);
                                    }

                                    break;
                                }
                                else
                                {
                                    MessageBox.Show("The password that you entered does not match the username.");
                                    break;
                                }
                            }
                        }
                        if (!userFound)
                        {
                            MessageBox.Show("Sorry, but Brain Computer doesn't recognise your email.");
                        }
                    }
                }
            }
        }
        public float[,] TimeMatrix { get; set; }   // x.Axis = number of digits => 0, 1, 2, 3, 4 (0 is the TOTAL, 1 is for 1 digit)
                                                   // y.Axis = operator index => 0, 1, 2, 3, 4 (0 is the TOTAL, 1 is for PLUS)
        #endregion Properties

        #region Constructors
        public EngineStatistics(int personId)
        {
            this.userId = personId;
            InitializeLists();

            using (BrainGameDBEntities3 context = new BrainGameDBEntities3())
            {
                CompleteTheFirstTenLists(context);
                CompleteTheDoubleLists();
                CreateTheDailyRateLists(context);
                CompleteTheTimeMatrix(context);
            }
        }
        }                                          // x.Axis = number of digits => 0, 1, 2, 3, 4 (0 is the TOTAL, 1 is for 1 digit)
                                                   // y.Axis = operator index => 0, 1, 2, 3, 4 (0 is the TOTAL, 1 is for PLUS)
        #endregion Properties

        #region Constructors
        public EngineStatistics(int personId)
        {
            this.userId = personId;
            InitializeLists();

            using (BrainGameDBEntities3 context = new BrainGameDBEntities3())
            {
                CompleteTheFirstTenLists(context);
                CompleteTheDoubleLists();
                CreateTheDailyRateLists(context);
                CompleteTheTimeMatrix(context);
            }
        }
Ejemplo n.º 9
0
        private void CheckIfTheUsernameIsUnique(BrainGameDBEntities3 context, out bool usernameIsUnique)
        {
            usernameIsUnique = true;
            List <Users> users = context.Users.ToList();

            foreach (Users item in users)
            {
                if (item.Username == tbxUsername.Text)
                {
                    MessageBox.Show("The username that you've chosen already exists.\nPlease try another one.");
                    usernameIsUnique = false;
                    break;
                }
            }
        }
        private void CreateTheDatesAndTheRatesAtOperator(BrainGameDBEntities3 context)
        {
            for (int i = 1; i <= 4; i++) // 4 signs >> + , - , x , /
            {
                var selected =
                    from results in context.Results
                    where results.Operation == i
                    where results.UserId == this.userId
                    select results.Date;


                List <DateTime> currentDateTimeList = selected.ToList();
                currentDateTimeList = currentDateTimeList.Distinct().ToList();
                currentDateTimeList = currentDateTimeList.OrderBy(x => x.Date).ToList();


                List <int> currentRateList = new List <int>();
                foreach (DateTime currentDay in currentDateTimeList)
                {
                    var selectedTwo =
                        from results in context.Results
                        where results.Operation == i
                        where results.Date == currentDay
                        where results.UserId == this.userId
                        select results.Succeeded;

                    List <bool> currentBoolList = new List <bool>();
                    foreach (bool currentBool in selectedTwo)
                    {
                        currentBoolList.Add(currentBool);
                    }
                    int currentRate = GetTheRate(currentBoolList);
                    currentRateList.Add(currentRate);
                }
                DailyRate currentDailyRateOperator = new DailyRate();
                currentDailyRateOperator.Dates = currentDateTimeList;
                currentDailyRateOperator.Rates = currentRateList;

                this.DailyRateOperator.Add(currentDailyRateOperator);
            }
        }
        private void AsignTheDailyRatesAtIndexZero(BrainGameDBEntities3 context)
        {
            this.DailyRateDigit    = new List <DailyRate>();
            this.DailyRateOperator = new List <DailyRate>();

            var select =
                from results in context.Results
                where results.UserId == this.userId
                select results.Date;

            List <DateTime> currentDateTimeList = select.ToList();

            currentDateTimeList = currentDateTimeList.Distinct().ToList();
            currentDateTimeList = currentDateTimeList.OrderBy(x => x.Date).ToList();

            List <int> currentRateList = new List <int>();

            foreach (DateTime currentDay in currentDateTimeList)
            {
                var selectTwo =
                    from results in context.Results
                    where results.Date == currentDay
                    where results.UserId == this.userId
                    select results.Succeeded;

                int currentRate = GetTheRate(selectTwo.ToList());
                currentRateList.Add(currentRate);
            }
            this.DailyRateDigit.Add(new DailyRate()
            {
                Dates = currentDateTimeList, Rates = currentRateList
            });
            this.DailyRateOperator.Add(new DailyRate()
            {
                Dates = currentDateTimeList, Rates = currentRateList
            });
        }
        private void btnDemoAccount_Click(object sender, EventArgs e)
        {
            MessageBox.Show("The account with the username = \"aaaaaa\" and with the password = \"aaaaaa\" will be oppened from the database.\nYou can also connect to this game manually, using this account.\nPlease make sure that you have already created the database by using the Sql query given in the file \"BrainGameDB.sql\".");
            int id = 1;

            try
            {
                using (BrainGameDBEntities3 context = new BrainGameDBEntities3())
                {
                    var selected = context.Users
                        .Where(x => x.Username == "aaaaaa")
                        .Select(x => x.Id).ToList();

                    foreach (int item in selected)
                    {
                        id = item;
                    }
                }
                OpenGame(id);
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }
        private void CheckIfTheUsernameIsUnique(BrainGameDBEntities3 context, out bool usernameIsUnique)
        {
            usernameIsUnique = true;
            List<Users> users = context.Users.ToList();

            foreach (Users item in users)
            {
                if (item.Username == tbxUsername.Text)
                {
                    MessageBox.Show("The username that you've chosen already exists.\nPlease try another one.");
                    usernameIsUnique = false;
                    break;
                }
            }
        }
        private void CreateNewAccount()
        {
            using (BrainGameDBEntities3 context = new BrainGameDBEntities3())
            {
                try
                {
                    bool usernameIsUnique = true;
                    CheckIfTheUsernameIsUnique(context, out usernameIsUnique);
                    if (usernameIsUnique)
                    {
                        Users currentUser = new Users();
                        currentUser.Username = tbxUsername.Text;
                        currentUser.Password = tbxPassword.Text;

                        context.Users.Add(currentUser);
                        context.SaveChanges();
                        MessageBox.Show("Your account has been successfully created.");
                        OpenGame(currentUser.Id);
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage(ex);
                }

            }
        }
        private void ExecuteSignIn()
        {
            bool heEnteredAUsernameAndAPassword =
                tbxUsername.Text != "Username" && tbxUsername.Text != "" &&
                tbxPassword.Text != "Password" && tbxPassword.Text != "";

            if (!heEnteredAUsernameAndAPassword)
            {
                MessageBox.Show("Please enter your Username and your Password.", "Sign in");
            }
            else
            {
                using (BrainGameDBEntities3 context = new BrainGameDBEntities3())
                {
                    List<Users> users = context.Users.ToList();

                    if (users.Count == 0)
                    {
                        MessageBox.Show("You have no account. Please create a new account.");
                    }
                    else
                    {
                        bool userFound = false;
                        foreach (Users item in users)
                        {
                            if (item.Username == tbxUsername.Text)
                            {
                                userFound = true;
                                if (item.Password == tbxPassword.Text)
                                {
                                    try
                                    {
                                        OpenGame(item.Id);
                                    }
                                    catch (Exception ex)
                                    {
                                        ShowErrorMessage(ex);
                                    }
                                    
                                    break;
                                }
                                else
                                {
                                    MessageBox.Show("The password that you entered does not match the username.");
                                    break;
                                }
                            }
                        }
                        if (!userFound)
                        {
                            MessageBox.Show("Sorry, but Brain Computer doesn't recognise your email.");
                        }
                    }
                }
            }
        }
        private void CompleteTheTimeMatrix(BrainGameDBEntities3 context)
        {
            this.TimeMatrix = new float[numberOfDigits + 1, 5];  // 5 = 4 operators + the TOTAL
            int[,] numberOfEcuations = new int[numberOfDigits + 1, 5];

            var selected =
                from results in context.Results
                where results.Succeeded == true
                where results.UserId == this.userId
                select new
                {
                    FirstNumber = results.FirstNumber,
                    SecondNumber = results.SecondNumber,
                    Operation = results.Operation,
                    Time = results.Time
                };

            foreach (var item in selected)
            {
                int maxNumber = Math.Max((int)item.FirstNumber, (int)item.SecondNumber);
                int digits = maxNumber.ToString().Length;
                int operatorId = item.Operation;

                this.TimeMatrix[digits, operatorId] += (float)item.Time;
                numberOfEcuations[digits, operatorId]++;
            }

            for (int i = 1; i <= numberOfDigits; i++)  // digits
            {
                float currentTimeSum = 0;
                int currentNumberOfItemsSum = 0;

                for (int j = 1; j <= 4; j++)   // operators
                {
                    currentTimeSum += this.TimeMatrix[i, j];
                    currentNumberOfItemsSum += numberOfEcuations[i, j];
                }

                this.TimeMatrix[i, 0] = currentTimeSum;
                numberOfEcuations[i, 0] = currentNumberOfItemsSum;
            }


            for (int i = 0; i <= 4; i++)  // operators
            {
                float currentTimeSum = 0;
                int currentNumberOfItemsSum = 0;

                for (int j = 1; j <= numberOfDigits; j++)  // digits
                {
                    currentTimeSum += this.TimeMatrix[j, i];
                    currentNumberOfItemsSum += numberOfEcuations[j, i];
                }

                this.TimeMatrix[0, i] = currentTimeSum;
                numberOfEcuations[0, i] = currentNumberOfItemsSum;
            }

            for (int i = 0; i <= numberOfDigits; i++)  // digits
            {
                for (int j = 0; j <= 4; j++)   // operators
                {
                    if (numberOfEcuations[i,j] != 0)
                    {
                        this.TimeMatrix[i, j] = this.TimeMatrix[i, j] / numberOfEcuations[i, j];
                    }
                }

            }
        }
        private void CompleteTheFirstTenLists(BrainGameDBEntities3 context)
        {
            // selected contains all the results of the user with the diven Id
            var selected =
                from results in context.Results
                where results.UserId == this.userId
                select new
                {
                    FirstNumber = results.FirstNumber,
                    SecondNumber = results.SecondNumber,
                    Operation = results.Operation,
                    Succeeded = results.Succeeded,
                    Time = results.Time
                };

            // creating these vectors that will help completing the Lists
            int[] plusCorect = new int[numberOfDigits + 1];
            int[] plusFalse = new int[numberOfDigits + 1];
            int[] minusCorect = new int[numberOfDigits + 1];
            int[] minusFalse = new int[numberOfDigits + 1];
            int[] multiplyCorect = new int[numberOfDigits + 1];
            int[] multiplyFalse = new int[numberOfDigits + 1];
            int[] divideCorect = new int[numberOfDigits + 1];
            int[] divideFalse = new int[numberOfDigits + 1];

            // completing the vectors
            foreach (var item in selected)
            {
                int max = Math.Max((int)item.FirstNumber, (int)item.SecondNumber);
                int digits = max.ToString().Length;

                var operation = item.Operation;

                switch ((int)item.Operation)
                {
                    case 1:
                        if (item.Succeeded)
                            plusCorect[digits]++;
                        else
                            plusFalse[digits]++;
                        break;
                    case 2:
                        if (item.Succeeded)
                            minusCorect[digits]++;
                        else
                            minusFalse[digits]++;
                        break;
                    case 3:
                        if (item.Succeeded)
                            multiplyCorect[digits]++;
                        else
                            multiplyFalse[digits]++;
                        break;
                    case 4:
                        if (item.Succeeded)
                            divideCorect[digits]++;
                        else
                            divideFalse[digits]++;
                        break;
                }
            }
            int plusAllCorect = 0;
            int minusAllCorect = 0;
            int multiplyAllCorect = 0;
            int divideAllCorect = 0;

            // completing the Lists
            for (int i = 1; i <= numberOfDigits; i++)
            {
                this.PlusSum.Add(plusCorect[i] + plusFalse[i]);
                this.MinusSum.Add(minusCorect[i] + minusFalse[i]);
                this.MultiplySum.Add(multiplyCorect[i] + multiplyFalse[i]);
                this.DivideSum.Add(divideCorect[i] + divideFalse[i]);
                this.AllOperationsSum.Add(this.PlusSum[i] + this.MinusSum[i] + this.MultiplySum[i] + this.DivideSum[i]);

                if (plusCorect[i] + plusFalse[i] != 0)
                {
                    this.PlusRateCorrect.Add(Procent(plusCorect[i], plusFalse[i]));
                }
                else
                {
                    this.PlusRateCorrect.Add(0);
                }

                if (minusCorect[i] + minusFalse[i] != 0)
                {
                    this.MinusRateCorrect.Add(Procent(minusCorect[i], minusFalse[i]));
                }
                else
                {
                    this.MinusRateCorrect.Add(0);
                }

                if (multiplyCorect[i] + multiplyFalse[i] != 0)
                {
                    this.MultiplyRateCorrect.Add(Procent(multiplyCorect[i], multiplyFalse[i]));
                }
                else
                {
                    this.MultiplyRateCorrect.Add(0);
                }

                if (divideCorect[i] + divideFalse[i] != 0)
                {
                    this.DivideRateCorrect.Add(Procent(divideCorect[i], divideFalse[i]));
                }
                else
                {
                    this.DivideRateCorrect.Add(0);
                }

                if (this.AllOperationsSum[i] != 0)
                {
                    this.AllOperationsRateCorrect.Add((int)Math.Round(100 * (double)(plusCorect[i] + minusCorect[i] + multiplyCorect[i] + divideCorect[i]) / (double)this.AllOperationsSum[i]));
                }
                else
                {
                    this.AllOperationsRateCorrect.Add(0);
                }

                this.PlusSum[0] += this.PlusSum[i];
                this.MinusSum[0] += this.MinusSum[i];
                this.MultiplySum[0] += this.MultiplySum[i];
                this.DivideSum[0] += this.DivideSum[i];
                this.AllOperationsSum[0] += this.AllOperationsSum[i];


                plusAllCorect += plusCorect[i];
                minusAllCorect += minusCorect[i];
                multiplyAllCorect += multiplyCorect[i];
                divideAllCorect += divideCorect[i];
            }

            if (this.PlusSum[0] != 0)
            {
                this.PlusRateCorrect[0] = Procent(plusAllCorect, this.PlusSum[0] - plusAllCorect);
            }

            if (this.MinusSum[0] != 0)
            {
                this.MinusRateCorrect[0] = Procent(minusAllCorect, this.MinusSum[0] - minusAllCorect);
            }

            if (this.MultiplySum[0] != 0)
            {
                this.MultiplyRateCorrect[0] = Procent(multiplyAllCorect, this.MultiplySum[0] - multiplyAllCorect);
            }

            if (this.DivideSum[0] != 0)
            {
                this.DivideRateCorrect[0] = Procent(divideAllCorect, this.DivideSum[0] - divideAllCorect);
            }

            if (this.AllOperationsSum[0] != 0)
            {
                this.AllOperationsRateCorrect[0] = (int)Math.Round(100 * (double)(plusAllCorect + minusAllCorect + multiplyAllCorect + divideAllCorect) / (double)this.AllOperationsSum[0]);
            }



        }
        private void CompleteTheFirstTenLists(BrainGameDBEntities3 context)
        {
            // selected contains all the results of the user with the diven Id
            var selected =
                from results in context.Results
                where results.UserId == this.userId
                select new
            {
                FirstNumber  = results.FirstNumber,
                SecondNumber = results.SecondNumber,
                Operation    = results.Operation,
                Succeeded    = results.Succeeded,
                Time         = results.Time
            };

            // creating these vectors that will help completing the Lists
            int[] plusCorect     = new int[numberOfDigits + 1];
            int[] plusFalse      = new int[numberOfDigits + 1];
            int[] minusCorect    = new int[numberOfDigits + 1];
            int[] minusFalse     = new int[numberOfDigits + 1];
            int[] multiplyCorect = new int[numberOfDigits + 1];
            int[] multiplyFalse  = new int[numberOfDigits + 1];
            int[] divideCorect   = new int[numberOfDigits + 1];
            int[] divideFalse    = new int[numberOfDigits + 1];

            // completing the vectors
            foreach (var item in selected)
            {
                int max    = Math.Max((int)item.FirstNumber, (int)item.SecondNumber);
                int digits = max.ToString().Length;

                var operation = item.Operation;

                switch ((int)item.Operation)
                {
                case 1:
                    if (item.Succeeded)
                    {
                        plusCorect[digits]++;
                    }
                    else
                    {
                        plusFalse[digits]++;
                    }
                    break;

                case 2:
                    if (item.Succeeded)
                    {
                        minusCorect[digits]++;
                    }
                    else
                    {
                        minusFalse[digits]++;
                    }
                    break;

                case 3:
                    if (item.Succeeded)
                    {
                        multiplyCorect[digits]++;
                    }
                    else
                    {
                        multiplyFalse[digits]++;
                    }
                    break;

                case 4:
                    if (item.Succeeded)
                    {
                        divideCorect[digits]++;
                    }
                    else
                    {
                        divideFalse[digits]++;
                    }
                    break;
                }
            }
            int plusAllCorect     = 0;
            int minusAllCorect    = 0;
            int multiplyAllCorect = 0;
            int divideAllCorect   = 0;

            // completing the Lists
            for (int i = 1; i <= numberOfDigits; i++)
            {
                this.PlusSum.Add(plusCorect[i] + plusFalse[i]);
                this.MinusSum.Add(minusCorect[i] + minusFalse[i]);
                this.MultiplySum.Add(multiplyCorect[i] + multiplyFalse[i]);
                this.DivideSum.Add(divideCorect[i] + divideFalse[i]);
                this.AllOperationsSum.Add(this.PlusSum[i] + this.MinusSum[i] + this.MultiplySum[i] + this.DivideSum[i]);

                if (plusCorect[i] + plusFalse[i] != 0)
                {
                    this.PlusRateCorrect.Add(Procent(plusCorect[i], plusFalse[i]));
                }
                else
                {
                    this.PlusRateCorrect.Add(0);
                }

                if (minusCorect[i] + minusFalse[i] != 0)
                {
                    this.MinusRateCorrect.Add(Procent(minusCorect[i], minusFalse[i]));
                }
                else
                {
                    this.MinusRateCorrect.Add(0);
                }

                if (multiplyCorect[i] + multiplyFalse[i] != 0)
                {
                    this.MultiplyRateCorrect.Add(Procent(multiplyCorect[i], multiplyFalse[i]));
                }
                else
                {
                    this.MultiplyRateCorrect.Add(0);
                }

                if (divideCorect[i] + divideFalse[i] != 0)
                {
                    this.DivideRateCorrect.Add(Procent(divideCorect[i], divideFalse[i]));
                }
                else
                {
                    this.DivideRateCorrect.Add(0);
                }

                if (this.AllOperationsSum[i] != 0)
                {
                    this.AllOperationsRateCorrect.Add((int)Math.Round(100 * (double)(plusCorect[i] + minusCorect[i] + multiplyCorect[i] + divideCorect[i]) / (double)this.AllOperationsSum[i]));
                }
                else
                {
                    this.AllOperationsRateCorrect.Add(0);
                }

                this.PlusSum[0]          += this.PlusSum[i];
                this.MinusSum[0]         += this.MinusSum[i];
                this.MultiplySum[0]      += this.MultiplySum[i];
                this.DivideSum[0]        += this.DivideSum[i];
                this.AllOperationsSum[0] += this.AllOperationsSum[i];


                plusAllCorect     += plusCorect[i];
                minusAllCorect    += minusCorect[i];
                multiplyAllCorect += multiplyCorect[i];
                divideAllCorect   += divideCorect[i];
            }

            if (this.PlusSum[0] != 0)
            {
                this.PlusRateCorrect[0] = Procent(plusAllCorect, this.PlusSum[0] - plusAllCorect);
            }

            if (this.MinusSum[0] != 0)
            {
                this.MinusRateCorrect[0] = Procent(minusAllCorect, this.MinusSum[0] - minusAllCorect);
            }

            if (this.MultiplySum[0] != 0)
            {
                this.MultiplyRateCorrect[0] = Procent(multiplyAllCorect, this.MultiplySum[0] - multiplyAllCorect);
            }

            if (this.DivideSum[0] != 0)
            {
                this.DivideRateCorrect[0] = Procent(divideAllCorect, this.DivideSum[0] - divideAllCorect);
            }

            if (this.AllOperationsSum[0] != 0)
            {
                this.AllOperationsRateCorrect[0] = (int)Math.Round(100 * (double)(plusAllCorect + minusAllCorect + multiplyAllCorect + divideAllCorect) / (double)this.AllOperationsSum[0]);
            }
        }
        private void AsignTheDailyRatesAtIndexZero(BrainGameDBEntities3 context)
        {
            this.DailyRateDigit = new List<DailyRate>();
            this.DailyRateOperator = new List<DailyRate>();

            var select =
                from results in context.Results
                where results.UserId == this.userId
                select results.Date;

            List<DateTime> currentDateTimeList = select.ToList();
            currentDateTimeList = currentDateTimeList.Distinct().ToList();
            currentDateTimeList = currentDateTimeList.OrderBy(x => x.Date).ToList();

            List<int> currentRateList = new List<int>();
            foreach (DateTime currentDay in currentDateTimeList)
            {
                var selectTwo =
                    from results in context.Results
                    where results.Date == currentDay
                    where results.UserId == this.userId
                    select results.Succeeded;

                int currentRate = GetTheRate(selectTwo.ToList());
                currentRateList.Add(currentRate);
            }
            this.DailyRateDigit.Add(new DailyRate() { Dates = currentDateTimeList, Rates = currentRateList });
            this.DailyRateOperator.Add(new DailyRate() { Dates = currentDateTimeList, Rates = currentRateList });
        }
 private void CreateTheDailyRateLists(BrainGameDBEntities3 context)
 {
     AsignTheDailyRatesAtIndexZero(context);
     CreateTheDatesAndTheRatesAtOperator(context);
     CreateTheDatesAndTheRatesAtDigit(context);
     CompleteTheDayDifferenceBetweenDates();
 }
        private void CreateTheDatesAndTheRatesAtDigit(BrainGameDBEntities3 context)
        {
            for (int i = 1; i <= numberOfDigits; i++) // 4 signs >> + , - , x , /
            {
                var selectDirect =
                    from results in context.Results
                    where results.UserId == this.userId
                    select new
                    {
                        FirstNumber = results.FirstNumber,
                        SecondNumber = results.SecondNumber,
                        Date = results.Date
                    };

                var selected =
                    from results in selectDirect.AsEnumerable()
                    where NumberOfDigitsEqualsWith(Math.Max((int)results.FirstNumber, (int)results.SecondNumber), i)
                    select results.Date;

                List<DateTime> currentDateTimeList = selected.ToList();
                currentDateTimeList = currentDateTimeList.Distinct().ToList();
                currentDateTimeList = currentDateTimeList.OrderBy(x => x.Date).ToList();

                List<int> currentRateList = new List<int>();
                foreach (DateTime currentDay in currentDateTimeList)
                {
                    var selectedTwoDirect =
                        from results in context.Results
                        where results.Date == currentDay
                        where results.UserId == this.userId
                        select new
                        {
                            FirstNumber = results.FirstNumber,
                            SecondNumber = results.SecondNumber,
                            Succeeded = results.Succeeded
                        };
                        

                    var selectedTwo =
                        from results in selectedTwoDirect.AsEnumerable()
                        where NumberOfDigitsEqualsWith(Math.Max((int)results.FirstNumber, (int)results.SecondNumber), i)
                        select results.Succeeded;

                    List<bool> currentBoolList = new List<bool>();
                    foreach (bool currentBool in selectedTwo)
                    {
                        currentBoolList.Add(currentBool);
                    }
                    int currentRate = GetTheRate(currentBoolList);
                    currentRateList.Add(currentRate);
                }
                DailyRate currentDailyRateDigit = new DailyRate();
                currentDailyRateDigit.Dates = currentDateTimeList;
                currentDailyRateDigit.Rates = currentRateList;

                this.DailyRateDigit.Add(currentDailyRateDigit);
            }
        }
        private void CompleteTheTimeMatrix(BrainGameDBEntities3 context)
        {
            this.TimeMatrix          = new float[numberOfDigits + 1, 5]; // 5 = 4 operators + the TOTAL
            int[,] numberOfEcuations = new int[numberOfDigits + 1, 5];

            var selected =
                from results in context.Results
                where results.Succeeded == true
                where results.UserId == this.userId
                select new
            {
                FirstNumber  = results.FirstNumber,
                SecondNumber = results.SecondNumber,
                Operation    = results.Operation,
                Time         = results.Time
            };

            foreach (var item in selected)
            {
                int maxNumber  = Math.Max((int)item.FirstNumber, (int)item.SecondNumber);
                int digits     = maxNumber.ToString().Length;
                int operatorId = item.Operation;

                this.TimeMatrix[digits, operatorId] += (float)item.Time;
                numberOfEcuations[digits, operatorId]++;
            }

            for (int i = 1; i <= numberOfDigits; i++)  // digits
            {
                float currentTimeSum          = 0;
                int   currentNumberOfItemsSum = 0;

                for (int j = 1; j <= 4; j++)   // operators
                {
                    currentTimeSum          += this.TimeMatrix[i, j];
                    currentNumberOfItemsSum += numberOfEcuations[i, j];
                }

                this.TimeMatrix[i, 0]   = currentTimeSum;
                numberOfEcuations[i, 0] = currentNumberOfItemsSum;
            }


            for (int i = 0; i <= 4; i++)  // operators
            {
                float currentTimeSum          = 0;
                int   currentNumberOfItemsSum = 0;

                for (int j = 1; j <= numberOfDigits; j++)  // digits
                {
                    currentTimeSum          += this.TimeMatrix[j, i];
                    currentNumberOfItemsSum += numberOfEcuations[j, i];
                }

                this.TimeMatrix[0, i]   = currentTimeSum;
                numberOfEcuations[0, i] = currentNumberOfItemsSum;
            }

            for (int i = 0; i <= numberOfDigits; i++) // digits
            {
                for (int j = 0; j <= 4; j++)          // operators
                {
                    if (numberOfEcuations[i, j] != 0)
                    {
                        this.TimeMatrix[i, j] = this.TimeMatrix[i, j] / numberOfEcuations[i, j];
                    }
                }
            }
        }
        private void CreateTheDatesAndTheRatesAtOperator(BrainGameDBEntities3 context)
        {
            for (int i = 1; i <= 4; i++) // 4 signs >> + , - , x , /
            {
                var selected =
                    from results in context.Results
                    where results.Operation == i
                    where results.UserId == this.userId
                    select results.Date;


                List<DateTime> currentDateTimeList = selected.ToList();
                currentDateTimeList = currentDateTimeList.Distinct().ToList();
                currentDateTimeList = currentDateTimeList.OrderBy(x => x.Date).ToList();


                List<int> currentRateList = new List<int>();
                foreach (DateTime currentDay in currentDateTimeList)
                {
                    var selectedTwo =
                        from results in context.Results
                        where results.Operation == i
                        where results.Date == currentDay
                        where results.UserId == this.userId
                        select results.Succeeded;

                    List<bool> currentBoolList = new List<bool>();
                    foreach (bool currentBool in selectedTwo)
                    {
                        currentBoolList.Add(currentBool);
                    }
                    int currentRate = GetTheRate(currentBoolList);
                    currentRateList.Add(currentRate);
                }
                DailyRate currentDailyRateOperator = new DailyRate();
                currentDailyRateOperator.Dates = currentDateTimeList;
                currentDailyRateOperator.Rates = currentRateList;

                this.DailyRateOperator.Add(currentDailyRateOperator);
            }
        }
        private void EndGame()
        {
            btnEndGame.Text = "Restart";
            this.Sw.Stop();
            tbxResult.Enabled = false;
            btnStatistics.Enabled = true;
            tbxOne.Text = "";
            tbxTwo.Text = "";
            tbxSeconds.Text = "";
            tbxResult.Text = "";
            tbxEqual.Text = "";
            tbxSign.Text = "";

            try
            {
                using (BrainGameDBEntities3 context = new BrainGameDBEntities3())
                {
                    foreach (Results item in this.ResultsList)
                    {
                        context.Results.Add(item);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show("We are sorry, but there was a problem saving your results in the database");
            }

            this.ResultsList = new List<Results>();
        }