Skip to content

Commit

Permalink
add verbose option
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey-wu committed Feb 16, 2023
1 parent f1c840c commit e33e901
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions server/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async function getPacket({ setName, packetNumber, questionTypes = ['tossups', 'b
* @param {Array<String>} subcategories
* @returns {Promise<{'tossups': {'count': Number, 'questionArray': Array<JSON>}, 'bonuses': {'count': Number, 'questionArray': Array<JSON>}}>}
*/
async function getQuery({ queryString, difficulties, setName, searchType = 'all', questionType = 'all', categories, subcategories, maxReturnLength, randomize = false, regex = false } = {}) {
async function getQuery({ queryString, difficulties, setName, searchType = 'all', questionType = 'all', categories, subcategories, maxReturnLength, randomize = false, regex = false, verbose = true } = {}) {
if (!queryString) queryString = '';
if (!difficulties || difficulties.length === 0) difficulties = [0].concat(DIFFICULTIES);
if (!categories || categories.length === 0) categories = CATEGORIES;
Expand Down Expand Up @@ -198,7 +198,6 @@ async function getQuery({ queryString, difficulties, setName, searchType = 'all'
if (questionType === 'bonus' || questionType === 'all')
bonusQuery = queryHelperBonus({ queryString, difficulties, setName, searchType, categories, subcategories, maxReturnLength, randomize });

console.log(`[DATABASE] QUERY: string: ${bcolors.OKCYAN}${queryString}${bcolors.ENDC}; difficulties: ${bcolors.OKGREEN}${difficulties}${bcolors.ENDC}; max length: ${bcolors.OKGREEN}${maxReturnLength}${bcolors.ENDC}; question type: ${bcolors.OKGREEN}${questionType}${bcolors.ENDC}; randomize: ${bcolors.OKGREEN}${randomize}${bcolors.ENDC}; regex: ${bcolors.OKGREEN}${regex}${bcolors.ENDC}; search type: ${bcolors.OKGREEN}${searchType}${bcolors.ENDC}; set name: ${bcolors.OKGREEN}${setName}${bcolors.ENDC};`);

const values = await Promise.all([tossupQuery, bonusQuery]);

Expand All @@ -208,6 +207,9 @@ async function getQuery({ queryString, difficulties, setName, searchType = 'all'
if (values[1])
returnValue.bonuses = values[1];

if (verbose)
console.log(`[DATABASE] QUERY: string: ${bcolors.OKCYAN}${queryString}${bcolors.ENDC}; difficulties: ${bcolors.OKGREEN}${difficulties}${bcolors.ENDC}; max length: ${bcolors.OKGREEN}${maxReturnLength}${bcolors.ENDC}; question type: ${bcolors.OKGREEN}${questionType}${bcolors.ENDC}; randomize: ${bcolors.OKGREEN}${randomize}${bcolors.ENDC}; regex: ${bcolors.OKGREEN}${regex}${bcolors.ENDC}; search type: ${bcolors.OKGREEN}${searchType}${bcolors.ENDC}; set name: ${bcolors.OKGREEN}${setName}${bcolors.ENDC};`);

return returnValue;
}

Expand Down Expand Up @@ -322,7 +324,7 @@ function getRandomName() {
* @param {Array<Number>} yearRange - an array of allowed years. Pass a 0-length array to select any year.
* @returns {Promise<Array<JSON>>}
*/
async function getRandomQuestions({ questionType = 'tossup', difficulties, categories, subcategories, number, yearRange = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023] }) {
async function getRandomQuestions({ questionType = 'tossup', difficulties, categories, subcategories, number, verbose = true, yearRange = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023] }) {
if (!difficulties || difficulties.length === 0) difficulties = DIFFICULTIES;
if (!categories || categories.length === 0) categories = CATEGORIES;
if (!subcategories || subcategories.length === 0) subcategories = SUBCATEGORIES_FLATTENED;
Expand All @@ -347,7 +349,9 @@ async function getRandomQuestions({ questionType = 'tossup', difficulties, categ
return [{}];
}

console.log(`[DATABASE] RANDOM QUESTIONS: difficulties: ${bcolors.OKGREEN}${difficulties}${bcolors.ENDC}; number: ${bcolors.OKGREEN}${number}${bcolors.ENDC}; question type: ${bcolors.OKGREEN}${questionType}${bcolors.ENDC}; categories: ${bcolors.OKGREEN}${categories}${bcolors.ENDC}; subcategories: ${bcolors.OKGREEN}${subcategories}${bcolors.ENDC};`);
if (verbose)
console.log(`[DATABASE] RANDOM QUESTIONS: difficulties: ${bcolors.OKGREEN}${difficulties}${bcolors.ENDC}; number: ${bcolors.OKGREEN}${number}${bcolors.ENDC}; question type: ${bcolors.OKGREEN}${questionType}${bcolors.ENDC}; categories: ${bcolors.OKGREEN}${categories}${bcolors.ENDC}; subcategories: ${bcolors.OKGREEN}${subcategories}${bcolors.ENDC};`);

return questionArray;
}

Expand Down

0 comments on commit e33e901

Please sign in to comment.