public static String getDailyFactsDataFilename(MathOperationTypeEnum operation) { switch (operation) { case MathOperationTypeEnum.ADDITION: return dailyAdditionFactsData; case MathOperationTypeEnum.SUBTRACTION: return dailySubtractionFactsData; case MathOperationTypeEnum.MULTIPLICATION: return dailyMultiplicationFactsData; default: return dailyDivisionFactsData; } }
/* * Retrieve the current saved response time. */ public static bool getSavedResponseTime(MathOperationTypeEnum operationType, List<long> factResponseTime, ref int maxResponseTime) { List<int> responseTime = new List<int> (); String[] savedTimes; try { savedTimes = System.IO.File.ReadAllLines (FactsFiles.getFactResponseTimeFilename ()); } catch (System.IO.FileNotFoundException) { return false; } foreach (String time in savedTimes) { responseTime.Add (System.Convert.ToInt32 (time)); } maxResponseTime = responseTime[(int) operationType]; // No fact response times have been recorded if no maxResponseTime exists return !maxResponseTime.Equals(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); }
/* * Determine which filename should be used. */ public static string getDailyFactsFilename(MathOperationTypeEnum operationType, bool knownFile) { switch (operationType) { case MathOperationTypeEnum.ADDITION: if (knownFile) { return System.IO.Path.Combine (knownFactsPath, ADDITION); } else { return System.IO.Path.Combine (unknownFactsPath, ADDITION); } case MathOperationTypeEnum.SUBTRACTION: if (knownFile) { return System.IO.Path.Combine (knownFactsPath, SUBTRACTION); } else { return System.IO.Path.Combine (unknownFactsPath, SUBTRACTION); } case MathOperationTypeEnum.MULTIPLICATION: if (knownFile) { return System.IO.Path.Combine (knownFactsPath, MULTIPLICATION); } else { return System.IO.Path.Combine (unknownFactsPath, MULTIPLICATION); } default: if (knownFile) { return System.IO.Path.Combine (knownFactsPath, DIVISION); } else { return System.IO.Path.Combine (unknownFactsPath, DIVISION); } } }
private static String getFactsFilename(MathOperationTypeEnum operation) { switch (operation) { case MathOperationTypeEnum.ADDITION: return ADDITION; case MathOperationTypeEnum.SUBTRACTION: return SUBTRACTION; case MathOperationTypeEnum.MULTIPLICATION: return MULTIPLICATION; default: return DIVISION; } }
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); } }
/* * Retrieves the last date a daily fact was run for the given operation. */ public String readDailyFactsDateDataFromFile(MathOperationTypeEnum operation) { try { String dateLog = getDailyFactsDataFilename (operation); // Check if more than 1 month has elapsed since the last speed test. using (System.IO.StreamReader file = new System.IO.StreamReader (dateLog)) { DateTime dateOfFirstSpeedTest = Convert.ToDateTime (file.ReadLine ()); if (DateTime.Today.AddMonths (1) <= dateOfFirstSpeedTest) { // Overwrite the current file to avoid saving more than 30 days of data at a time. System.IO.File.Create (dateLog); return "MAX_TIME_ELAPSED"; } return System.IO.File.ReadLines (dateLog).Last (); } } catch (Exception) { return ""; } }
/* * Saves the current date for the given math fact operation. */ public static void writeDailyFactsDateDataToFile(String date, MathOperationTypeEnum operation) { try { using (System.IO.StreamWriter fileWriter = System.IO.File.AppendText (getDailyFactsDataFilename (operation))) { fileWriter.WriteLine (date); } } catch (Exception e) { Console.WriteLine (e); } }
private void updateFactFiles(MathOperationTypeEnum operationType, int maxFactNumber) { MathFactsForm.userProfile.maxFactNumbers[(int) operationType] = maxFactNumber; // Delete the files so new facts will be generated the next time daily facts is selected. String unknownFactsFile = FactsFiles.getDailyFactsFilename (operationType, false); if (System.IO.File.Exists (unknownFactsFile)) { System.IO.File.Delete (unknownFactsFile); } String knownFactsFile = FactsFiles.getDailyFactsFilename (operationType, true); if (System.IO.File.Exists (knownFactsFile)) { System.IO.File.Delete (knownFactsFile); } // Also clear any existing date data String dailyFactsDataFile = FactsFiles.getDailyFactsDataFilename (operationType); System.IO.File.Create (dailyFactsDataFile); }
public MathOperation(MathOperationTypeEnum operationType) { this.operationType = operationType; }