public static string GetQuestionHotspotAsCSV(Question q) { string csv = ""; // name - code csv += "\"" + q.name + "\"" + ","; // questionText - body csv += "\"" + q.text + "\"" + ","; csv += "\"" + q.data + "\"" + ","; // answer options for (int i = 0; i < 10; i++) { csv += ","; } csv += "Open,L1,"; // category - question_category_code csv += "\"" + q.category + "\"" + ","; //string feedback_right = ""; //string feedback_wrong = ""; String[] fb = QuestionLib.ParseFeedbacks(q); string images = ""; for (int j = 0; j < q.images.Count; j++) { if (images != String.Empty) { images += ";"; } images += q.images[j].name; } csv += "\"" + images + "\"" + ",n," + "\"" + fb[0] + "\"" + "," + "\"" + fb[1] + "\""; return(csv); }
public static List <string> CreateDefaultCSV(string filename, List <Question> questions) { int questionsSkipped = 0; List <string> result = new List <string>(); result.Add("Processing default question types...."); // build CSV text string csvText = "code,body,correct_choice,"; csvText += "choice_1,choice_2,choice_3,choice_4,choice_5,choice_6,choice_7,choice_8,choice_9,choice_10,"; csvText += "status,difficulty,question_category_code,keyword,can_fail_exam,correct_feedback,incorrect_feedback"; //csvText += ",generalfeedback,partiallycorrectfeedback"; for (int i = 1; i <= 10; i++) { csvText += ",choice_" + i.ToString() + "_feedback"; } for (int i = 0; i < questions.Count; i++) { Question q = questions[i]; List <string> errorsFound = QuestionLib.CheckQuestion(q); if (errorsFound.Count == 0) { string csv = GetQuestionAsCSV(q); if (csv.Length > 0) { csvText += Environment.NewLine + csv; } } else { questionsSkipped++; } } result.Add("\tCSV text created; questions skipped: " + questionsSkipped.ToString()); // write csv file JwCSV.WriteToFile(filename, csvText); result.Add("\tCSV file created."); // create image folder List <Question> questionsWithImageData = QuestionLib.GetQuestionsWithImageData(questions); string imageFolder = CFG.outputDir + Path.GetFileNameWithoutExtension(filename) + "-img"; if (questionsWithImageData.Count > 0) { System.IO.Directory.CreateDirectory(imageFolder); result.Add("\timage dir created."); // create images int imageCount = 0; for (int i = 0; i < questionsWithImageData.Count; i++) { Question q = questionsWithImageData[i]; for (int j = 0; j < q.images.Count; j++) { if (q.images[j].name != String.Empty && q.images[j].imageData != String.Empty) { string imageFile = Path.Combine(imageFolder, q.images[j].name); File.WriteAllBytes(imageFile, Convert.FromBase64String(q.images[j].imageData)); imageCount++; } } } result.Add("\t" + imageCount.ToString() + " images created."); } // return result return(result); }
public static string GetQuestionMResponseAsCSV(Question q) { string csv = ""; if ((q.type == "multichoice" || q.type == "Multiple Choice" || q.type == "multichoiceset") == false) { return(""); } // name - code csv += "\"" + q.name + "\"" + ","; // questionText - body csv += "\"" + q.text + "\"" + ","; // answer options for (int i = 0; i < 10; i++) { if (i < q.options.Count) { csv += "\"" + q.options[i].text + "\"" + ","; if (q.options[i].grade <= 0) { csv += "FALSE,"; } else { csv += "TRUE,"; } } else { csv += "\"\",\"\","; } } csv += "Open,L1,"; // category - question_category_code csv += "\"" + q.category + "\"" + ","; csv += "\"\",\"\""; // feedback String[] fb = QuestionLib.ParseFeedbacks(q); csv += ",\"" + fb[0] + "\""; csv += ",\"" + fb[1] + "\""; //csv += ",\"" + q.generalfeedback + "\""; //csv += ",\"" + q.partiallycorrectfeedback + "\""; for (int i = 1; i <= 10; i++) { string optionFeedback = ""; if (i <= q.options.Count) { optionFeedback = q.options[i - 1].feedback; } csv += ",\"" + optionFeedback + "\""; } return(csv); }
public static string GetQuestionAsCSV(Question q) { string csv = ""; if ((q.type == "multichoice" || q.type == "truefalse" || q.type == "Multiple Choice" || q.type == "cloze") == false) { return(""); } //TODO - this is duplicated in GetCSVText List <string> errors = QuestionLib.CheckQuestion(q); if (errors.Count > 0) { return(""); } // name - code csv += "\"" + q.name + "\"" + ","; // questionText - body csv += "\"" + q.text + "\"" + ","; // correct_choice int correct_choice = 1; for (int i = 0; i < q.options.Count; i++) { if (q.options[i].grade == 100) { correct_choice = i + 1; } } csv += "choice_" + correct_choice.ToString() + ","; // answer options for (int i = 0; i < 10; i++) { if (i < q.options.Count) { csv += "\"" + q.options[i].text + "\"" + ","; } else { csv += ","; } } csv += "Open,L1,"; // category - question_category_code csv += "\"" + q.category + "\"" + ","; string images = ""; for (int j = 0; j < q.images.Count; j++) { if (images != String.Empty) { images += ";"; } images += q.images[j].name; } // process feedback String[] fb = QuestionLib.ParseFeedbacks(q); csv += "\"" + images + "\"" + ",n," + "\"" + fb[0] + "\"" + "," + "\"" + fb[1] + "\""; //csv += "\"" + images + "\"" + ",n," + "\"" + q.correctfeedback + "\"" + "," + "\"" + q.incorrectfeedback + "\""; //csv += ",\"" + q.generalfeedback + "\""; //csv += ",\"" + q.partiallycorrectfeedback + "\""; for (int i = 1; i <= 10; i++) { string optionFeedback = ""; if (i <= q.options.Count) { optionFeedback = q.options[i - 1].feedback; } csv += ",\"" + optionFeedback + "\""; } return(csv); }