Esempio n. 1
0
 public static int calculateAnswer(int leftNum, int rightNum, MathOperation operation)
 {
     if (operation.operationType == MathOperationTypeEnum.ADDITION)
         return leftNum + rightNum;
     else if (operation.operationType == MathOperationTypeEnum.SUBTRACTION)
         return leftNum - rightNum;
     else if (operation.operationType == MathOperationTypeEnum.MULTIPLICATION)
         return leftNum * rightNum;
     else
         return leftNum / rightNum;
 }
Esempio n. 2
0
        /*
         * Starts the chosen daily facts or speed test
         */
        public void startTheFacts(MathOperationTypeEnum sign, Boolean isSpeedTest, Boolean processAllDailyFacts)
        {
            operationType = new MathOperation (sign);

            if (userProfile.Equals (GUEST_PROFILE))
            {
                var confirmResult = MessageBox.Show ("Would you like to create a profile before continuing?\nA profile is required for your progress to be saved.", "Confirm Cancel", MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    createNewUserProfile ();
                }
            }

            // Determine if the user has already used the daily facts today.
            String dateData = files.readDailyFactsDateDataFromFile(operationType.operationType);
            if (dateData == "MAX_TIME_ELAPSED")
            {
                MessageBox.Show ("A month or more has passed since your last speed test.\nPlease retake the " + operationType.ToString () +
                                     "Facts speed test.", "New Speed Test Needed");

                return;
            }
            else if (dateData == DateTime.Today.ToString ("d"))
            {
                saveProgress = false;
                var continueWithoutSavingResponse = MessageBox.Show ("Oops! It looks like you have already practiced your " + operationType.ToString () +
                    " facts today.\nYou can practice them again, but your progress will not be saved.\n\n Continue anyway?",
                    "Progress Will Not Be Saved", MessageBoxButtons.YesNo);

                if (continueWithoutSavingResponse == DialogResult.No)
                {
                    return;
                }
            }
            else
            {
                saveProgress = true;
            }

            speedTest = isSpeedTest;
            processingAllDailyFacts = processAllDailyFacts;

            if (!processingAllDailyFacts)
            {
                toggleMainMenuControl ();
                toggleFactsDisplayControl ();
            }

            // Change the bool value so the last set of messages for all daily facts are not suppressed.
            else if (operationType.operationType == MathOperationTypeEnum.DIVISION)
            {
                processingAllDailyFacts = !processingAllDailyFacts;
            }

            // Initialize and reset data structures for holding facts data
            incorrectResponses = new Stack <int> ();
            reference.unknownFacts.Clear ();
            reference.knownFacts.Clear ();
            reference.correctResponseCount = 0;
            reference.factResponseTime.Clear ();
            reference.factsOrder.Clear ();
            incorrectResponses.Clear ();
            factsReviewControl.incorrectQuestions.Clear ();

            reference.startProcessingFacts (speedTest, operationType, m_factsDisplayControl, processingAllDailyFacts, userProfile);
        }
Esempio n. 3
0
 /*
  * Fills facts queue with simple facts for testing input speed.
  */
 public static void getFactsForSpeedTest(ref FactsQueue facts, MathOperation operation)
 {
 }
Esempio n. 4
0
        /*
         * Fill the List with newly generated facts if no known facts exist;
         * otherwise, fill with unknown facts.
         */
        void generateFactsList(ref FactsQueue facts, MathOperation oper, UserProfile userProfile)
        {
            FactsList mathFactsList = new FactsList ();

            // Determine whether to read previously generated facts or generate new facts.
            if ((System.IO.File.Exists (FactsFiles.getDailyFactsFilename (oper.operationType, false))))
            {
                readUnknownFactsFromFile (ref mathFactsList, oper);
            }
            else
            {
                generateAndStoreNewFacts (ref mathFactsList, oper, userProfile);
            }

            // Determine the number of facts and obtain a set of random numbers for displaying of the facts
            if (mathFactsList != null)
            {
                randomizeFacts (ref facts, mathFactsList);
            }
        }
Esempio n. 5
0
        /*
         * Read unmastered facts from the file.
         */
        static void readUnknownFactsFromFile(ref FactsList mathFactsList, MathOperation operation)
        {
            try
            {
                String[] numbers = System.IO.File.ReadAllLines (FactsFiles.getDailyFactsFilename (operation.operationType,
                    false));

                Fact newFact = new Fact ();
                newFact.operation = operation;

                for (int index = 0; index < numbers.Count (); ++index)
                {
                    newFact.leftNum = System.Convert.ToInt32 (numbers[index++]);

                    if (numbers.Count () != 0)
                    {
                        newFact.rightNum = System.Convert.ToInt32 (numbers[index]);
                        mathFactsList.Add (newFact);
                    }
                }
            }
            catch (Exception e)
            {
                if (e.InnerException is System.IO.FileNotFoundException)
                {
                    MessageBox.Show ("The file with your unmastered facts could not be found.");
                    return;
                }
                else
                {
                    MessageBox.Show ("There was a problem reading the file with your unmastered facts.");
                    Application.Exit ();
                }
            }
        }
