1
1
import { db } from "./db.js" ;
2
2
import { io } from "../webserver.js" ;
3
+ import { getWeightedRandomIndex } from "./miscutils.js" ;
3
4
console . log ( "Running db query" ) ;
4
5
const doc = process . env . DEV ? "namesListsDev" : "namesLists" ;
5
6
const docRef = db . collection ( "ViewerQueue" ) . doc ( doc ) ;
@@ -13,7 +14,11 @@ export let nameGraveyard: { [key: string]: boolean } = document?.data()?.nameGra
13
14
export async function addName ( name : string ) {
14
15
if ( name === "testSet" ) {
15
16
//TODO: remove this later
16
- const testNames = [ "test1" , "test2" , "test3" , "test4" , "test5" , "test6" , "test7" , "test8" , "test9" , "test10" ] ;
17
+
18
+ const testNames = new Array < string > ( ) ;
19
+ for ( let i = 1 ; i <= 10 ; i ++ ) {
20
+ testNames . push ( `test${ i } ` ) ;
21
+ }
17
22
queuedNames = testNames ;
18
23
await docRef . update ( { queuedNames } ) ;
19
24
io . emit ( "refresh-lists" , queuedNames , poppedNames , nameGraveyard ) ;
@@ -84,13 +89,9 @@ export async function popName(random: boolean) {
84
89
poppedNames . unshift ( name ) ;
85
90
} else {
86
91
let idx : number = - 1 ;
87
- // if (queuedNames.includes("eyemozzie")) {
88
- // name = "eyemozzie";
89
- // idx = queuedNames.findIndex((s) => s === name);
90
- // } else {
91
- idx = Math . floor ( Math . random ( ) * queuedNames . length ) ;
92
+ // idx = Math.floor(Math.random() * queuedNames.length);
93
+ idx = getWeightedRandomIndex ( queuedNames ) ;
92
94
name = queuedNames [ idx ] ;
93
- // }
94
95
queuedNames . splice ( idx , 1 ) ;
95
96
poppedNames . unshift ( name ) ;
96
97
}
0 commit comments