// What the working line says while a company is read into the store: a sentence for the stage the // work is at, with the count, rather than the count alone. Pure, so it is tested. const n = (value: number): string => value.toLocaleString('en-US') /** How far along, 0 to 10, from what is done against the whole; 0 when the whole is not known yet. */ function stage(done: number, total: number): number { if (total <= 0) return 0 return Math.min(10, Math.floor((done / total) * 10)) } /** The filings read so far: SEC is asked for each, it is cut by its items, and put in the store. */ export function readingLine(ticker: string, done: number, total: number): string { const count = `${n(done)} of ${n(total)}` switch (stage(done, total)) { case 0: return `Knocking on SEC's door for ${ticker}: ${count} filings read` case 1: return `${ticker}'s first filings coming in, cut by their items: ${count}` case 2: return `Working through ${ticker}'s reports, one item at a time: ${count}` case 3: return `A third of ${ticker}'s filings are in: ${count}` case 4: return `${ticker}'s years going in, risk factors and all: ${count}` case 5: return `Halfway through ${ticker}'s filings: ${count}` case 6: return `Past the middle of ${ticker}'s filings: ${count}` case 7: return `${ticker}'s later years landing: ${count}` case 8: return `Nearly every ${ticker} filing is in: ${count}` case 9: return `The last of ${ticker}'s filings: ${count}` default: return `Every ${ticker} filing is read: ${count}` } } /** The passages still waiting for their embedding, out of the company's whole, which the queue works through newest first. */ export function embeddingLine(ticker: string, left: number, total: number): string { const togo = `${n(left)} to go` switch (stage(total - left, total)) { case 0: return `Giving ${ticker}'s ${total > 0 ? n(total) + ' ' : ''}passages their meaning, newest first: ${togo}` case 1: return `${ticker}'s latest filings learning what they are about: ${togo}` case 2: return `Teaching the model ${ticker}'s recent years: ${togo}` case 3: return `A third of ${ticker}'s passages searchable by meaning: ${togo}` case 4: return `${ticker}'s middle years going in: ${togo}` case 5: return `Halfway through ${ticker}'s passages: ${togo}` case 6: return `${ticker}'s older filings taking their turn: ${togo}` case 7: return `Three quarters of ${ticker} is searchable by meaning: ${togo}` case 8: return `Down to ${ticker}'s last stretch: ${togo}` case 9: return `The last few ${ticker} passages: ${togo}` default: return `Every ${ticker} passage is in: ${togo}` } }