Esempio n. 6
0
        /*
         * Generate and stores the facts.
         */
        static void generateAndStoreNewFacts(ref FactsList factsList, MathOperation operation, UserProfile userProfile)
        {
            Fact newFact;
            newFact.operation = operation;
            MathOperationTypeEnum operationType = operation.operationType;

            // Generate facts starting from 0 to the max number.
            for (int i = 0; i <= userProfile.maxFactNumbers[System.Convert.ToInt16 (operation.operationType)]; ++i)
            {
                for (int j = 0; j <= userProfile.maxFactNumbers[System.Convert.ToInt16 (operation.operationType)]; ++j)
                {
                    if (operationType == MathOperationTypeEnum.ADDITION ||
                         operationType == MathOperationTypeEnum.MULTIPLICATION)
                    {
                        newFact.leftNum = i;
                        newFact.rightNum = j;
                        factsList.Add (newFact);
                    }

                    // Don't allow division by 0 or results with remainders for division facts.
                    else if (i >= j && (operationType == MathOperationTypeEnum.SUBTRACTION ||
                            (operationType == MathOperationTypeEnum.DIVISION && j != 0 && (i % j == 0))))
                    {
                        newFact.leftNum = i;
                        newFact.rightNum = j;
                        factsList.Add (newFact);
                    }
                }
            }
        }
Esempio n. 7
0
        /*
         * Saves the results, overwriting any existing data.
         */
        public void writeResultsToFile(int correctResponseCount, Stack<Fact> unknown, Stack<Fact> known,
										MathOperation operatorType, List<long> factResponseTime)
        {
            using (System.IO.StreamWriter swU = new System.IO.StreamWriter (FactsFiles.getDailyFactsFilename
                    (operatorType.operationType, false)))
            {
                using (System.IO.StreamWriter swK = new System.IO.StreamWriter (FactsFiles.getDailyFactsFilename
                        (operatorType.operationType, true), true))
                {
                    // For use with factResponseTime.
                    int index = 0;

                    // Store each number from the List in the appropriate file.
                    while (knownFacts.Count () != 0)
                    {
                        // Determine whether a correct answer was entered, and whether the answer was entered after a period of elapsed time.
                        if (factResponseTime[index] < maxResponseTime)
                        {
                            // A correct answer was given. Store in the known facts file.
                            swK.WriteLine (knownFacts.Peek ().leftNum);
                            swK.WriteLine (knownFacts.Peek ().rightNum);
                        }

                        // Correct answer was given, but in more than allotted time for a known fact.
                        else
                        {
                            swU.WriteLine (knownFacts.Peek ().leftNum);
                            swU.WriteLine (knownFacts.Peek ().rightNum);
                        }

                        knownFacts.Pop ();
                        ++correctResponseCount;
                        ++index;
                    }

                    // Store incorrect responses in the unknown facts file.
                    while (unknownFacts.Count () != 0)
                    {
                        swU.WriteLine (unknownFacts.Peek ().leftNum);
                        swU.WriteLine (unknownFacts.Peek ().rightNum);
                        unknownFacts.Pop ();
                    }
                }
            }

            // Save the current date in MM/DD/YYYY format to file.
            FactsFiles.writeDailyFactsDateDataToFile (DateTime.Today.ToString ("d"), operatorType.operationType);
        }
Esempio n. 8
0
        /*
         * For determining how long it takes for known versus unknown fact responses to to be entered.
         */
        public void writeFactResponseTimeToFile(MathOperation operation)
        {
            List<int> responseTime = new List<int> ();
            String responseTimeFilename = FactsFiles.getFactResponseTimeFilename ();

            // Read in the current input and write out the new data.
            if (System.IO.File.Exists (responseTimeFilename))
            {
                String[] savedTimes = System.IO.File.ReadAllLines (responseTimeFilename);

                foreach (String time in savedTimes)
                {
                    responseTime.Add (Convert.ToInt32 (time));
                }

                // Determine if the saved file has a complete data set.
                if (responseTime.Count != 4)
                {
                    MessageBox.Show ("The file with your fact response time was damaged.\nYour results for this test have been saved,\nbut any other test data could not be recovered.");
                    responseTime = new List<int> (new int[] { 0, 0, 0, 0 });
                }
            }
            else
            {
                // The file was not created yet - create default data.
                responseTime = new List<int> (new int[] { 0, 0, 0, 0 });
            }

            double sum = 0;
            foreach (double time in factResponseTime)
            {
                sum += time;
            }

            // Store the average response time.
            responseTime[(int) operation.operationType] = (int) (System.Math.Ceiling (sum / factResponseTime.Count ()));

            using (System.IO.StreamWriter sw = new System.IO.StreamWriter (responseTimeFilename))
            {
                foreach (int time in responseTime)
                {
                    sw.WriteLine (time);
                }
            }
        }
