-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a111c0
commit 9b8a264
Showing
8 changed files
with
136 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{"answers":{ | ||
"1": "0", | ||
"2": "0", | ||
"3": "0" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<n;i++) { | ||
if (pointsTemp > 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 | ||
} | ||
console.log(getScoreSheet()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"submissions":[{"color":"red","question":1,"answer":3.5,"correct":true,"time":"20:04:32","solvers":["lukas cerny"]}]} |