diff --git a/src/WebSocketHandler.ts b/src/WebSocketHandler.ts index 7b9de18..892268d 100644 --- a/src/WebSocketHandler.ts +++ b/src/WebSocketHandler.ts @@ -5,7 +5,6 @@ import {Settings} from "./Settings"; import Container from "./database/Container"; import Job from "./database/Job"; import Drink from "./database/Drink"; -import {IDrink} from "./database/IDrink"; import Ingredient from "./database/Ingredient"; import {RequestType} from "./RequestType"; import debug from "debug"; @@ -61,26 +60,31 @@ export class WebSocketHandler { static sendStats() { return new Promise(async resolve => { - let counts: IDrink[] = []; + + let counts: any[] = []; for (let drink of (await Drink.find())) { // @ts-ignore - drink.count = (await Job.countDocuments({drink: drink})); - counts.push(drink) + let count = await Job.countDocuments({drink: drink._id}); + counts.push([drink, count]); } - counts.sort((a: IDrink, b: IDrink) => { + + + counts.sort((a, b) => { // @ts-ignore - if (a.count < b.count) + if (a[1] < b[1]) return -1; // @ts-ignore - else if (a.count > b.count) + else if (a[1] > b[1]) return 1; else return 0; }); + + console.debug(counts); let stats = { "drinks_finished": (await Job.countDocuments({successful: true})), - "drink_most": (counts.length == 0) ? "Keiner" : counts[0].name, + "drink_most": (counts.length == 0) ? "Keiner" : counts[0][0].name, "count_ingredients": (await Ingredient.countDocuments()), "count_cocktails": (await Drink.countDocuments()) }; diff --git a/src/web/Fill.ts b/src/web/Fill.ts index d054d16..81de201 100644 --- a/src/web/Fill.ts +++ b/src/web/Fill.ts @@ -77,7 +77,7 @@ export class Fill { let interval = setInterval(() => { minus++; if (minus + 1 > (job.estimatedTime as number)) { - clearInterval(interval); + setTimeout( () => clearInterval(interval), 1500 ); } seconds.innerText = (Math.floor(job.estimatedTime as number - minus)) + "s";