From a3bada0da294aaeaa2bbbdbf04e1d30d4b3a524d Mon Sep 17 00:00:00 2001 From: pinks Date: Fri, 27 Oct 2023 21:49:46 +0200 Subject: [PATCH 1/3] sort most used tags --- app/userStatsStore.ts | 17 +++++++++++++---- deno.lock | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/userStatsStore.ts b/app/userStatsStore.ts index e842a8b..e3b9aa8 100644 --- a/app/userStatsStore.ts +++ b/app/userStatsStore.ts @@ -5,6 +5,7 @@ import { JsonSchema, jsonType } from "t_rest/server"; import { db } from "./db.ts"; import { generationStore } from "./generationStore.ts"; import { kvMemoize } from "./kvMemoize.ts"; +import { sortBy } from "std/collections/sort_by.ts"; export const userStatsSchema = { type: "object", @@ -59,7 +60,7 @@ export const getUserStats = kvMemoize( let stepCount = 0; let pixelCount = 0; let pixelStepCount = 0; - const tagCountMap: Record = {}; + const tagCountMap = new Map(); info(`Calculating user stats for ${userId}`); @@ -77,7 +78,7 @@ export const getUserStats = kvMemoize( // split on punctuation and newlines .split(/[,;.]\s+|\n/) // remove `:weight` syntax - .map((tag) => tag.replace(/:[\d\.]+/g, " ")) + .map((tag) => tag.replace(/:[\d\.]+/g, "")) // remove `(tag)` and `[tag]` syntax .map((tag) => tag.replace(/[()[\]]/g, " ")) // collapse multiple whitespace to one @@ -92,17 +93,25 @@ export const getUserStats = kvMemoize( []; for (const tag of tags) { - tagCountMap[tag] = (tagCountMap[tag] ?? 0) + 1; + const count = tagCountMap.get(tag) ?? 0; + tagCountMap.set(tag, count + 1); } } + const tagCountObj = Object.fromEntries( + sortBy( + Array.from(tagCountMap.entries()), + ([_tag, count]) => -count, + ).filter(([_tag, count]) => count >= 3), + ); + return { userId, imageCount, stepCount, pixelCount, pixelStepCount, - tagCountMap, + tagCountMap: tagCountObj, timestamp: Date.now(), }; }, diff --git a/deno.lock b/deno.lock index b82efc4..ab58e99 100644 --- a/deno.lock +++ b/deno.lock @@ -106,6 +106,7 @@ "https://deno.land/std@0.202.0/collections/deep_merge.ts": "9db788ba56cb05b65c77166b789e58e125dff159b7f41bf4d19dc1cba19ecb8b", "https://deno.land/std@0.202.0/collections/distinct_by.ts": "3afe11d81eafb30c7c9dbf568d94357f3d88153292c00671b72cd695deae6602", "https://deno.land/std@0.202.0/collections/max_by.ts": "9d5940986aac51b2e4feaebef9cd8bf6e1eceeee5edcf3303e334b737f99520d", + "https://deno.land/std@0.202.0/collections/sort_by.ts": "1207755af756a5da04bebff39146c93cbe54f7870a5d67cf6922e871d96a01d5", "https://deno.land/std@0.202.0/encoding/base64.ts": "144ae6234c1fbe5b68666c711dc15b1e9ee2aef6d42b3b4345bf9a6c91d70d0d", "https://deno.land/std@0.202.0/flags/mod.ts": "0948466fc437f017f00c0b972a422b3dc3317a790bcf326429d23182977eaf9f", "https://deno.land/std@0.202.0/fmt/bytes.ts": "f29cf69e0791d375f9f5d94ae1f0641e5a03b975f32ddf86d70f70fdf37e7b6a", -- 2.43.4 From 6d6174ab483e427267072353610ecf5f9c53aa3f Mon Sep 17 00:00:00 2001 From: pinks Date: Fri, 27 Oct 2023 21:50:20 +0200 Subject: [PATCH 2/3] silence getUpdates error --- bot/mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/mod.ts b/bot/mod.ts index b947640..ad3b35b 100644 --- a/bot/mod.ts +++ b/bot/mod.ts @@ -174,6 +174,6 @@ bot.command("crash", () => { }); export async function runBot() { - const runner = run(bot); + const runner = run(bot, { runner: { silent: true } }); await runner.task(); } -- 2.43.4 From f678324889359fe0443fbf45476c02453d571cad Mon Sep 17 00:00:00 2001 From: pinks Date: Mon, 6 Nov 2023 18:38:41 +0100 Subject: [PATCH 3/3] add badges to readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index ba3c1ae..96e5ef4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Eris the Bot +[![Website](https://img.shields.io/website?url=https%3A%2F%2Feris.lisq.eu%2F)](https://eris.lisq.eu/) +![Unique users](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Feris.lisq.eu%2Fapi%2Fstats&query=%24.userCount&label=unique%20users) +![Generated images](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Feris.lisq.eu%2Fapi%2Fstats&query=%24.imageCount&label=images%20generated) +![Processed steps](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Feris.lisq.eu%2Fapi%2Fstats&query=%24.stepCount&label=steps%20processed) +![Painted pixels](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Feris.lisq.eu%2Fapi%2Fstats&query=%24.pixelCount&label=pixels%20painted) + Telegram bot for generating images from text. ## Requirements -- 2.43.4