Exemplo n.º 1
0
        /*
         * Process a fact answer
         */
        public void processInput()
        {
            timer.Stop();
            m_factsDisplayControl.factsProgressBar.Increment (1);

            long secondsElapsed;

            // Obtain the input answer.
            String inputString = (m_factsDisplayControl.inputMaskedTextBox.Text);
            int answer = System.Convert.ToInt32 (inputString);
            Fact input = reference.getQuestionAndResponse (operationType);
            int calculatedAnswer = MathOperation.calculateAnswer (input.leftNum, input.rightNum, operationType);

            // Only store the response time for correct answers.
            if (answer == calculatedAnswer)
            {
                secondsElapsed = (long) (timer.ElapsedMilliseconds / 1000.0);
                reference.factResponseTime.Add(secondsElapsed);
            }

            // Only keep answers for daily facts.
            if (!speedTest)
            {
                if (answer == calculatedAnswer)
                {
                    reference.knownFacts.Push (new Fact (input.leftNum, input.rightNum, operationType));
                }
                else
                {
                    reference.unknownFacts.Push (new Fact (input.leftNum, input.rightNum, operationType));
                    incorrectResponses.Push (answer);
                }
            }

            Fact nextFact = new Fact();

            // Get the next fact and update the labels.
            if (reference.getNextFact (ref nextFact))
            {
                m_factsDisplayControl.inputMaskedTextBox.Text = "";
                m_factsDisplayControl.num1Label.Text = System.Convert.ToString (nextFact.leftNum);
                m_factsDisplayControl.num2Label.Text = System.Convert.ToString (nextFact.rightNum);

                timer.Restart ();
            }
            else
            {
                toggleInputDisplay ();
                displayCompletionMessage ();
            }
        }
Exemplo n.º 2
0
        /*
         * Functions to process the facts. Removes the last answered fact and retrieves the next fact.
         */
        public bool getNextFact(ref Fact nextFact)
        {
            queueOfFacts.Dequeue ();
            ++numberOfFactsProcessed;

            // Return the next fact to display, if any remain.
            if (queueOfFacts.Count () > 0)
            {
                nextFact = queueOfFacts.Peek ();
                return true;
            }

            return false;
        }
Exemplo n.º 3
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 ();
                }
            }
        }
Exemplo n.º 4
0
        public void saveResponseData(int[] incorrectResponses, Fact[] unknownFacts, String username, MathOperationTypeEnum operation)
        {
            Data.UserDataSetTableAdapters.ResponseDataTableAdapter responseDataTableAdapter = new Data.UserDataSetTableAdapters.ResponseDataTableAdapter ();
            DateTime date = DateTime.Today.Date;
            System.Text.StringBuilder responseStringBuilder = new System.Text.StringBuilder ();

            // Create a formatted response string.
            for (int index = 0; index < unknownFacts.Count (); ++index)
            {
                responseStringBuilder.Append ("\n");
                responseStringBuilder.Append (unknownFacts[index].ToString ());
                responseStringBuilder.Append (" = ");
                responseStringBuilder.Append(incorrectResponses[index].ToString ());
            }

            try
            {
                responseDataTableAdapter.Insert (username, date, (int) operation, responseStringBuilder.ToString ());
            }
            catch (Exception e)
            {
                // TODO Handle exceptions
                Console.WriteLine (e.StackTrace);
            }
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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;
        }