Skip to content

Commit

Permalink
Merge branch 'pr/279'
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey-wu committed May 17, 2024
2 parents ceee90c + 98993f0 commit 1ee0150
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 72 deletions.
4 changes: 4 additions & 0 deletions client/bootstrap/dark.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/bootstrap/dark.css.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions client/bootstrap/light.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/bootstrap/light.css.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions client/multiplayer/room.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ <h1 id="funny-toast-text" class="me-auto text-danger"></h1>
-
<span class="sliderValue1" id="year-range-b">2024</span>
<div id="slider"></div>
<div class="alert small-alert alert-danger" role="alert" id="yearRangeAlert" style="display: none">
Invalid input. Years must be after or during each other to update.
</div>
</section>
</div>
<div class="mt-2" id="general-settings">
Expand Down
10 changes: 8 additions & 2 deletions client/multiplayer/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ socket.onmessage = function (event) {
break;
case 'packet-number':
data.value = arrayToRange(data.value);
// eslint-disable-next-line no-fallthrough
// eslint-disable-next-line no-fallthrough
case 'set-name':
if (data.value.length > 0) {
logEvent(data.username, `changed the ${data.type} to ${data.value}`);
Expand Down Expand Up @@ -872,7 +872,11 @@ document.getElementById('skip').addEventListener('click', function () {


document.getElementById('packet-number').addEventListener('change', function () {
socket.send(JSON.stringify({ type: 'packet-number', value: rangeToArray(this.value, maxPacketNumber) }));
const range = rangeToArray(this.value, maxPacketNumber);
if (range.some((num) => num < 1 || num > maxPacketNumber))
return document.getElementById('packet-number').classList.add('is-invalid');
else document.getElementById('packet-number').classList.remove('is-invalid');
socket.send(JSON.stringify({ type: 'packet-number', value: range }));
});


Expand Down Expand Up @@ -980,6 +984,8 @@ document.getElementById('username').addEventListener('change', function () {

document.getElementById('year-range-a').onchange = function () {
const [minYear, maxYear] = $('#slider').slider('values');
if (maxYear < minYear) return document.querySelector('#yearRangeAlert').style.display = '';
else document.querySelector('#yearRangeAlert').style.display = 'none';
socket.send(JSON.stringify({ type: 'year-range', minYear, maxYear }));
};

Expand Down
2 changes: 1 addition & 1 deletion client/utilities/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import star from '../auth/star.js';
import { escapeHTML, removeParentheses } from './strings.js';
import { removeParentheses } from './strings.js';

// Constants and functions useful for quizbowl.

Expand Down
82 changes: 46 additions & 36 deletions database/account-info/user-stats/get-stats-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,32 @@ async function getStatsHelper({ user_id, questionType, groupByField, difficultie
{ $addFields: { 'createdAt': { '$toDate': '$_id' } } },
{ $match: matchDocument },
{ $match: { [groupByField]: { $exists: true } } },
{ $addFields: {
is15: { $gt: ['$pointValue', 10] },
is10: { $eq: ['$pointValue', 10] },
isNeg5: { $lt: ['$pointValue', 0] },
} },
{ $group: {
numCorrect: { $sum: { $cond: ['$isCorrect', 1, 0] } },
_id: '$' + groupByField,
count: { $sum: 1 },
'15s': { $sum: { $cond: ['$is15', 1, 0] } },
'10s': { $sum: { $cond: ['$is10', 1, 0] } },
'-5s': { $sum: { $cond: ['$isNeg5', 1, 0] } },
totalCelerity: { $sum: '$celerity' },
totalCorrectCelerity: { $sum: { $cond: ['$isCorrect', '$celerity', 0] } },
totalPoints: { $sum: '$pointValue' },
pptu: { $avg: '$pointValue' },
} },
{ $addFields: {
averageCorrectCelerity: { $cond: ['$numCorrect', { $divide: ['$totalCorrectCelerity', '$numCorrect'] }, 0] },
} },
{
$addFields: {
is15: { $gt: ['$pointValue', 10] },
is10: { $eq: ['$pointValue', 10] },
isNeg5: { $lt: ['$pointValue', 0] },
},
},
{
$group: {
numCorrect: { $sum: { $cond: ['$isCorrect', 1, 0] } },
_id: '$' + groupByField,
count: { $sum: 1 },
'15s': { $sum: { $cond: ['$is15', 1, 0] } },
'10s': { $sum: { $cond: ['$is10', 1, 0] } },
'-5s': { $sum: { $cond: ['$isNeg5', 1, 0] } },
totalCelerity: { $sum: '$celerity' },
totalCorrectCelerity: { $sum: { $cond: ['$isCorrect', '$celerity', 0] } },
totalPoints: { $sum: '$pointValue' },
pptu: { $avg: '$pointValue' },
},
},
{
$addFields: {
averageCorrectCelerity: { $cond: ['$numCorrect', { $divide: ['$totalCorrectCelerity', '$numCorrect'] }, 0] },
},
},
{ $sort: { pptu: -1, averageCorrectCelerity: -1, totalPoints: -1 } },
]).toArray();
case 'bonus':
Expand All @@ -51,22 +57,26 @@ async function getStatsHelper({ user_id, questionType, groupByField, difficultie
{ $match: matchDocument },
{ $match: { [groupByField]: { $exists: true } } },
{ $addFields: { pointValue: { $sum: '$pointsPerPart' } } },
{ $addFields: {
is30: { $eq: ['$pointValue', 30] },
is20: { $eq: ['$pointValue', 20] },
is10: { $eq: ['$pointValue', 10] },
is0: { $eq: ['$pointValue', 0] },
} },
{ $group: {
_id: '$' + groupByField,
count: { $sum: 1 },
'30s': { $sum: { $cond: ['$is30', 1, 0] } },
'20s': { $sum: { $cond: ['$is20', 1, 0] } },
'10s': { $sum: { $cond: ['$is10', 1, 0] } },
'0s': { $sum: { $cond: ['$is0', 1, 0] } },
totalPoints: { $sum: '$pointValue' },
ppb: { $avg: '$pointValue' },
} },
{
$addFields: {
is30: { $eq: ['$pointValue', 30] },
is20: { $eq: ['$pointValue', 20] },
is10: { $eq: ['$pointValue', 10] },
is0: { $eq: ['$pointValue', 0] },
},
},
{
$group: {
_id: '$' + groupByField,
count: { $sum: 1 },
'30s': { $sum: { $cond: ['$is30', 1, 0] } },
'20s': { $sum: { $cond: ['$is20', 1, 0] } },
'10s': { $sum: { $cond: ['$is10', 1, 0] } },
'0s': { $sum: { $cond: ['$is0', 1, 0] } },
totalPoints: { $sum: '$pointValue' },
ppb: { $avg: '$pointValue' },
},
},
{ $sort: { ppb: -1, totalPoints: -1 } },
]).toArray();
}
Expand Down
30 changes: 18 additions & 12 deletions database/qbreader/get-frequency-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,26 @@ function mergeTwoSortedArrays(array1, array2, keyFunction, combineFunction) {
* @param {number} [limit=50] The maximum number of answers to return. Defaults to 50.
* @returns {Promise<{ answer: string, count: number }[]>} The frequency list.
*/
async function getFrequencyList(subcategory, difficulties=DIFFICULTIES, limit=50, questionType='all') {
async function getFrequencyList(subcategory, difficulties = DIFFICULTIES, limit = 50, questionType = 'all') {
const tossupAggregation = [
{ $match: { subcategory, difficulty: { $in: difficulties } } },
{ $addFields: {
// This is a regex that matches everything before the first open parenthesis or bracket.
regex: { $regexFind: { input: '$answer_sanitized', regex: /^[^[(]*/ } },
} },
{ $addFields: {
// This is a regex that matches everything outside of parentheses ()
regex: { $regexFind: { input: '$regex.match', regex: /[^()]+(?![^(]*\))/ } },
} },
{ $addFields: {
sanitized_answer: { $trim: { input: '$regex.match' } },
} },
{
$addFields: {
// This is a regex that matches everything before the first open parenthesis or bracket.
regex: { $regexFind: { input: '$answer_sanitized', regex: /^[^[(]*/ } },
},
},
{
$addFields: {
// This is a regex that matches everything outside of parentheses ()
regex: { $regexFind: { input: '$regex.match', regex: /[^()]+(?![^(]*\))/ } },
},
},
{
$addFields: {
sanitized_answer: { $trim: { input: '$regex.match' } },
},
},
{ $group: { _id: '$sanitized_answer', count: { $sum: 1 } } },
{ $match: { _id: { $ne: null } } },
{ $addFields: { answer_sanitized: '$_id' } },
Expand Down
18 changes: 13 additions & 5 deletions scss/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
$font-family-sans-serif: Helvetica, sans-serif;
$link-decoration: none;

$popover-body-padding-y: 0;
$popover-body-padding-x: 0;
$popover-max-width: 100%;
$popover-body-padding-y: 0;
$popover-body-padding-x: 0;
$popover-max-width: 100%;

// 6. Optionally include any other parts as needed
@import url(https://cdn.jsdelivr.net/npm/firacode@6.2.0/distr/fira_code.css); // Fira Code font
Expand Down Expand Up @@ -79,10 +79,14 @@ $popover-max-width: 100%;
font-weight: bold;
}

code { font-family: 'Fira Code', monospace; }
code {
font-family: 'Fira Code', monospace;
}

@supports (font-variation-settings: normal) {
code { font-family: 'Fira Code VF', monospace; }
code {
font-family: 'Fira Code VF', monospace;
}
}

.logo-prefix {
Expand Down Expand Up @@ -118,5 +122,9 @@ a.list-group-item:hover {
color: inherit;
}

.small-alert {
--bs-alert-padding-y: 0.5rem;
}

@import "./dual-slider";
@import "./dropdown-checklist";
Loading

0 comments on commit 1ee0150

Please sign in to comment.