import { objectLoop, objectMap } from '@dzeio/object-util' import { SupportedLanguages } from '@tcgdex/sdk' import express from 'express' import Serie from './V2/Components/Serie' import Set from './V2/Components/Set' const enStats = require('../generated/en/stats.json') const frStats = require('../generated/fr/stats.json') const deStats = require('../generated/de/stats.json') const esStats = require('../generated/es/stats.json') const itStats = require('../generated/it/stats.json') const ptStats = require('../generated/pt/stats.json') /** * This file is meant to contains the TCGdex Project status page. * */ /** * Simple calculation of maximum and current count globally */ const totalStats = { count: enStats.count + frStats.count + deStats.count + itStats.count + ptStats.count + esStats.count, total: enStats.total + frStats.total + deStats.total + itStats.total + ptStats.total + esStats.total, images: enStats.images + frStats.images + deStats.images + itStats.images + ptStats.images + esStats.images, } /** * Array containing data for sets, it also allow to display non english available sets * Serie * Set * Array of langs */ const setsData: Record>> = {} function preProcessSets(t: any, lang: SupportedLanguages) { objectLoop(t.sets, (sets, serieId) => { if (!(serieId in setsData)) { setsData[serieId] = {} } objectLoop(sets, (_, set) => { if (!(set in setsData[serieId])) { setsData[serieId][set] = [] } setsData[serieId][set].push(lang) }) }) } preProcessSets(enStats, 'en') preProcessSets(frStats, 'fr') preProcessSets(esStats, 'es') preProcessSets(itStats, 'it') preProcessSets(ptStats, 'pt') preProcessSets(deStats, 'de') // Yes this is ugly export default express.Router() .get('/github.svg', (_, res): void => { res.setHeader('Content-Type', 'image/svg+xml') res.send(` English French German Italian Portuguese Spanish Total Card Progress ${enStats.count} of ${enStats.total} ${(100 * enStats.count / enStats.total).toFixed(2)}% ${frStats.count} of ${frStats.total} ${(100 * frStats.count / frStats.total).toFixed(2)}% ${deStats.count} of ${deStats.total} ${(100 * deStats.count / deStats.total).toFixed(2)}% ${itStats.count} of ${itStats.total} ${(100 * itStats.count / itStats.total).toFixed(2)}% ${ptStats.count} of ${ptStats.total} ${(100 * ptStats.count / ptStats.total).toFixed(2)}% ${esStats.count} of ${esStats.total} ${(100 * esStats.count / esStats.total).toFixed(2)}% ${totalStats.count} of ${totalStats.total} ${(100 * totalStats.count / totalStats.total).toFixed(2)}% Images Progress ${enStats.images} of ${enStats.total} ${(100 * enStats.images / enStats.total).toFixed(2)}% ${frStats.images} of ${frStats.total} ${(100 * frStats.images / frStats.total).toFixed(2)}% ${deStats.images} of ${deStats.total} ${(100 * deStats.images / deStats.total).toFixed(2)}% ${itStats.images} of ${itStats.total} ${(100 * itStats.images / itStats.total).toFixed(2)}% ${ptStats.images} of ${ptStats.total} ${(100 * ptStats.images / ptStats.total).toFixed(2)}% ${esStats.images} of ${esStats.total} ${(100 * esStats.images / esStats.total).toFixed(2)}% ${totalStats.images} of ${totalStats.total} ${(100 * totalStats.images / totalStats.total).toFixed(2)}% Total Progress ${enStats.images + enStats.count} of ${enStats.total * 2} ${(100 * (enStats.images + enStats.count) / (enStats.total * 2)).toFixed(2)}% ${frStats.images + frStats.count} of ${frStats.total * 2} ${(100 * (frStats.images + frStats.count) / (frStats.total * 2)).toFixed(2)}% ${deStats.images + deStats.count} of ${deStats.total * 2} ${(100 * (deStats.images + deStats.count) / (deStats.total * 2)).toFixed(2)}% ${itStats.images + itStats.count} of ${itStats.total * 2} ${(100 * (itStats.images + itStats.count) / (itStats.total * 2)).toFixed(2)}% ${ptStats.images + ptStats.count} of ${ptStats.total * 2} ${(100 * (ptStats.images + ptStats.count) / (ptStats.total * 2)).toFixed(2)}% ${esStats.images + esStats.count} of ${esStats.total * 2} ${(100 * (esStats.images + esStats.count) / (esStats.total * 2)).toFixed(2)}% ${totalStats.images + totalStats.count} of ${totalStats.total * 2} ${(100 * (totalStats.images + totalStats.count) / (totalStats.total * 2)).toFixed(2)}% `) }) .get('/', (_, res): void => { res.send(`

TCGdex Progress

