diff --git a/node_modules/fs/README.md b/node_modules/fs/README.md new file mode 100644 index 00000000..5e9a74ca --- /dev/null +++ b/node_modules/fs/README.md @@ -0,0 +1,9 @@ +# Security holding package + +This package name is not currently in use, but was formerly occupied +by another package. To avoid malicious use, npm is hanging on to the +package name, but loosely, and we'll probably give it to you if you +want it. + +You may adopt this package by contacting support@npmjs.com and +requesting the name. diff --git a/node_modules/fs/package.json b/node_modules/fs/package.json new file mode 100644 index 00000000..448aa6e9 --- /dev/null +++ b/node_modules/fs/package.json @@ -0,0 +1,78 @@ +{ + "_args": [ + [ + { + "raw": "fs", + "scope": null, + "escapedName": "fs", + "name": "fs", + "rawSpec": "", + "spec": "latest", + "type": "tag" + }, + "/Users/lc/Documents/LUKI/EDINBURGH/PROGRAMMING/ReactJS/porgor-patch" + ] + ], + "_from": "fs@latest", + "_id": "fs@0.0.1-security", + "_inCache": true, + "_location": "/fs", + "_nodeVersion": "4.1.2", + "_npmUser": { + "name": "ehsalazar", + "email": "ernie@npmjs.com" + }, + "_npmVersion": "3.10.5", + "_phantomChildren": {}, + "_requested": { + "raw": "fs", + "scope": null, + "escapedName": "fs", + "name": "fs", + "rawSpec": "", + "spec": "latest", + "type": "tag" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "_shasum": "8a7bd37186b6dddf3813f23858b57ecaaf5e41d4", + "_shrinkwrap": null, + "_spec": "fs", + "_where": "/Users/lc/Documents/LUKI/EDINBURGH/PROGRAMMING/ReactJS/porgor-patch", + "author": "", + "bugs": { + "url": "https://github.com/npm/security-holder/issues" + }, + "dependencies": {}, + "description": "This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.", + "devDependencies": {}, + "directories": {}, + "dist": { + "shasum": "8a7bd37186b6dddf3813f23858b57ecaaf5e41d4", + "tarball": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz" + }, + "homepage": "https://github.com/npm/security-holder#readme", + "keywords": [], + "license": "ISC", + "main": "index.js", + "maintainers": [ + { + "name": "ehsalazar", + "email": "ernie@npmjs.com" + } + ], + "name": "fs", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/npm/security-holder.git" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "version": "0.0.1-security" +} diff --git a/package.json b/package.json index 933cd516..c322575c 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "dependencies": { "countdown": "^2.6.0", + "fs": "0.0.1-security", "react": "^15.5.4", "react-dom": "^15.5.4" }, diff --git a/src/data/answerSheet.json b/src/data/answerSheet.json new file mode 100644 index 00000000..ad45b2a7 --- /dev/null +++ b/src/data/answerSheet.json @@ -0,0 +1,5 @@ +{"answers":{ + "1": "0", + "2": "0", + "3": "0" +}} \ No newline at end of file diff --git a/src/data/dataTest.json b/src/data/dataTest.json new file mode 100644 index 00000000..c66ef78a --- /dev/null +++ b/src/data/dataTest.json @@ -0,0 +1,5 @@ +{"scoreSheet":[{"color":"red","points":0,"questions":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}, +{"color":"white","points":0,"questions":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}, +{"color":"blue","points":0,"questions":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}, +{"color":"black","points":0,"questions":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}], +"submissions":[{"color":"red","question":1,"answer":3.5,"correct":true,"time":"20:04:32","solvers":["lukas cerny"]}]} \ No newline at end of file diff --git a/src/data/database.js b/src/data/database.js index bb970eda..756a3042 100644 --- a/src/data/database.js +++ b/src/data/database.js @@ -1,49 +1,44 @@ -const scoreSheet = [ -{color:"red",points:0,questions:{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}, -{color:"blue",points:0,questions:{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}, -{color:"white",points:0,questions:{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}, -{color:"black",points:0,questions:{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}]; +const fs = require('fs'); -let submissionsSheet = [ -{color:"red",question:"2",answer:"5.6",time:"20:32:34"}, -{color:"blue",question:"1",answer:"7",time:"20:56:08"}, -{color:"black",question:"1",answer:"8",time:"20:51:12"} -] +const teams = ["red", "blue", "black", "white"]; const getRandomArbitrary = (min, max) => Math.random() * (max - min) + min; -const answerSheet = {"1":"7","2":"5.6"}; - -const teams = ["red", "blue", "black", "white"]; - -let initializeScoreSheet = (n) => { - teams.map(team => { - const points = getRandomArbitrary(0,n); - const pointsTemp = points; - let sheet; - for (let i=0;i 0) { - sheet[i] = "correct"; - } else { - sheet[i] = 0; - } +let getScoreSheet = () => { + fs.readFile("scoreSheet.json", (err, data) => { + if (err) { + console.log(err); + } else { + return JSON.parse(data).scoreSheet; } }) } -let addSubmission = (t, q, a) => { - let date = new Date(); - submissionsSheet.push({color:t,question:q,answer:a,time:date.getHours().toString().concat(date.getMinutes().toString())}) - if (validateAnswer(q,a)) { - scoreSheet[t].questions[q] = "correct"; - scoreSheet[t].points++; - } else { - scoreSheet[t].questions[q]++; - } +let addSubmission = (team, question, answer, solvers) => { + fs.readFile('submissionSheet.json', (err, data) => { + if (err){ + console.log(err); + } else { + let submissionSheet = JSON.parse(data); + const date = new Date(); + submissionSheet.submissions.push({"color":team,"question":question,"answer":answer, + "time":date.getHours().toString().concat(":",date.getMinutes().toString()),"correct":validateAnswer(question, answer)}); + const json = JSON.stringify(submissionSheet); + fs.writeFile('submissionSheet.json', json, (err) => (err) ? console.log(err) : console.log("Submission recorded.")); // write it back + } + }); } -let validateAnswer = (q, a) => a==answerSheet[q]; +let validateAnswer = (q, a) => { + fs.readFile('answerSheet.json', (err, data) => { + if (err) { + console.log(err); + return false; + } else { + let answerSheet = JSON.parse(data); + return answerSheet.answers[q]==a.toString(); + } + }) +} -module.exports = { - scoreSheet: scoreSheet -} \ No newline at end of file +console.log(getScoreSheet()); \ No newline at end of file diff --git a/src/data/scoreSheet.json b/src/data/scoreSheet.json new file mode 100644 index 00000000..73df3668 --- /dev/null +++ b/src/data/scoreSheet.json @@ -0,0 +1,4 @@ +{"scoreSheet":{"red":{"color":"red","points":0,"questions":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}, +"white":{"color":"white","points":0,"questions":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}, +"blue":{"color":"blue","points":0,"questions":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}, +"black":{"color":"black","points":0,"questions":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0}}}} \ No newline at end of file diff --git a/src/data/submissionSheet.json b/src/data/submissionSheet.json new file mode 100644 index 00000000..827772ac --- /dev/null +++ b/src/data/submissionSheet.json @@ -0,0 +1 @@ +{"submissions":[{"color":"red","question":1,"answer":3.5,"correct":true,"time":"20:04:32","solvers":["lukas cerny"]}]} \ No newline at end of file