From 6f2cd6be1d44fb13d75f66418c9a27b01b77a53d Mon Sep 17 00:00:00 2001 From: spv Date: Mon, 17 Nov 2025 16:47:32 -0500 Subject: add WIP report gen, systemd user service, work time tracker, sig handling --- src/report.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/report.c (limited to 'src/report.c') diff --git a/src/report.c b/src/report.c new file mode 100644 index 0000000..060e98a --- /dev/null +++ b/src/report.c @@ -0,0 +1,48 @@ +// report generator + +#include + +#include "common.h" + +extern keypresses_t keypresses; + +static double work_time; +static double idle_time; + +#define REPORT(t, s, v...) do { \ + fprintf(report_fp, "%s: " t "\n", s, v); \ +} while (0) + +void gen_report(FILE* report_fp) { + LOG(LOG_DEBUG, "total keypresses: %d\n", keypresses.length); + + rewind(report_fp); + + work_time = 0; + idle_time = 0; + + if (keypresses.length > 2) { + double last_press = keypresses.keys[0].when; + + for (int i = 1; i < keypresses.length; i++) { + keypress_t* press = &keypresses.keys[i]; + + if (press->when < last_press + IDLE_TIME) { + work_time += press->when - last_press; + } else { + idle_time += press->when - last_press - IDLE_TIME; + } + + last_press = press->when; + + LOG(LOG_INSANEDEBUG, "%d %d %d\n", keypresses.keys[i].when, keypresses.length); + } + } + + 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); + + fflush(report_fp); +} -- cgit v1.2.3