From 927d52f5884d900e5514c28ffe3eca9e48303adb Mon Sep 17 00:00:00 2001
From: retoor <retoor@molodetz.nl>
Date: Mon, 17 Mar 2025 04:58:10 +0100
Subject: [PATCH] Removed bugs.

---
 .gitignore |  7 +++++--
 Makefile   |  3 +++
 merge.py   |  9 +++++++++
 sormc.h    | 12 ++++++++++--
 tags.py    | 15 +++++++++++----
 5 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore
index 7c4d409..ee58b2d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,10 @@
 *.db*
-
+*.png
+.*
 .venv
-
+contrib
+logs_*
+*.txt
 # ---> C++
 # Prerequisites
 *.d
diff --git a/Makefile b/Makefile
index 5899eb8..980c8cf 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ PYTHON="./.venv/bin/python"
 
 ensure_env:
 	-@python3 -m venv .venv
+	$(PYTHON) -m pip install dataset
 
 merge:
 	$(PYTHON) merge.py
@@ -32,3 +33,5 @@ index:
 popular:
 	$(PYTHON) tags.py --popular
 
+process:
+	PYTHONPATH=/home/retoor/bin $(PYTHON) process.py
diff --git a/merge.py b/merge.py
index 6577b27..9b83fab 100644
--- a/merge.py
+++ b/merge.py
@@ -12,6 +12,15 @@ for file in pathlib.Path("logs_plain").glob("*.txt"):
 
 lines_per_hour = return_count // hour_count
 
+
+for file in pathlib.Path("logs_plain").glob("*.txt"):
+    with open(file, "r") as f:
+        all_content.append(f.read())
+
+with open("logs_plain/merged.txt", "w") as f:
+    f.write("\n\n".join(all_content))
+
+
 for file in pathlib.Path("logs_summaries").glob("*.txt"):
     with open(file, "r") as f:
         all_content.append(f.read())
diff --git a/sormc.h b/sormc.h
index d7c14d4..be76dbc 100644
--- a/sormc.h
+++ b/sormc.h
@@ -8663,14 +8663,22 @@ unsigned int sormcq(char *sql, char *out) {
     // converts %s %i parameters to ?
 
     unsigned int count = 0;
+    char prev = 0;
     while (*sql) {
-        if (*sql != '%' && *sql != '?')
+        if ((*sql != '%') && (*sql != '?'))
             *out = *sql;
         else {
-            count++;
+            
             sql++;
+            if(*sql == '%'){
+                *out = '%';
+                //sql++;
+            }else{
+            count++;
             *out = '?';
+            }
         }
+        prev = *sql;
         out++;
         sql++;
     }
diff --git a/tags.py b/tags.py
index 8c54350..1f9cb79 100644
--- a/tags.py
+++ b/tags.py
@@ -134,7 +134,8 @@ class WordDb:
 
     def most_popular(self, count):
         self.cursor.execute("SELECT word, count FROM words ORDER BY count DESC LIMIT ?", (count,))
-        return list(self.cursor.fetchall())
+        for (x,record) in enumerate(self.cursor.fetchall()):
+            yield x,record 
 
     def __del__(self):
         self.commit()
@@ -158,9 +159,15 @@ if args.find:
     print(db.get(args.find))
 
 if args.popular:
-    for item in db.most_popular(300):
-        print(item)
-    print(db.total_count())
+    total_count =  db.total_count()
+    all_ = list(db.most_popular(300))
+    longest_word = max([len(record[0]) for (x, record) in all_])
+    longest_number = 5
+    for (x, record) in all_:
+        percentage = record[1] / total_count 
+        print(str("#" + str(x)).ljust(longest_number), str(record[0]).ljust(longest_word), str("is pressed " + str(record[1]) + " times").rjust(20), str("("+str(round(percentage * 100, 2)) + "% of total input)").ljust(20))
+        #print(f"#{x}\t`{record[0]}` is {record[1]} times pressed.")
+    print("Unique words:", db.total_count())
 
 if args.index:
     db.reset()