Created
October 11, 2019 14:26
-
-
Save OtacilioN/bd89866a787288e4bbe17955c999cf29 to your computer and use it in GitHub Desktop.
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
const admin = require("firebase-admin"); | |
let serviceAccount = require("./joaoestudantepk.json"); | |
function countPoints(input) { | |
var ccPoints = 0; | |
var dePoints = 0; | |
var bestCC = { userName: null, points: 0 }; | |
var bestDE = { userName: null, points: 0 }; | |
for (objeto in input) { | |
if (input[objeto].course == "design") { | |
const personPoints = Object.keys(input[objeto]).length; | |
dePoints = dePoints + personPoints; | |
if (personPoints > bestDE.points) { | |
bestDE.userName = input[objeto].userName; | |
bestDE.points = personPoints; | |
} | |
} else { | |
const personPoints = Object.keys(input[objeto]).length; | |
ccPoints = ccPoints + personPoints; | |
if (personPoints > bestCC.points) { | |
bestCC.userName = input[objeto].userName; | |
bestCC.points = personPoints; | |
} | |
} | |
} | |
console.log("\n\nResumo no momento\n\n"); | |
console.log("Pontuação de Computação", ccPoints); | |
console.log("Pontuação de Design", dePoints); | |
console.log( | |
"O melhor de CC foi:", | |
bestCC.userName, | |
"com ", | |
bestCC.points, | |
" pontos" | |
); | |
console.log( | |
"O melhor de DE foi:", | |
bestDE.userName, | |
"com ", | |
bestDE.points, | |
" pontos" | |
); | |
} | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount) | |
}); | |
let db = admin.firestore(); | |
const objetao = {}; | |
db.collection("tdc") | |
.get() | |
.then(snapshot => { | |
snapshot.forEach(doc => { | |
objetao[doc.id] = doc.data(); | |
console.log(doc.id, "=>", doc.data()); | |
}); | |
countPoints(objetao); | |
}) | |
.catch(err => { | |
console.log("Error getting documents", err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment