1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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("%f", "work time", work_time);
REPORT("%f", "avg keys/sec", keypresses.length / work_time);
REPORT("%f", "idle time", idle_time);
fflush(report_fp);
}
|