diff options
| author | spv <spv@spv.sh> | 2025-11-17 16:47:32 -0500 |
|---|---|---|
| committer | spv <spv@spv.sh> | 2025-11-17 16:47:32 -0500 |
| commit | 6f2cd6be1d44fb13d75f66418c9a27b01b77a53d (patch) | |
| tree | 7ba44fa400145e77ef487b9fd1de36d692e7cd9f /src/report.c | |
| parent | 6f010046f0f17a5684a0f30423e2b3c6a41099d1 (diff) | |
add WIP report gen, systemd user service, work time tracker, sig handling
Diffstat (limited to 'src/report.c')
| -rw-r--r-- | src/report.c | 48 |
1 files changed, 48 insertions, 0 deletions
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 <stdio.h> + +#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); +} |
