prakhar1989 / react-surveyman

SurveyMan in React
http://prakhar.me/react-surveyman
BSD 2-Clause "Simplified" License
154 stars 27 forks source link

Survey Incremental Validation #35

Open prakhar1989 opened 9 years ago

prakhar1989 commented 9 years ago

Add support for incrementally validating survey by making a ajax call to runner.jar.

prakhar1989 commented 9 years ago

@etosch - I have cloned and built runner.jar on my computer. Can you paste some examples on how I can run sample json survey to validate with the jar file.

etosch commented 9 years ago

runner.jar handles communication with backends; @jfoley threw together a StaticAnalysisServer for running the static analyses (which includes the validation).

Send the request as json to /analyser via POST.

On 7/19/15 12:18 PM, Prakhar Srivastav wrote:

Add support for incrementally validating survey by making a ajax call to runner.jar.

— Reply to this email directly or view it on GitHub https://github.com/prakhar1989/react-surveyman/issues/35.

prakhar1989 commented 9 years ago

Hi @etosch

So I pulled in the Surveyman code and was able to build the package too. However, I'm unable to start the server. Can you tell me what's wrong?

PS: Not quite well-versed with the java stack :grimacing:

 java -cp edu.umass.cs.surveyman.server.StaticAnalysisServer
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
prakhar1989 commented 9 years ago

Run command - java -cp surveyman.jar edu.umass.cs.surveyman.server.StaticAnalysisServer

So I was able to run the server and hit the /analyze route but no matter what JSON is sent in POST, the server keeps throwing up an exception.

Here's the curl request that I'm making

curl -X POST -H "Content-Type: application/json" -d '{"survey": [
    {
        "id": "b_10101",
        "randomize": true,
        "questions": [],
        "subblocks": []
    }
]}' 'http://localhost:1234/analyze'
java.lang.NullPointerException
    at edu.umass.cs.surveyman.input.json.JSONParser.makeCorrelationMap(JSONParser.java:258)
    at edu.umass.cs.surveyman.input.json.JSONParser.populateSurvey(JSONParser.java:363)
    at edu.umass.cs.surveyman.input.json.JSONParser.parse(JSONParser.java:382)
    at edu.umass.cs.surveyman.server.StaticAnalysisServer.parseJSON(StaticAnalysisServer.java:175)
    at edu.umass.cs.surveyman.server.StaticAnalysisServer.analyzeRequest(StaticAnalysisServer.java:118)
    at edu.umass.cs.surveyman.server.StaticAnalysisServer$1.handle(StaticAnalysisServer.java:46)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:363)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:483)
    at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:931)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:992)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
    at java.lang.Thread.run(Thread.java:745)

@jjfiv / @etosch: Any pointers?

prakhar1989 commented 9 years ago

With the latest build the server is working now. Here's what I get when I run the curl above -

<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 400 SurveyException: A survey must have at least one question.</title>
</head>
<body>
<h2>HTTP ERROR: 400</h2>
<p>Problem accessing /analyze. Reason:
<pre>    SurveyException: A survey must have at least one question.</pre></p>

So then I added a single question (as shown below) but now I keep getting a 501 Unimplemented error.

{"survey": [
    {
        "id": "b_10101",
        "randomize": true,
        "questions": [
        {
          "id": "q_5847",
          "qtext": "First question",
          "options": [
            {
              "id": "o_97512",
              "otext": "first"
            },
            {
              "id": "o_57705",
              "otext": "second"
            },
            {
              "id": "o_32878",
              "otext": "third"
            }
          ],
          "ordering": false,
          "freetext": false,
          "exclusive": true
        }
      ],
      "subblocks": []
    }
]}
etosch commented 9 years ago

s/ordering/ordered

prakhar1989 commented 9 years ago

Tried. Same error :cry:

etosch commented 9 years ago

It's failing when trying to assign breakoff (not finding the permitBreakoff tag). This isn't required, though, and the assignment for that value does check to see if the tag is present in the JSON node. More on this in a minute.

prakhar1989 commented 9 years ago

@etosch: I just noticed that the server response is missing access-control headers because of which I'm unable to make requests to it via the react-surveyman app.

etosch commented 9 years ago

@jjfiv merged; try out and confirm.

  Emma Tosch   etosch@fastmail.fm

On Fri, Aug 14, 2015, at 02:13 AM, Prakhar Srivastav wrote:

@etosch[1]: I just noticed that the server response is missing access-control headers because of which I'm unable to make requests to it via the react-surveyman app.

— Reply to this email directly or view it on GitHub[2].

Links:

  1. https://github.com/etosch
  2. https://github.com/prakhar1989/react-surveyman/issues/35#issuecomment-131035232
prakhar1989 commented 9 years ago

I downloaded the latest build and tried running the server - but I still can't see the new headers.

curl -i POST -H "Content-Type: application/json" -d '{"survey": [
    {
        "id": "b_10101",
        "randomize": true,
        "questions": [
        {
          "id": "q_5847",
          "qtext": "First question",
          "options": [
            {
              "id": "o_97512",
              "otext": "first"
            },
            {
              "id": "o_57705",
              "otext": "second"
            },
            {
              "id": "o_32878",
              "otext": "third"
            }
          ],
          "ordered": false,
          "freetext": false,
          "exclusive": true
        }
      ],
      "subblocks": []
    }
]}
' 'http://localhost:1234/analyze' | head

> HTTP/1.1 200 OK
Content-Length: 831
Server: Jetty(7.x.y-SNAPSHOT)

Min Path Length:    1
Max Path Length:    1
Average Path Length:    1.000000
Max Possible Entropy:   1.584963
Prob. False Correlation:    1.000000
group,percentBots,entropy,TP,FP,TN,FN
etosch commented 9 years ago

I see the new access control header when running locally; will upload my jar.

etosch commented 9 years ago

See https://github.com/SurveyMan/SurveyMan/releases/download/v1.6.6/surveyman.jar