aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorspv <spv@spv.sh>2025-11-18 10:29:15 -0500
committerspv <spv@spv.sh>2025-11-18 10:29:15 -0500
commitdf46e8485d65cc9dae9b959e828eec1eed36838e (patch)
treeb2a1816784a55dc46b6133af544b0c0bd357e534 /src
parent89928b63f48116604bddf10763123ee979f038cc (diff)
change reporting logic, 1 per hour. add skeleton of report processing code.
Diffstat (limited to 'src')
-rw-r--r--src/config.h2
-rw-r--r--src/main.c31
-rwxr-xr-xsrc/process.py15
-rw-r--r--src/report.c8
4 files changed, 50 insertions, 6 deletions
diff --git a/src/config.h b/src/config.h
index 0635948..908a95b 100644
--- a/src/config.h
+++ b/src/config.h
@@ -6,7 +6,7 @@
#define LOG_FP stderr
#define LOG_LEVEL LOG_INFO
-#define REPORT_PATH "/home/spv/.local/stroke_buddy/%d.log"
+#define REPORT_PATH "/home/spv/.local/stroke_buddy/%d-%d-%d@%d.log"
#define IDLE_TIME 30
diff --git a/src/main.c b/src/main.c
index a9f14f5..dab70af 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5,6 +5,9 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <unistd.h>
+
+#include <time.h>
#include "common.h"
@@ -23,7 +26,31 @@ void handler(int _) {
exit(0);
}
+void wait_thread(pid_t keypress_pid) {
+ time_t start_time = time(NULL);
+ struct tm* start_tm = localtime(&start_time);
+ int start_hour = start_tm->tm_hour;
+
+ while (1) {
+ time_t now = time(NULL);
+ struct tm* now_tm = localtime(&now);
+
+ if (now_tm->tm_hour != start_hour) {
+ kill(keypress_pid, SIGQUIT);
+
+ exit(0);
+ }
+
+ sleep(1);
+ }
+}
+
int main(int argc, char* argv[]) {
+ pid_t keypress_pid = getpid();
+ pid_t wait_pid = fork();
+
+ if (wait_pid == 0) wait_thread(keypress_pid);
+
evdev_fp = fopen(KEYBOARD_EVDEV, "r");
report_fp = NULL;
@@ -39,7 +66,9 @@ int main(int argc, char* argv[]) {
gettimeofday(&start_time, NULL);
- asprintf(&report_path, REPORT_PATH, start_time.tv_sec);
+ struct tm* start_tm = localtime(&start_time.tv_sec);
+
+ asprintf(&report_path, REPORT_PATH, start_tm->tm_year + 1900, start_tm->tm_mon + 1, start_tm->tm_mday, start_tm->tm_hour);
report_fp = fopen(report_path, "w");
diff --git a/src/process.py b/src/process.py
new file mode 100755
index 0000000..0b645b8
--- /dev/null
+++ b/src/process.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+
+import sys, os
+
+def main(argv):
+ homedir = os.getenv("HOME")
+ stroke_buddydir = homedir + "/.local/stroke_buddy"
+ log_files = os.listdir(stroke_buddydir)
+
+ print(log_files)
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
diff --git a/src/report.c b/src/report.c
index 060e98a..ea238a9 100644
--- a/src/report.c
+++ b/src/report.c
@@ -10,7 +10,7 @@ static double work_time;
static double idle_time;
#define REPORT(t, s, v...) do { \
- fprintf(report_fp, "%s: " t "\n", s, v); \
+ fprintf(report_fp, "%s," t "\n", s, v); \
} while (0)
void gen_report(FILE* report_fp) {
@@ -40,9 +40,9 @@ void gen_report(FILE* report_fp) {
}
REPORT("%d", "total keypresses", keypresses.length);
- REPORT("%.1fs", "work time", work_time);
- REPORT("%.1f k/s", "avg keys/sec", keypresses.length / work_time);
- REPORT("%.1fs", "idle time", idle_time);
+ REPORT("%f", "work time", work_time);
+ REPORT("%f", "avg keys/sec", keypresses.length / work_time);
+ REPORT("%f", "idle time", idle_time);
fflush(report_fp);
}