Ejemplo n.º 1
0
        private static string exportReponsesMultiple(QuestionMultiple q)
        {
            String res = "{\n";

            foreach (Reponse r in q.getReponses())
            {
                ReponseSimple rs       = (ReponseSimple)r;
                String        fraction = "";
                if (rs.isTrue())
                {
                    fraction = "100";
                }
                else
                {
                    fraction = "-100";
                }
                res += "~%" + fraction + "%" + rs.texte;
                if (!rs.feedbackR.Equals(""))
                {
                    res += "#" + rs.feedbackR;
                }
                res += "\n";
            }
            if (!q.feedbackQ.Equals(""))
            {
                res += "####" + q.feedbackQ + "\n";
            }
            res += "}\n\n";
            return(res);
        }
Ejemplo n.º 2
0
        private static string exportReponsesSimple(Question q)
        {
            String res = "{\n";

            foreach (Reponse r in q.getReponses())
            {
                ReponseSimple rs   = (ReponseSimple)r;
                String        type = "";
                if (rs.isTrue())
                {
                    type = "=";
                }
                else
                {
                    type = "~";
                }
                res += type + rs.texte;
                if (!rs.feedbackR.Equals(""))
                {
                    res += "#" + rs.feedbackR;
                }
                res += "\n";
            }
            if (!q.feedbackQ.Equals(""))
            {
                res += "####" + q.feedbackQ + "\n";
            }
            res += "}\n\n";
            return(res);
        }
Ejemplo n.º 3
0
        private static void cleanReponse(Reponse r)
        {
            if (r is ReponseSimple)
            {
                ReponseSimple rm    = (ReponseSimple)r;
                String        texte = rm.texte;
                texte = Regex.Replace(texte, @"%-?[0-9]+(\.[0-9]+)?%", "");
                texte = texte.Replace("\n", "");
                texte = Regex.Replace(texte, @"####.*", "");
                int index = texte.IndexOf("#");
                if (index != -1)
                {
                    String[] split = texte.Split("#");
                    texte        = split[0];
                    rm.feedbackR = split[1];
                }
                rm.texte = texte;
            }
            if (r is ReponseMatching)
            {
                ReponseMatching rm     = (ReponseMatching)r;
                String          texte1 = rm.texte1;
                texte1 = texte1.Replace("\n", "");
                String texte2 = rm.texte2;
                texte2 = texte2.Replace("\n", "");

                texte2 = Regex.Replace(texte2, @"####.*", "");
                int index = texte2.IndexOf("#");
                if (index != -1)
                {
                    String[] split = texte2.Split("#");
                    texte2       = split[0];
                    rm.feedbackR = split[1];
                }
                rm.texte1 = texte1;
                rm.texte2 = texte2;
            }
        }
Ejemplo n.º 4
0
 internal static void exportQuestions(List <Groupe> gquestions, string destpath, int verbose)
 {
     using (StreamWriter w = new StreamWriter(destpath, false))
     {
         String res               = "";
         int    nbquestions       = 0;
         int    nbquestionsignore = 0;
         for (int i = 0; i < gquestions.Count; i++)
         {
             if (i != 0)
             {
                 res += "*(";
                 res += gquestions[i].getTexte()[0] + "\n";
             }
             foreach (Question q in gquestions[i].getQuestions())
             {
                 nbquestions++;
                 logExport(q);
                 String typeq = "";
                 if (q is QuestionSimple)
                 {
                     typeq = "* ";
                 }
                 if (q is QuestionMultiple)
                 {
                     typeq = "** ";
                 }
                 if (q is QuestionOuverte)
                 {
                     typeq = "*<lines=" + ((QuestionOuverte)q).getLignes() + "> ";
                     QuestionOuverte qo = (QuestionOuverte)q;
                     if (!(q is QuestionOuverteAMC))
                     {
                         qo.getReponses().Clear();
                     }
                     if (qo.getReponses().Count < 2)
                     {
                         qo.getReponses().Clear();
                         qo.addReponse(new ReponseSimple("", "Ok", true));
                         qo.addReponse(new ReponseSimple("", "Erreur", false));
                     }
                 }
                 if (typeq != "")
                 {
                     res += typeq + q.getTitre() + "\n";
                     foreach (Reponse r in q.getReponses())
                     {
                         ReponseSimple rs = (ReponseSimple)r;
                         String        vf = "";
                         if (rs.vrai)
                         {
                             vf = "+ ";
                         }
                         else
                         {
                             vf = "- ";
                         }
                         res += vf + rs.texte + "\n";
                     }
                     res += "\n";
                 }
                 else
                 {
                     nbquestionsignore++;
                 }
             }
             if (i != 0)
             {
                 res += "*)";
                 res += gquestions[i].getTexte()[1] + "\n";
             }
         }
         if (nbquestionsignore > 0)
         {
             Console.WriteLine((nbquestions - nbquestionsignore) + " questions sur " + nbquestions + " converties");
         }
         else
         {
             Console.WriteLine(nbquestions + " questions converties");
         }
         w.Write(res);
     }
 }