English French German Italian Portuguese Spanish Total
Card Progress
Cards ${enStats.count} of ${enStats.total} ${frStats.count} of ${frStats.total} ${deStats.count} of ${deStats.total} ${itStats.count} of ${itStats.total} ${ptStats.count} of ${ptStats.total} ${esStats.count} of ${esStats.total} ${totalStats.count} of ${totalStats.total}
Percentage ${(100 * enStats.count / enStats.total).toFixed(2)}% ${(100 * frStats.count / frStats.total).toFixed(2)}% ${(100 * deStats.count / deStats.total).toFixed(2)}% ${(100 * itStats.count / itStats.total).toFixed(2)}% ${(100 * ptStats.count / ptStats.total).toFixed(2)}% ${(100 * esStats.count / esStats.total).toFixed(2)}% ${(100 * totalStats.count / totalStats.total).toFixed(2)}%
Remaining ${enStats.total - enStats.count} ${frStats.total - frStats.count} ${deStats.total - deStats.count} ${itStats.total - itStats.count} ${ptStats.total - ptStats.count} ${esStats.total - esStats.count} ${totalStats.total - totalStats.count}
Images Progress
Cards ${enStats.images} of ${enStats.total} ${frStats.images} of ${frStats.total} ${deStats.images} of ${deStats.total} ${itStats.images} of ${itStats.total} ${ptStats.images} of ${ptStats.total} ${esStats.images} of ${esStats.total} ${totalStats.images} of ${totalStats.total}
Percentage ${(100 * enStats.images / enStats.total).toFixed(2)}% ${(100 * frStats.images / frStats.total).toFixed(2)}% ${(100 * deStats.images / deStats.total).toFixed(2)}% ${(100 * itStats.images / itStats.total).toFixed(2)}% ${(100 * ptStats.images / ptStats.total).toFixed(2)}% ${(100 * esStats.images / esStats.total).toFixed(2)}% ${(100 * totalStats.images / totalStats.total).toFixed(2)}%
Remaining ${enStats.total - enStats.images} ${frStats.total - frStats.images} ${deStats.total - deStats.images} ${itStats.total - itStats.images} ${ptStats.total - ptStats.images} ${esStats.total - esStats.images} ${totalStats.total - totalStats.images}
Total Progress
Cards ${enStats.images + enStats.count} of ${enStats.total * 2} ${frStats.images + frStats.count} of ${frStats.total * 2} ${deStats.images + deStats.count} of ${deStats.total * 2} ${itStats.images + itStats.count} of ${itStats.total * 2} ${ptStats.images + ptStats.count} of ${ptStats.total * 2} ${esStats.images + esStats.count} of ${esStats.total * 2} ${totalStats.images + totalStats.count} of ${totalStats.total * 2}
Percentage ${(100 * (enStats.images + enStats.count) / (enStats.total * 2)).toFixed(2)}% ${(100 * (frStats.images + frStats.count) / (frStats.total * 2)).toFixed(2)}% ${(100 * (deStats.images + deStats.count) / (deStats.total * 2)).toFixed(2)}% ${(100 * (itStats.images + itStats.count) / (itStats.total * 2)).toFixed(2)}% ${(100 * (ptStats.images + ptStats.count) / (ptStats.total * 2)).toFixed(2)}% ${(100 * (esStats.images + esStats.count) / (esStats.total * 2)).toFixed(2)}% ${(100 * (totalStats.images + totalStats.count) / (totalStats.total * 2)).toFixed(2)}%
Remaining ${enStats.total * 2 - (enStats.images + enStats.count)} ${frStats.total * 2 - (frStats.images + frStats.count)} ${deStats.total * 2 - (deStats.images + deStats.count)} ${itStats.total * 2 - (itStats.images + itStats.count)} ${ptStats.total * 2 - (ptStats.images + ptStats.count)} ${esStats.total * 2 - (esStats.images + esStats.count)} ${totalStats.total * 2 - (totalStats.images + totalStats.count)}

Status

${objectMap(setsData, (serie, serieId) => { // Loop through every series and name them const name = Serie.findOne('en', {id: serieId})?.name return ` ${objectMap(serie, (data, setId) => { // loop through every sets // find the set in the first available language (Should be English globally) const setTotal = Set.findOne(data[0] as 'en', {id: setId}) let str = '' + `` // Loop through every languages const l = ['en', 'fr', 'de', 'it', 'pt', 'es'] l.map((it) => { // Change the stats file depending on the language let stats: any = enStats switch (it) { case 'fr': stats = frStats; break case 'de': stats = deStats; break case 'it': stats = itStats; break case 'pt': stats = ptStats; break case 'es': stats = esStats; break } // Get the stats we want const item = stats.sets[serieId]?.[setId] as {count: number, images: number} | undefined // if item dont exist for the language skip it if (!item) { str += ` ` return } // Calculate percentages and status const percent = 100 * item.count / (setTotal?.cardCount.total ?? 1) const imgPercent = 100 * item.images / (setTotal?.cardCount.total ?? 1) // append to string :D str +=`` }) // finish Row return str + '' }).join('')} `}).join('')}

${name} (${serieId})

Set Name English French German Italian Portuguese Spanish
Cards Images Cards Images Cards Images Cards Images Cards Images Cards Images
${setTotal?.name} (${setId})
${setTotal?.cardCount.total ?? 1} cards
${percent.toFixed(2)}%
(${item.count})
${imgPercent.toFixed(2)}%
(${item.images})
`) })