public Collection <AssociationQuestion> CreateNewQuestionList() { Collection <AssociationQuestion> associationQuestions = new Collection <AssociationQuestion>(); Hashtable oldTestWords = new Hashtable(); if (this.WithoutOldWords) { oldTestWords = LogExercise.GetOldTestWords(this.oldWordsCount); } Collection <string> questions = new Collection <string>(); for (int i = 0; i < this.questionsCount; i++) { string nextWord; do { int nextWordIndex = rnd.Next(programDictionary.Count); nextWord = (string)programDictionary[nextWordIndex]; } while (oldTestWords.ContainsKey(nextWord) || (questions.Contains(nextWord) && !this.WithRepeats)); questions.Add(nextWord); AssociationQuestion temp = new AssociationQuestion(); temp.QuestionSerie.Add(new AssociationQuestionPart(nextWord)); temp.Number = i + 1; associationQuestions.Add(temp); } if (this.WithNumber && this.RandomOrder) { Collection <int> allPositions = new Collection <int>(); for (int i = 0; i < associationQuestions.Count; i++) { allPositions.Add(i); } for (int i = 0; i < associationQuestions.Count; i++) { int ind = allPositions[rnd.Next(allPositions.Count)]; allPositions.Remove(ind); associationQuestions[ind].ShowPosition = i + 1; } } else { foreach (AssociationQuestion item in associationQuestions) { item.ShowPosition = item.Number; } } return(associationQuestions); }
public Collection <AssociationQuestion> CreateNewQuestionList() { Collection <AssociationQuestion> associationQuestions = new Collection <AssociationQuestion>(); Collection <string> questionSource = new Collection <string>(); if (this.TestType == TrainTypeAssociationClosed.WordDictionary) { for (int i = 0; i < 7; i++) { string nextWord = string.Empty; do { int nextWordIndex = rnd.Next(programDictionary.Count); nextWord = (string)programDictionary[nextWordIndex]; } while (questionSource.Contains(nextWord)); questionSource.Add(nextWord); } } else if (this.TestType == TrainTypeAssociationClosed.ClosedList || this.TestType == TrainTypeAssociationClosed.RandomClosedList) { if (this.TestType == TrainTypeAssociationClosed.RandomClosedList) { int tmp = rnd.Next(ClosedList.ClosedLists.Count); this.SelectedClosedList = ClosedList.ClosedLists[tmp]; } foreach (string item in this.SelectedClosedList.Words) { questionSource.Add(item); } } for (int i = 0; i < this.questionsCount; i++) { string nextWord; do { int nextWordIndex = rnd.Next(questionSource.Count); nextWord = (string)questionSource[nextWordIndex]; } while (CheckNextQuestion(nextWord, associationQuestions)); AssociationQuestion temp = new AssociationQuestion(); temp.QuestionSerie.Add(new AssociationQuestionPart(nextWord)); temp.Number = i + 1; temp.ShowPosition = temp.Number; associationQuestions.Add(temp); } return(associationQuestions); }
/// <summary> /// Считывание атрибутов из XmlNode. /// </summary> /// <param name="xmlNode"></param> public override void LoadAttributesFromXml(XmlNode xmlNode) { base.LoadAttributesFromXml(xmlNode); XmlAttribute attr; attr = xmlNode.Attributes[xmlFieldTimeForWord]; if (attr != null && !string.IsNullOrEmpty(attr.Value)) { int temp; if (int.TryParse(attr.Value, out temp)) { this.TimeForWord = temp; } } attr = xmlNode.Attributes[xmlFieldDateCheck]; if (attr != null && !string.IsNullOrEmpty(attr.Value)) { DateTime temp; if (DateTime.TryParse(attr.Value, out temp)) { this.DateCheck = temp; } } attr = xmlNode.Attributes[xmlFieldTimeCheck]; if (attr != null && !string.IsNullOrEmpty(attr.Value)) { double temp; if (double.TryParse(attr.Value, out temp)) { this.TimeCheck = temp; } } foreach (XmlNode item in xmlNode.ChildNodes) { this.questions.Add(AssociationQuestion.CreateFromXml(item)); } }
private bool CheckNextQuestion(string nextWord, Collection <AssociationQuestion> associationQuestions) { if (associationQuestions.Count > 0) { AssociationQuestion temp = associationQuestions[associationQuestions.Count - 1]; if (temp.Question.ToLower() == nextWord.ToLower()) { return(true); } } if (associationQuestions.Count > 1) { AssociationQuestion temp = associationQuestions[associationQuestions.Count - 2]; if (temp.Question.ToLower() == nextWord.ToLower()) { return(true); } } return(false); }
private void PerformNextQuestion() { timerNextQuestion.Stop(); if (this.status == MachineStatus.NotStarted) { this.associationQuestions = this.generator.CreateNewQuestionList(); questionIndex = -1; status = MachineStatus.ShowingQuestion; testStartDate = DateTime.Now; OnTrainStarted(new EventArgs()); } questionIndex++; if (questionIndex < this.generator.QuestionsCount) { { AssociationQuestion nextQuestion = GetQuestionByShowPosition(questionIndex + 1); if (nextQuestion != null) { if (this.WithNumber) { this.questionText = string.Format("{0}. {1}", nextQuestion.Number.ToString(), nextQuestion.Question); } else { this.questionText = nextQuestion.Question; } } else { this.questionText = string.Empty; } } DateTime lastWordStartDate = wordStartDate; wordStartDate = DateTime.Now; OnTrainNewQuestion(new EventArgs()); if (questionIndex != 0) { AssociationQuestion lastQuestion = GetQuestionByShowPosition(questionIndex); if (lastQuestion != null) { lastQuestion.Time = (wordStartDate - lastWordStartDate).TotalSeconds; } } if (this.isAutoNextQuestion) { timerNextQuestion.Start(); } } else { testEndDate = DateTime.Now; status = MachineStatus.WaitingAnswer; OnTrainTestEnd(new EventArgs()); } }
public override void CreateTestTextFile() { if (this.Questions.Count > 0) { string numFormat = "D1"; if (this.Questions.Count > 99) { numFormat = "D3"; } else if (this.Questions.Count > 9) { numFormat = "D2"; } int maxLengthQuestion = 0; int maxLengthTime = 0; foreach (AssociationQuestion item in this.Questions) { string tmp = item.ToString(numFormat); maxLengthQuestion = Math.Max(maxLengthQuestion, tmp.Length); tmp = item.Time.ToString("F2"); maxLengthTime = Math.Max(maxLengthTime, tmp.Length); } StringBuilder sb = new StringBuilder(); DateTime durationTest = new DateTime().Add(this.DateEnd.Value - this.DateStart.Value); DateTime durationCheck = new DateTime().Add(this.DateCheck.Value - this.DateEnd.Value); DateTime durationTotal = new DateTime().Add(this.DateCheck.Value - this.DateStart.Value); sb.AppendLine(string.Format("Тест последовательных ассоциаций на {0} слов.", this.Questions.Count)); sb.AppendLine(); sb.AppendLine(string.Format("Время начала теста {0}", this.DateStart.Value.ToString("dd.MM.yyyy HH:mm:ss"))); sb.AppendLine(string.Format("Время окончания теста {0}", this.DateEnd.Value.ToString("dd.MM.yyyy HH:mm:ss"))); sb.AppendLine(string.Format("Время окончания написания ответов {0}", this.DateCheck.Value.ToString("dd.MM.yyyy HH:mm:ss"))); sb.AppendLine(); sb.AppendLine(string.Format("Продолжительность теста {0}", durationTest.ToLongTimeString())); sb.AppendLine(string.Format("Продолжительность написания ответов {0}", durationCheck.ToLongTimeString())); sb.AppendLine(string.Format("Продолжительность общая {0}", durationTotal.ToLongTimeString())); sb.AppendLine(); sb.AppendLine(string.Format("Минимальное время на образ {0}", this.GetTimeMinimum().ToString("F2").PadLeft(maxLengthTime))); sb.AppendLine(string.Format("Среднее время на образ {0}", this.GetTimeAverange().ToString("F2").PadLeft(maxLengthTime))); sb.AppendLine(string.Format("Максимальное время на образ {0}", this.GetTimeMaximum().ToString("F2").PadLeft(maxLengthTime))); sb.AppendLine(); sb.AppendLine(); for (int i = 0; i < this.Questions.Count; i++) { AssociationQuestion item = this.Questions[i]; string tmp = item.ToString(numFormat); tmp = tmp.PadRight(maxLengthQuestion); string position = string.Empty; if (this.WithNumber && this.Random) { position = string.Format("на {0} месте, ", item.ShowPosition.ToString(numFormat)); } tmp += string.Format(" {0}отображался {1}c.", position, item.Time.ToString("F2").PadLeft(maxLengthTime)); sb.AppendLine(tmp); } string fileName = "Тест " + this.DateStart.Value.ToString("yyyy-MM-dd HH-mm-ss") + " Ассоциации " + this.Questions.Count.ToString() + ".txt"; string pathFile = Path.Combine(Config.ReportFolder, fileName); if (!Directory.Exists(Config.ReportFolder)) { Directory.CreateDirectory(Config.ReportFolder); } using (StreamWriter sw = File.CreateText(pathFile)) { sw.Write(sb.ToString()); } try { Process.Start(pathFile); } catch (Exception) { } } }
public override void CreateTestTextFile() { if (this.Questions.Count > 0) { string numFormat = "D1"; if (this.Questions.Count > 99) { numFormat = "D3"; } else if (this.Questions.Count > 9) { numFormat = "D2"; } int maxLengthQuestion1 = 0; int maxLengthQuestion2 = 0; int maxLengthTime = 0; string netFormat = " {0}"; foreach (AssociationQuestion item in this.Questions) { string tmp = item.ToString(numFormat); maxLengthQuestion1 = Math.Max(maxLengthQuestion1, tmp.Length); tmp = item.Time.ToString("F2"); maxLengthTime = Math.Max(maxLengthTime, tmp.Length); } foreach (AssociationQuestion item in this.Questions) { string tmp = item.ToString(numFormat); tmp = tmp.PadRight(maxLengthQuestion1); if (!string.IsNullOrEmpty(item.NetName)) { tmp += string.Format(netFormat, item.NetName); } maxLengthQuestion2 = Math.Max(maxLengthQuestion2, tmp.Length); } StringBuilder sb = new StringBuilder(); int numberCount = this.NumberCount; DateTime durationTest = new DateTime().Add(this.DateEnd.Value - this.DateStart.Value); DateTime durationCheck = new DateTime().Add(this.DateCheck.Value - this.DateEnd.Value); DateTime durationTotal = new DateTime().Add(this.DateCheck.Value - this.DateStart.Value); sb.AppendLine(string.Format("Тест на {0}-значное число.", numberCount)); sb.AppendLine(string.Format("Всего образов - {0}.", this.Questions.Count)); sb.AppendLine(); sb.AppendLine(string.Format("Время начала теста {0}", this.DateStart.Value.ToString("dd.MM.yyyy HH:mm:ss"))); sb.AppendLine(string.Format("Время окончания теста {0}", this.DateEnd.Value.ToString("dd.MM.yyyy HH:mm:ss"))); sb.AppendLine(string.Format("Время окончания написания ответов {0}", this.DateCheck.Value.ToString("dd.MM.yyyy HH:mm:ss"))); sb.AppendLine(); sb.AppendLine(string.Format("Продолжительность теста {0}", durationTest.ToLongTimeString())); sb.AppendLine(string.Format("Продолжительность написания ответов {0}", durationCheck.ToLongTimeString())); sb.AppendLine(string.Format("Продолжительность общая {0}", durationTotal.ToLongTimeString())); sb.AppendLine(); sb.AppendLine(string.Format("Минимальное время на образ {0}", this.GetTimeMinimum().ToString("F2").PadLeft(maxLengthTime))); sb.AppendLine(string.Format("Среднее время на образ {0}", this.GetTimeAverange().ToString("F2").PadLeft(maxLengthTime))); sb.AppendLine(string.Format("Максимальное время на образ {0}", this.GetTimeMaximum().ToString("F2").PadLeft(maxLengthTime))); sb.AppendLine(); sb.AppendLine(); StringBuilder fullNumber = new StringBuilder(); StringBuilder fullNumberWithSplit = new StringBuilder(); for (int i = 0; i < this.Questions.Count; i++) { AssociationQuestion item = this.Questions[i]; string tmp = item.ToString(numFormat); tmp = tmp.PadRight(maxLengthQuestion1); if (!string.IsNullOrEmpty(item.NetName)) { tmp += string.Format(netFormat, item.NetName); } tmp = tmp.PadRight(maxLengthQuestion2); string position = string.Empty; if (this.WithNumber && this.Random) { position = string.Format("на {0} месте, ", item.ShowPosition.ToString(numFormat)); } tmp += string.Format(" {0}отображался {1}c.", position, item.Time.ToString("F2").PadLeft(maxLengthTime)); sb.AppendLine(tmp); if (fullNumberWithSplit.Length != 0) { fullNumberWithSplit.Append("-"); } fullNumberWithSplit.Append(item.Question); fullNumber.Append(item.Question); } sb.AppendLine(); sb.AppendLine(string.Format("Строка чисел: {0}.", fullNumberWithSplit.ToString())); sb.Append(string.Format("Полное число: {0}.", fullNumber.ToString())); string fileName = "Тест " + this.DateStart.Value.ToString("yyyy-MM-dd HH-mm-ss") + " Числа " + numberCount.ToString() + ".txt"; string pathFile = Path.Combine(Config.ReportFolder, fileName); if (!Directory.Exists(Config.ReportFolder)) { Directory.CreateDirectory(Config.ReportFolder); } using (StreamWriter sw = File.CreateText(pathFile)) { sw.Write(sb.ToString()); } try { Process.Start(pathFile); } catch (Exception) { } } }
public Collection <AssociationQuestion> CreateNewQuestionList() { Collection <AssociationQuestion> associationQuestions = new Collection <AssociationQuestion>(); int patternCount = this.numbersCount / 2 + this.numbersCount % 2; int singleNumber = -1; if (this.numbersCount % 2 != 0) { singleNumber = rnd.Next(patternCount); } for (int i = 0; i < patternCount; i++) { string nextNumber = rnd.Next(100).ToString("D2"); if (i == singleNumber) { nextNumber = rnd.Next(10).ToString(); } AssociationQuestion temp = new AssociationQuestion(); temp.QuestionSerie.Add(new AssociationQuestionPart(nextNumber)); temp.Number = i + 1; associationQuestions.Add(temp); } Collection <Net> selectedNets = GetSelectedNets(); if (selectedNets.Count > 2) { int[] netIndexs = new int[associationQuestions.Count]; int serieCount = associationQuestions.Count / selectedNets.Count + (associationQuestions.Count % selectedNets.Count > 0 ? 1 : 0); for (int i = 0; i < serieCount; i++) { bool cont = false; int[] netOrder = new int[selectedNets.Count]; do { Collection <int> allPositions = new Collection <int>(); for (int j = 0; j < selectedNets.Count; j++) { allPositions.Add(j); } for (int j = 0; j < selectedNets.Count; j++) { int index = allPositions[rnd.Next(allPositions.Count)]; allPositions.Remove(index); netOrder[j] = index; } cont = i != 0 && netIndexs[i * selectedNets.Count - 1] == netOrder[0]; if (i != 0) { bool equals = true; for (int j = 0; j < selectedNets.Count; j++) { if (netIndexs[(i - 1) * selectedNets.Count + j] != netOrder[j]) { equals = false; break; } } if (equals) { cont = true; } } } while (cont); for (int j = 0; j < selectedNets.Count && (i * selectedNets.Count + j < associationQuestions.Count); j++) { netIndexs[i * selectedNets.Count + j] = netOrder[j]; } } for (int i = 0; i < associationQuestions.Count; i++) { associationQuestions[i].QuestionSerie[0].NetName = selectedNets[netIndexs[i]].ToString(); } } if (this.WithNumber && this.RandomOrder) { Collection <int> allPositions = new Collection <int>(); for (int i = 0; i < associationQuestions.Count; i++) { allPositions.Add(i); } for (int i = 0; i < associationQuestions.Count; i++) { int ind = allPositions[rnd.Next(allPositions.Count)]; allPositions.Remove(ind); AssociationQuestion quest = associationQuestions[ind]; quest.ShowPosition = i + 1; } } else { foreach (AssociationQuestion item in associationQuestions) { item.ShowPosition = item.Number; } } return(associationQuestions); }