diff --git a/backend/index.js b/backend/index.js index 2711cea..839f83d 100644 --- a/backend/index.js +++ b/backend/index.js @@ -57,21 +57,21 @@ cardsCollection.aggregate([ console.log(totalCount + " мемов всего. Квота: " + quota) // Подсчет количества активных пользователей - memeCount.forEach((n) => { - if (n.count > quota/10) + memeCount.forEach((person) => { + if (person.count > quota/10) activeUsers++ }) - memeCount.forEach((n) => { + memeCount.forEach((person) => { // Во сколько раз превышена квота: // (колич. астивных человек в конфе * колич. мемов данного человека / мемов всего) - quotaTimes = activeUsers*n.count/totalCount + quotaTimes = activeUsers*person.count/totalCount if (quotaTimes > 1) { - dropProb[n._id] = 1 - (1/quotaTimes) + dropProb[person._id] = 1 - (1/quotaTimes) } else { - dropProb[n._id] = 0 + dropProb[person._id] = 0 } - console.log(n._id + " ["+n.count+"]: " + dropProb[n._id]) + console.log(person._id + " ["+person.count+"]: " + dropProb[person._id]) }) }) }) @@ -148,6 +148,34 @@ app.get('/score', (req, res) => { } }) +app.get('/stats', async (req, res) => { + if (req.session.loggedIn) { + answersCollection.aggregate([ + { + '$group': { + '_id': '$selected', + 'correct': { + '$sum': { + '$cond': [ + '$correct', 1, 0 + ] + } + }, + 'wrong': { + '$sum': { + '$cond': [ + '$correct', 0, 1 + ] + } + } + } + } + ]).toArray().then(stats => res.status(200).send(stats)) + } else { + res.status(403).send() + } +}) + app.get('/options', async (req, res) => { if (req.session.loggedIn) { res.status(200).send(names) diff --git a/frontend/src/components/Game.vue b/frontend/src/components/Game.vue index d57165c..ccd20c8 100644 --- a/frontend/src/components/Game.vue +++ b/frontend/src/components/Game.vue @@ -14,8 +14,9 @@ - + + @@ -24,6 +25,7 @@ import axios from 'axios' import List from './List.vue' import Result from './Result.vue' import Score from './Score.vue' +import Stats from './Stats.vue' import SquareLoader from 'vue-spinner/src/SquareLoader.vue' @@ -33,6 +35,7 @@ export default { List, Result, Score, + Stats, SquareLoader }, props: { diff --git a/frontend/src/components/Score.vue b/frontend/src/components/Score.vue index 2c3f345..93410c6 100644 --- a/frontend/src/components/Score.vue +++ b/frontend/src/components/Score.vue @@ -42,10 +42,10 @@ span { div { width: 100%; position: fixed; - height: 1em; padding: 0.4em 0px 0.4em 0px; bottom: 0px; border-radius: 0px; + z-index: 100; } } \ No newline at end of file diff --git a/frontend/src/components/Stats.vue b/frontend/src/components/Stats.vue new file mode 100644 index 0000000..2580b91 --- /dev/null +++ b/frontend/src/components/Stats.vue @@ -0,0 +1,80 @@ + + + 🎭 Самый непредсказуемый: {{ mostOriginal }} 🎭 + 🪂 Самый стабильный: {{ mostPredictable }} 🪂 + + + + + + \ No newline at end of file