Ejemplo n.º 5
0
        private static List <Reponse> getReponses(string reponses)
        {
            Regex          rx3 = new Regex(@"^(FALSE|TRUE|T|F)(#([A-z0-9]*[^A-Za-z0-9#{}~=]*)*){0,2}$");
            List <Reponse> res = new List <Reponse>();

            if (rx3.IsMatch(reponses.ToUpper()))
            {
                switch (reponses.Substring(0, 1).ToUpper())
                {
                case "T":
                    res.Add(new ReponseSimple("", "TRUE", true));
                    res.Add(new ReponseSimple("", "FALSE", false));
                    break;

                case "F":
                    res.Add(new ReponseSimple("", "TRUE", false));
                    res.Add(new ReponseSimple("", "FALSE", true));
                    break;
                }
            }
            else if (reponses.IndexOf("=") == -1 && reponses.IndexOf("~") == -1)
            {
                if (reponses.Substring(0, 1).Equals("#"))
                {
                    reponses = reponses.Substring(1);
                }
                res.Add(new ReponseSimple("", reponses, true));
            }
            else if (reponses.IndexOf("=") != -1 && reponses.IndexOf("~") == -1)
            {
                String[] split = reponses.Split("=");
                if (reponses.IndexOf("->") != -1)
                {
                    for (int i = 1; i < split.Length; i++)
                    {
                        String[] texteappariement = Regex.Split(split[i], "->");
                        if (texteappariement.Length == 2)
                        {
                            res.Add(new ReponseMatching(texteappariement[0], texteappariement[1]));
                        }
                    }
                }
                else
                {
                    for (int i = 1; i < split.Length; i++)
                    {
                        res.Add(new ReponseSimple("", split[i], true));
                    }
                }
            }
            else if (reponses.IndexOf("=") == -1 && reponses.IndexOf("~") != -1)
            {
                String[] split = reponses.Split("~");
                for (int i = 1; i < split.Length; i++)
                {
                    String  fraction = "";
                    Boolean vrai     = false;
                    String  entitule = split[i];
                    int     index1   = split[i].IndexOf('%');
                    int     index2   = split[i].IndexOf('%', split[i].IndexOf('%') + 1);
                    if (index1 != -1 && index2 != -1)
                    {
                        fraction = split[i].Substring(index1 + 1, index2 - 1);
                        if (Double.Parse(fraction) > 0)
                        {
                            vrai = true;
                        }
                        entitule = split[i].Substring(index2 + 1);
                    }
                    ReponseSimple r = new ReponseSimple("", entitule, vrai);
                    r.fraction = fraction;
                    res.Add(r);
                }
            }
            else
            {
                Regex           rx1 = new Regex(@"(~|=)[^~=]*");
                MatchCollection ms  = rx1.Matches(reponses);
                foreach (Match m in ms)
                {
                    Boolean vrai     = false;
                    String  entitule = "";
                    if (m.Value.Substring(0, 1).Equals("="))
                    {
                        vrai = true;
                    }
                    entitule = m.Value.Substring(1);
                    res.Add(new ReponseSimple("", entitule, vrai));
                }
            }
            return(res);
        }
Ejemplo n.º 6
0
        internal static void exportQuestions(List <Groupe> gquestions, string destpath, int verbose)
        {
            XmlTextWriter writer = new XmlTextWriter(destpath, System.Text.Encoding.UTF8);

            writer.WriteStartDocument(true);
            writer.Formatting  = Formatting.Indented;
            writer.Indentation = 2;
            writer.WriteStartElement("quiz");
            int nbquestions = 0;

            foreach (Groupe g in gquestions)
            {
                int i = 1;
                foreach (Question q in g.getQuestions())
                {
                    logExport(q);
                    nbquestions++;
                    writer.WriteStartElement("question");
                    switch (q)
                    {
                    case QuestionDescription qd:
                        writer.WriteAttributeString("type", "description");
                        break;

                    case QuestionVF qvf:
                        writer.WriteAttributeString("type", "truefalse");
                        break;

                    case QuestionSimple qs:
                        writer.WriteAttributeString("type", "multichoice");
                        writer.WriteStartElement("single");
                        writer.WriteString("true");
                        writer.WriteEndElement();
                        break;

                    case QuestionMultiple qm:
                        writer.WriteAttributeString("type", "multichoice");
                        writer.WriteStartElement("single");
                        writer.WriteString("false");
                        writer.WriteEndElement();
                        break;

                    case QuestionAppariement qmt:
                        writer.WriteAttributeString("type", "matching");
                        break;

                    case QuestionNumerical qn:
                        writer.WriteAttributeString("type", "numerical");
                        break;

                    case QuestionShort qs:
                        writer.WriteAttributeString("type", "shortanswer");
                        break;

                    default:
                        writer.WriteAttributeString("type", "essay");
                        break;
                    }
                    if (q.nomq.Equals(""))
                    {
                        q.nomq = "Question " + i;
                    }
                    writer.WriteStartElement("name");
                    writer.WriteStartElement("text");
                    writer.WriteString(q.nomq);
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                    if (q.getTitre().Equals(""))
                    {
                        q.titre[0] = "No title";
                    }

                    writer.WriteStartElement("questiontext");
                    writer.WriteStartElement("text");
                    writer.WriteString(q.getTitre());
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                    if (!q.feedbackQ.Equals(""))
                    {
                        writer.WriteStartElement("generalfeedback");
                        writer.WriteStartElement("text");
                        writer.WriteString(q.feedbackQ);
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }
                    if (q is QuestionOuverteAMC)
                    {
                        q.getReponses().Clear();
                    }
                    foreach (Reponse r in q.getReponses())
                    {
                        if (r is ReponseSimple)
                        {
                            String        fraction;
                            ReponseSimple rs = (ReponseSimple)r;
                            if (rs.isTrue())
                            {
                                fraction = "100";
                            }
                            else
                            {
                                fraction = "0";
                            }
                            writer.WriteStartElement("answer");
                            writer.WriteAttributeString("fraction", fraction);
                            writer.WriteStartElement("text");
                            writer.WriteString(rs.texte);
                            writer.WriteEndElement();
                            if (!rs.feedbackR.Equals(""))
                            {
                                writer.WriteStartElement("feedback");
                                writer.WriteStartElement("text");
                                writer.WriteString(rs.feedbackR);
                                writer.WriteEndElement();
                                writer.WriteEndElement();
                            }
                            writer.WriteEndElement();
                        }
                        if (r is ReponseMatching)
                        {
                            ReponseMatching rm = (ReponseMatching)r;
                            writer.WriteStartElement("subquestion");
                            writer.WriteStartElement("text");
                            writer.WriteString(rm.texte1);
                            writer.WriteEndElement();
                            writer.WriteStartElement("answer");
                            writer.WriteStartElement("text");
                            writer.WriteString(rm.texte2);
                            writer.WriteEndElement();
                            writer.WriteEndElement();
                            writer.WriteEndElement();
                        }
                    }
                    writer.WriteEndElement();
                    i++;
                }
            }
            writer.WriteEndElement();
            writer.WriteEndDocument();
            Console.WriteLine(nbquestions + " questions converties");
            writer.Close();
        }