From d084574b2aa3cf2f33858b77a854007f984e7974 Mon Sep 17 00:00:00 2001 From: Hanneli Date: Thu, 11 Mar 2021 22:43:47 -0500 Subject: [PATCH] Data collection fix - proper encoding of solution key --- Dockerfile | 4 ++-- node/app.js | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index e71e23173..05529e16f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ RUN opam install . --destdir /home/opam/install-prefix --locked FROM alpine:3.7 as client RUN apk update \ - && apk add ncurses-libs libev dumb-init \ + && apk add ncurses-libs libev dumb-init openssl \ && addgroup learn-ocaml \ && adduser learn-ocaml -DG learn-ocaml @@ -53,7 +53,7 @@ LABEL org.opencontainers.image.vendor="The OCaml Software Foundation" FROM alpine:3.7 as program RUN apk update \ - && apk add ncurses-libs libev dumb-init git \ + && apk add ncurses-libs libev dumb-init git openssl \ && addgroup learn-ocaml \ && adduser learn-ocaml -DG learn-ocaml diff --git a/node/app.js b/node/app.js index f1adc3fcc..80e962220 100644 --- a/node/app.js +++ b/node/app.js @@ -7,7 +7,8 @@ const compile_collection = process.env.COMP_COLLECTION; const eval_collection = process.env.EVAL_COLLECTION; const mongoose = require('mongoose'); -app.use(bodyParser.text({ type: "application/json" })); +// app.use(bodyParser.text({ type: "application/json" })); +app.use(bodyParser.json()); // connect to database // mongoose.connect('mongodb://172.17.0.1/learn-ocaml-code'); @@ -28,10 +29,9 @@ app.post("/grade", function (req, res) { if (req.body) { - const raw_array = req.body; - const split_array = raw_array.split(","); - const collection = JSON.parse(split_array[3]); - let parsedSolStr = split_array.slice(4).join(' ').slice(0, -1); + const split_array = req.body; + const collection = split_array[3]; + let parsedSolStr = split_array[4]; const obj = new Object(); obj.studentId = split_array[1]; obj.timestamp = new Date().toString(); @@ -54,10 +54,9 @@ app.post("/compile", function (req, res) { if (req.body) { - const raw_array = req.body; - const split_array = raw_array.split(","); - const collection = JSON.parse(split_array[3]); - let parsedSolStr = split_array.slice(4).join(' ').slice(0, -1); + const split_array = req.body; + const collection = split_array[3]; + let parsedSolStr = split_array[4]; const obj = new Object(); obj.studentId = split_array[1]; obj.timestamp = new Date().toString(); @@ -78,15 +77,13 @@ app.post("/eval", function (req, res) { if (req.body) { - const raw_array = req.body; - const split_array = raw_array.split(","); - const collection = JSON.parse(split_array[3]); - const parsedSolStr = split_array.slice(4).join(' ').slice(0, -1); + const split_array = req.body; + const collection = split_array[3]; + let parsedSolStr = split_array[4]; const obj = new Object(); obj.studentId = split_array[1]; obj.timestamp = new Date().toString(); obj.solution = parsedSolStr; - const jsonString = JSON.stringify(obj); const solution = JSON.parse( jsonString ); // parse req.body as an object db.collection(collection).insertOne(solution);