ladders.js
/**
	 * Internal function, returns a Promise for a ladder
	 */
Internal function, returns a Promise for a ladder
Internal function returns a Promise for a ladder
load() {
		if (this.formatid in ladderCaches) {
			let cachedLadder = ladderCaches[this.formatid];
			if (cachedLadder.then) {
				return cachedLadder.then(ladder => {
					this.loadedLadder = ladder;
					return ladder;
				});
			} else {
				return Promise.resolve(this.loadedLadder = cachedLadder);
			}
		}
		return (ladderCaches[this.formatid] = new Promise((resolve, reject) => {
			fs.readFile('config/ladders/' + this.formatid + '.tsv', (err, data) => {
				if (err) {
					this.loadedLadder = ladderCaches[this.formatid] = [];
					resolve(this.loadedLadder);
					return;
				}
				let ladder = [];
				let dataLines = ('' + data).split('\n');
				for (let i = 1; i < dataLines.length; i++) {
					let line = dataLines[i].trim();
					if (!line) continue;
					let row = line.split('\t');
					ladder.push([toId(row[1]), Number(row[0]), row[1], Number(row[2]), Number(row[3]), Number(row[4]), row[5]]);
				}
				this.loadedLadder = ladderCaches[this.formatid] = ladder;
				resolve(this.loadedLadder);
			});
		}));
	}
load ( ) { if ( this . formatid in ladderCaches ) { let cachedLadder = ladderCaches [ this . formatid ] ; if ( cachedLadder . then ) { return cachedLadder . then ( ladder => { this . loadedLadder = ladder ; return ladder ; } ) ; } else { return Promise . resolve ( this . loadedLadder = cachedLadder ) ; } } return ( ladderCaches [ this . formatid ] = new Promise ( ( resolve , reject ) => { fs . readFile ( 'config/ladders/' + this . formatid + '.tsv' , ( err , data ) => { if ( err ) { this . loadedLadder = ladderCaches [ this . formatid ] = [ ] ; resolve ( this . loadedLadder ) ; return ; } let ladder = [ ] ; let dataLines = ( '' + data ) . split ( '\n' ) ; for ( let i = 1 ; i < dataLines . length ; i ++ ) { let line = dataLines [ i ] . trim ( ) ; if ( ! line ) continue ; let row = line . split ( '\t' ) ; ladder . push ( [ toId ( row [ 1 ] ) , Number ( row [ 0 ] ) , row [ 1 ] , Number ( row [ 2 ] ) , Number ( row [ 3 ] ) , Number ( row [ 4 ] ) , row [ 5 ] ] ) ; } this . loadedLadder = ladderCaches [ this . formatid ] = ladder ; resolve ( this . loadedLadder ) ; } ) ; } ) ) ; }
Internal function, returns a Promise for a ladder
Internal function returns a Promise for a ladder
// ladderCaches[formatid] // console.log('Ladders(' + this.formatid + ') err loading tsv: ' + JSON.stringify(this.loadedLadder)); // console.log('Ladders(' + this.formatid + ') loaded tsv: ' + JSON.stringify(this.loadedLadder));