aboutsummaryrefslogtreecommitdiff
path: root/src/report.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/report.c')
-rw-r--r--src/report.c48
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);
+}