Esempio n. 9
0
        /*
         * Handles starting the daily facts and speed test.
         */
        public void startProcessingFacts(bool speedTest, MathOperation operation, FactsDisplayControl displayControl, 
													 bool processingAllDailyFacts, UserProfile userProfile)
        {
            MathOperationTypeEnum opType = MathFactsForm.operationType.operationType;
            // Suppress messages if all daily facts are being processed.
            if (!MathFactsForm.speedTest && !getSavedResponseTime (opType, factResponseTime, ref maxResponseTime))
            {
                if (!processingAllDailyFacts)
                {
                    // No saved response data was found for this fact type.
                    MathFactsForm.toggleInputDisplay ();

                    String operatorName = MathFactsForm.operationType.ToString ();
                    MathFactsForm.m_factsDisplayControl.messageLabel.Text = "No data could be found for " + operatorName + " facts.\n"
                                + "Please take the " + operatorName + " speed test first.\n" + MathFactsForm.COMPLETION_CONTINUE_PROMPT;
                    return;
                }
            }

            correctResponseCount = 0;
            numberOfFactsProcessed = 0;

            if (!speedTest)
            {
                generateFactsList (ref queueOfFacts, operation, userProfile);
            }
            else
            {
                if (userProfile.hasCustomSpeedFacts)
                {
                    randomizeFacts (ref queueOfFacts, FactsFiles.loadCustomSpeedFacts (operation));
                }
                else
                {
                    randomizeFacts (ref queueOfFacts, FactsFiles.loadDefaultSpeedFacts (operation));
                }
            }

            if (queueOfFacts.Count () == 0)
            {
                if (!processingAllDailyFacts)
                {
                    MathFactsForm.toggleInputDisplay ();
                    displayControl.messageLabel.Text = "You have mastered all the facts, there are none to practice!\n"
                            + MathFactsForm.COMPLETION_CONTINUE_PROMPT;
                }
            }
            else
            {
                // Set up the progress bar.
                FactsDisplayControl reference = FactsDisplayControl.Instance;
                reference.factsProgressBar.Maximum = queueOfFacts.Count ();
                reference.factsProgressBar.Increment (1);

                // Display the first fact.
                displayControl.factSignLabel.Text = operation.getOperationSign ();
                displayControl.num1Label.Text = System.Convert.ToString (queueOfFacts.First ().leftNum);
                displayControl.num2Label.Text = System.Convert.ToString (queueOfFacts.First ().rightNum);

                displayControl.inputMaskedTextBox.Focus ();
                MathFactsForm.timer = System.Diagnostics.Stopwatch.StartNew ();
            }
        }
Esempio n. 10
0
 public Fact getQuestionAndResponse(MathOperation operation)
 {
     return new Fact (queueOfFacts.First ().leftNum, queueOfFacts.First ().rightNum, operation);
 }
Esempio n. 11
0
        public void saveCustomSpeedFacts(MathOperation operation, List<Fact> speedFacts)
        {
            String speedFactsFilename = System.IO.Path.Combine (speedTestPath, operation.ToString () + ".txt");

            using (System.IO.StreamWriter file = new System.IO.StreamWriter (speedFactsFilename))
            {
                foreach (Fact speedFact in speedFacts)
                {
                    file.WriteLine (speedFact.leftNum);
                    file.WriteLine (speedFact.rightNum);
                }
            }
        }
