Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.Question


     * @since 1.2.4
     */
    public static boolean loadQuestionData(File inputFile, EntityManager em)
    {
        EntityTransaction tx = em.getTransaction();
        Question question = new Question();
        Query query;
        Document doc;
        try
        {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder builder = factory.newDocumentBuilder();
            doc = builder.parse(inputFile);
            XPathFactory xFactory = XPathFactory.newInstance();
            XPath xpath = xFactory.newXPath();
            // Loop through each of the questions and build the set of questions
            NodeList nodes = (NodeList) xpath.evaluate("/GradedEvent/Question", doc, XPathConstants.NODESET);
            for (int i = 0; i < nodes.getLength(); i++)
            {
                Question quest;
                boolean qnew = true;
                Node q = nodes.item(i);
                String qname = xpath.evaluate("./Name/@name", q);
                String qcategory = xpath.evaluate("./@category", q);
               
                // Switch to the CategoryDAO class
                CategoryDAO catDAO = new CategoryDAO(em);
                //query = em.createQuery("SELECT c FROM Category c WHERE c.name = :cname");
                //query.setParameter("cname", qcategory);
                Category qcat;
                try
                {
                    //qcat = (Category) query.getSingleResult();
                    qcat = catDAO.find(qcategory);
                } catch (NoResultException e)
                {
                    qcat = new Category(qcategory);
                    Long newCatId = catDAO.create(qcat);
                    qcat.setId(newCatId);
                }
                //tx.begin();
                //em.persist(qcat);
                //tx.commit();
                qcat = catDAO.update(qcat);
                query = em.createQuery("SELECT q FROM Question q WHERE "
                        + "q.name = :name AND q.category = :cat");
                query.setParameter("name", qname);
                query.setParameter("cat", qcat);
                try
                {
                    quest = (Question) query.getSingleResult();
                    qnew = false;
                } catch (NoResultException e)
                {
                    quest = new Question(qname, qcat);
                    qnew = true;
                }

                if (qnew)
                {
                    // This is a new question, so add the other details
                    String qidStr = xpath.evaluate("./@id", q);
                    Long qid;
                    if (qidStr.equals(""))
                    {
                        qid = -1L;
                    } else
                    {
                        qid = Long.parseLong(xpath.evaluate("./@id", q));
                    }

                    String qdesc = xpath.evaluate("./Description/text()", q);
                    quest.setDescription(qdesc);
                    boolean verbatim;
                    if (xpath.evaluate("./Verbatim/@value", q).equals("true"))
                    {
                        verbatim = true;
                    } else
                    {
                        verbatim = false;
                    }
                    quest.setVerbatim(verbatim);

                    // Set whether the question requires ordered output
                    boolean orderedOutput;
                    if (xpath.evaluate("./OrderedOutput/@value", q).equals("true"))
                    {
                        orderedOutput = true;
                    } else
                    {
                        orderedOutput = false;
                    }

                    // Parse test cases for each question
                    NodeList testCaseNodes = (NodeList) xpath.evaluate("./TestCase", q, XPathConstants.NODESET);
                    for (int j = 0; j < testCaseNodes.getLength(); j++)
                    {
                        TestCase tc = new TestCase();
                        Node t = testCaseNodes.item(j);
                        String value = xpath.evaluate("./Value/@value", t);
                        tc.setValue(new BigDecimal(value));
                        NodeList tcInputs = (NodeList) xpath.evaluate("./input", t, XPathConstants.NODESET);
                        for (int k = 0; k < tcInputs.getLength(); k++)
                        {
                            Node inputNode = tcInputs.item(k);
                            String input = inputNode.getTextContent();
                            //System.out.println("Input: " + input);
                            tc.addInput(input);
                        }
                        NodeList tcOutputs = (NodeList) xpath.evaluate("./output", t, XPathConstants.NODESET);
                        for (int k = 0; k < tcOutputs.getLength(); k++)
                        {
                            Node outputNode = tcOutputs.item(k);
                            String output = outputNode.getTextContent();
                            //System.out.println("Expected Output: " + output);
                            tc.addOutput(output);
                        }
                        NodeList tcExcludes = (NodeList) xpath.evaluate("./exclude", t, XPathConstants.NODESET);
                        for (int k = 0; k < tcExcludes.getLength(); k++)
                        {
                            Node outputNode = tcExcludes.item(k);
                            String exclude = outputNode.getTextContent();
                            //System.out.println("Exclusion: " + exclude);
                            tc.addExclusion(exclude);
                        }
                        tx.begin();
                        em.persist(tc);
                        tx.commit();
                        quest.addTestCase(tc);
                    }
                }
                tx.begin();
                em.persist(quest);
                tx.commit();
View Full Code Here


                                + sReport.getResults().get(j).getScore().toPlainString()
                                + "</p>");
                        responseWriter.println("<table border='1'>\n<tr>\n<th>Test Case</th>");
                        responseWriter.println("<th>Inputs</th><th>Expected Output</th>");
                        responseWriter.println("<th>Actual Output</th>\n</tr>\n");
                        Question question = sReport.getResults().get(j).getQuestion();
                        // Loop through all the Test Cases
                        for (int k = 0; k < question.getTestCases().size(); k++)
                        {
                            int testCaseIndex = k + 1;
                            responseWriter.println("<tr>\n<td>" + testCaseIndex
                                    + "</td>");
                            responseWriter.println("<td><center>");
                            TestCase testCase = question.getTestCases().get(k);
                            for (int m = 0; m < testCase.getInputs().size(); m++)
                            {
                                responseWriter.println(testCase.getInputs().get(m)
                                        + "<br />");
                            }
View Full Code Here

            LOGGER.info("Loaded " + availQuestions.size() + " questions.");

            for (Iterator i = availQuestions.iterator(); i.hasNext();)
            {
                Question question = (Question) i.next();
                question_names.add(question.getName().toUpperCase());
            }

            // Thread variables to track the Question and our location in it
            Question question = new Question();
            // Initialize the iterator with some dummy (aka empty) data
            // Iterator will be properly initialized when the question has been picked
            Iterator tcIterator = question.getTestCases().iterator();
            TestCase tc = new TestCase();

            while (!done)
            {
                String line;
                try
                {
                    line = in.nextLine();
                } catch (NoSuchElementException exc)
                {
                    line = null;
                }
                if (line == null)
                {
                    done = true;
                } else
                {
                    if (!input_sent && line.trim().equalsIgnoreCase("DIRECTORY"))
                    {
                        for (int i = 0; i < question_names.size(); i++)
                        {
                            out.print(question_names.get(i) + "\r\n");
                            out.flush();
                        }
                        out.print("EOF\r\n");
                        out.flush();
                        done = true;
                    } else if (!input_sent
                            && question_names.contains(line.trim().toUpperCase()))
                    {
                        for (int i = 0; i < availQuestions.size(); i++)
                        {
                            Question q = availQuestions.get(i);
                            // We can set the question here because we know that
                            // the question exists on the server--we're in this
                            // block
                            if (q.getName().equalsIgnoreCase(line.trim()))
                            {
                                question = q;
                            }
                        }
                        /**
 
View Full Code Here

            em.persist(dbCat);
            em.getTransaction().commit();
        }

        query = em.createQuery("SELECT q FROM Question q");
        Question question;
        try
        {
            question = (Question) query.getSingleResult();
        } catch (NoResultException ex)
        {
            question = new Question("Runaway", dbCat, "Test Question");
            em.getTransaction().begin();
            em.persist(question);
            em.getTransaction().commit();
        }
        gevent.addQuestion(question);
View Full Code Here

     */
    public TestCaseGenThread()
    {
        processBuilder = new ProcessBuilder();
        testFile = null;
        question = new Question();
        node = null;
        type = 0;
    }
View Full Code Here

TOP

Related Classes of com.darkhonor.rage.model.Question

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.