Exemplo n.º 1
0
        //public void ExportResponse_v2()
        //{
        //    string file = zPath.Combine(_directory, GetFileName() + ".response.txt");
        //    Response[] responses = ReadResponses().ToArray();

        //    // 2012
        //    // Q102: ABCD
        //    Trace.WriteLine($"export responses to \"{file}\"");

        //    //Dictionary<int, int> years = new Dictionary<int, int>();
        //    //List<IEnumerator<Response>> yearResponses = new List<IEnumerator<Response>>();
        //    SortedDictionary<int, IEnumerator<Response>> years = new SortedDictionary<int, IEnumerator<Response>>();
        //    //int index = 0;
        //    //Trace.WriteLine($"{responses.Length} responses");
        //    foreach (Response response in responses)
        //    {
        //        //Trace.WriteLine($"{response.Year} - Q{response.QuestionNumber}: {response.Responses}");
        //        if (!years.ContainsKey(response.Year))
        //        {
        //            //years.Add(response.Year, index++);
        //            //yearResponses.Add(responses.Where(response2 => response2.Year == response.Year).GetEnumerator());
        //            years.Add(response.Year, responses.Where(response2 => response2.Year == response.Year).GetEnumerator());
        //        }
        //    }

        //    using (StreamWriter sw = new StreamWriter(zFile.Create(file)))
        //    {
        //        StringBuilder sb = new StringBuilder();

        //        bool first = true;
        //        foreach (int year in years.Keys.Reverse())
        //        {
        //            if (!first)
        //                sb.Append(new string(' ', _yearWidth - 5));
        //            sb.Append($" {year}");
        //            first = false;
        //        }
        //        sw.WriteLine();
        //        sw.WriteLine(sb.ToString());
        //        sw.WriteLine();

        //        sb.Clear();
        //        //int lastIndex = -1;
        //        int l = 0;
        //        //foreach (Response response in responses)
        //        while (true)
        //        {
        //            bool found = false;
        //            int lastIndex = -1;
        //            int index = -1;
        //            //foreach (IEnumerator<Response> yearResponse in yearResponses)
        //            foreach (int year in years.Keys.Reverse())
        //            {
        //                index++;
        //                IEnumerator<Response> yearResponse = years[year];

        //                if (!yearResponse.MoveNext())
        //                    continue;

        //                found = true;
        //                Response response = yearResponse.Current;
        //                //Trace.WriteLine($"{response.Year} - Q{response.QuestionNumber}: {response.Responses}");
        //                //index = years[response.Year];
        //                if (index <= lastIndex)
        //                {
        //                    sw.WriteLine(sb.ToString());
        //                    sw.WriteLine();
        //                    sb.Clear();
        //                    lastIndex = -1;
        //                    l = 0;
        //                }
        //                if (index != lastIndex - 1 || l > 0)
        //                    sb.Append(new string(' ', (index - lastIndex - 1) * _yearWidth + l));
        //                string text = $" Q{response.QuestionNumber}: {response.Responses}";
        //                l = _yearWidth - text.Length;
        //                sb.Append(text);
        //                lastIndex = index;
        //            }
        //            if (!found)
        //                break;
        //            if (sb.Length > 0)
        //                sw.WriteLine(sb.ToString());
        //            sw.WriteLine();
        //            sb.Clear();
        //            lastIndex = -1;
        //            l = 0;
        //        }
        //    }
        //}

        //public void ExportResponse_v1()
        //{
        //    string file = zPath.Combine(_directory, GetFileName() + ".response.txt");
        //    Response[] responses = GetResponses().ToArray();

        //    // 2012
        //    // Q102: ABCD
        //    Trace.WriteLine($"export responses to \"{file}\"");

        //    Dictionary<int, int> years = new Dictionary<int, int>();
        //    List<IEnumerator<Response>> yearResponses = new List<IEnumerator<Response>>();
        //    //SortedDictionary<int, IEnumerator<Response>> years = new SortedDictionary<int, IEnumerator<Response>>();
        //    int index = 0;
        //    //Trace.WriteLine($"{responses.Length} responses");
        //    foreach (Response response in responses)
        //    {
        //        //Trace.WriteLine($"{response.Year} - Q{response.QuestionNumber}: {response.Responses}");
        //        if (!years.ContainsKey(response.Year))
        //        {
        //            years.Add(response.Year, index++);
        //            yearResponses.Add(responses.Where(response2 => response2.Year == response.Year).GetEnumerator());
        //        }
        //    }

        //    using (StreamWriter sw = new StreamWriter(zFile.Create(file)))
        //    {
        //        StringBuilder sb = new StringBuilder();

        //        bool first = true;
        //        foreach (int year in years.Keys)
        //        {
        //            if (!first)
        //                sb.Append(new string(' ', _yearWidth - 5));
        //            sb.Append($" {year}");
        //            first = false;
        //        }
        //        sw.WriteLine();
        //        sw.WriteLine(sb.ToString());
        //        sw.WriteLine();

        //        sb.Clear();
        //        int lastIndex = -1;
        //        int l = 0;
        //        //foreach (Response response in responses)
        //        while (true)
        //        {
        //            bool found = false;
        //            foreach (IEnumerator<Response> yearResponse in yearResponses)
        //            {
        //                if (!yearResponse.MoveNext())
        //                    continue;

        //                found = true;
        //                Response response = yearResponse.Current;
        //                //Trace.WriteLine($"{response.Year} - Q{response.QuestionNumber}: {response.Responses}");
        //                index = years[response.Year];
        //                if (index <= lastIndex)
        //                {
        //                    sw.WriteLine(sb.ToString());
        //                    sw.WriteLine();
        //                    sb.Clear();
        //                    lastIndex = -1;
        //                    l = 0;
        //                }
        //                if (index != lastIndex - 1 || l > 0)
        //                    sb.Append(new string(' ', (index - lastIndex - 1) * _yearWidth + l));
        //                string text = $" Q{response.QuestionNumber}: {response.Responses}";
        //                l = _yearWidth - text.Length;
        //                sb.Append(text);
        //                lastIndex = index;
        //            }
        //            if (!found)
        //                break;
        //            if (sb.Length > 0)
        //                sw.WriteLine(sb.ToString());
        //            sw.WriteLine();
        //            sb.Clear();
        //            lastIndex = -1;
        //            l = 0;
        //        }
        //    }
        //}

        // QuestionResponseFiles questionResponseFiles
        private IEnumerable <QuestionResponse> GetQuestionResponses()
        {
            //QuestionResponseFiles questionResponseFiles = GetQuestionResponseScanFiles();
            //// , string baseDirectory = null
            //return QuestionResponses.GetQuestionResponses(QuestionReader.Read(questionResponseFiles.QuestionFiles, _questionRegexValuesList, questionResponseFiles.BaseDirectory),
            //    ResponseReader.Read(questionResponseFiles.ResponseFile, _responseRegexValuesList));
            return(QuestionResponses.GetQuestionResponses(ReadQuestions(), ReadResponses()));
        }
Exemplo n.º 2
0
        public void CreateAllQuestionResponseFiles()
        {
            Response[] responses = ReadResponses().ToArray();
            CreateResponsesFile(responses);
            ExportResponses(responses);

            Question[] questions = ReadQuestions().ToArray();
            CreateQuestionsFile(questions);

            QuestionResponses.DeleteUnmodifiedQuestionResponseFiles(_directory);
            CreateQuestionResponseFiles(QuestionResponses.GetQuestionResponses(questions, responses));
        }