Esempio n. 12
0
        public static List<Fact> loadDefaultSpeedFacts(MathOperation operation)
        {
            List<Fact> speedFactsList = new List<Fact> ();
            String speedFactsString = "";

            switch (operation.operationType)
            {
                case MathOperationTypeEnum.ADDITION:
                    speedFactsString = Properties.Resources.AdditionSpeedFacts;
                    break;
                case MathOperationTypeEnum.SUBTRACTION:
                    speedFactsString = Properties.Resources.SubtractionSpeedFacts;
                    break;
                case MathOperationTypeEnum.MULTIPLICATION:
                    speedFactsString = Properties.Resources.MultiplicationSpeedFacts;
                    break;
                case MathOperationTypeEnum.DIVISION:
                    speedFactsString = Properties.Resources.DivisionSpeedFacts;
                    break;
            }

            int[] speedFactDataArray = speedFactsString.Split (' ', '\n').Select (n => Convert.ToInt32 (n)).ToArray ();

            Fact speedFact = new Fact ();
            speedFact.operation = operation;

            for (int index = 0; index < speedFactDataArray.Count (); ++index)
            {
                speedFact.leftNum = speedFactDataArray[index++];
                speedFact.rightNum = speedFactDataArray[index];
                speedFactsList.Add (speedFact);
            }

            return speedFactsList;
        }
Esempio n. 13
0
        public static List<Fact> loadCustomSpeedFacts(MathOperation operation)
        {
            List<Fact> speedFactsList = new List<Fact> ();
            Fact speedFact = new Fact ();
            speedFact.operation = operation;

            String speedFactsFilename = System.IO.Path.Combine (speedTestPath, operation.ToString () + ".txt");

            using (System.IO.StreamReader file = new System.IO.StreamReader (speedFactsFilename))
            {
                String speedFactNumber;
                while ((speedFactNumber = file.ReadLine ()) != null)
                {
                    speedFact.leftNum = System.Convert.ToInt32 (speedFactNumber);

                    if ((speedFactNumber = file.ReadLine ()) != null)
                    {
                        speedFact.rightNum = System.Convert.ToInt32 (speedFactNumber);
                        speedFactsList.Add (speedFact);
                    }
                }
            }

            return speedFactsList;
        }
Esempio n. 14
0
        private void editSpeedFactsButton_MouseClick(object sender, MouseEventArgs e)
        {
            if (speedTestComboBox.Text == "")
            {
                MessageBox.Show ("You didn't select the type of speed test facts.\nPlease select the fact type before continuing.",
                    "No Speed Test Chosen", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MathOperation operation = new MathOperation ((MathOperationTypeEnum) Enum.Parse (typeof (MathOperationTypeEnum), speedTestComboBox.Text, true));

            SpeedFactEditDialog speedFactEditDialog = new SpeedFactEditDialog ();
            speedFactEditDialog.Text = operation.ToString () + speedFactEditDialog.Text;
            DataGridView speedFactDataGridView = speedFactEditDialog.speedFactsDataGridView;

            List<Fact> speedFacts;
            if ((speedFacts = FactsFiles.loadCustomSpeedFacts (operation)).Count () == 0)
            {
                // Load the default speed fact data for creation of the speed facts.
                speedFacts = FactsFiles.loadDefaultSpeedFacts (operation);
            }

            // Load the current speed facts.
            for (int index = 0; index < speedFacts.Count (); ++index)
            {
                speedFactDataGridView.Rows.Add (speedFacts[index].leftNum, speedFacts[index].rightNum);
            }

            // Update the current selected cell to a new row.
            speedFactDataGridView.CurrentCell =
                speedFactDataGridView.Rows[speedFactDataGridView.Rows.Count - 1].Cells[0];

            if (speedFactEditDialog.ShowDialog () == DialogResult.OK)
            {
                speedFacts.Clear ();

                String topNumber;
                String bottomNumber;

                DataGridViewCell cell1;
                DataGridViewCell cell2;

                for (int rowIndex = 0; rowIndex < speedFactDataGridView.RowCount; ++rowIndex)
                {
                    try
                    {
                        cell1 = speedFactDataGridView[rowIndex, 0];
                        cell2 = speedFactDataGridView[rowIndex, 1];

                        // TODO prompt to re-enter row with invalid input
                        topNumber = cell1.Value.ToString ();
                        bottomNumber = cell2.Value.ToString ();
                        speedFacts.Add (new Fact (System.Convert.ToInt16 (topNumber), System.Convert.ToInt16 (bottomNumber), operation));
                    }
                    catch (Exception exception)
                    {
                        if (exception is System.FormatException || exception is System.ArgumentOutOfRangeException || exception is System.NullReferenceException)
                        {
                            // Do nothing. No data entered in this row.
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                if (speedFacts.Count () < 4)
                {
                    MessageBox.Show ("At least 4 speed facts are recommended.\nHaving less than 4 will affect the accuracy of determining the daily facts.\nPlease consider revising and adding more facts.",
                            "Add More Speed Facts", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                files.saveCustomSpeedFacts (operation, speedFacts);
            }

            if (speedFactEditDialog != null)
            {
                speedFactEditDialog.Dispose ();
            }
        }