Ok, this might be a mess.
I just recently learned Javascript and Firebase and i have this project for the school i'm currently working at where students can do exams on a website. The answer keys for the exam is stored in Firebase Firestore in a collection named "answerkeys".
I use Javascript to change the document IDs in this "answerkeys" collection so that each document ID is named like this:
collection /answerkey/
math01 {
answerKey : a,
subject : math,
questionNum : 01,
score: 5
},
math02 {
answerKey : b,
subject : math,
questionNum : 02,
score: 15
},
....,
science01 {
answerKey : b,
subject : science,
questionNum : 02,
score: 10
},
science02 {
answerKey : c,
subject : science,
questionNum : 02,
score: 20
}
So the document ID math01 represents subject: math & question number: 01.
I use subject: math for querying, so whenever it's math exam, i just query it like this:
query(collection(db, "exam"), where("category", "==", "math")
When students submit their answer, it is stored like this in their user profile:
collection /users/
userID (generated by firebase) {
firstName : Jeff,
lastName : Kalimba,
subject1 : math,
subject2 : science,
subject3 : english
answer : {
math01: a,
math02: b,
...,
science01: c,
science02: a,
...,
english01: e,
english02: b,
...
}
}
And now i'm absolutely confused how to do the grading. How should i approach this problem if the requirement is to show, say of 1.000 students, name the top 25%?
I'm not even sure now if i made the right data structure. And now the amount of student data actually is 1.000 students. So to redo the data structure will take quite some time. If it's possible, i'd like to avoid that.
What i have in mind now is to query all names where subject 1 = math. This will not be efficient at all because some students have subject 2 = math (because i mistakenly thought at first that the order is not important). But it is what i currently have. So is there an efficient way to get to the grading and then the top 25%?
I don't need the answers and suggestions to be in the form of JS code, but what is the right steps to approach this problem? I'm lost with what to do next, what i should do first? Or could you point out that i should've done the structure this way or that way instead of what it is currently?
CodePudding user response:
Copying from the comments above:
You can calculate the score for each student and store that in the users
collection in a new field score
. Now you can simply query the top N documents by ordering on the new score
field.