-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactive-summarize.awk
More file actions
100 lines (98 loc) · 3.26 KB
/
Copy pathactive-summarize.awk
File metadata and controls
100 lines (98 loc) · 3.26 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function get_duration(start_minutes, end_minutes) {
start_hour = start_minutes / 60;
end_hour = end_minutes / 60;
printf "start_hour: %s: end_hour: %s\n", start_hour, end_hour
if (start_hour < 11 && end_hour > 13.5 && end_hour - start_hour > 5) {
print "_\nLunch break";
return end_minutes - start_minutes - 30;
} else {
return end_minutes - start_minutes;
}
}
function print_duration(date, duration) {
printf "%s %02.2d:%02.2d %.2f\n", date, int(duration/60), duration%60, duration/60
}
BEGIN {
if (pattern == "") {
pattern = "work";
}
print "Pattern: " pattern;
FS = "|";
previous_week = "";
previous_date = "";
previous_minutes = "";
other_minutes = "";
start = -1;
day_total = 0.0;
week_total = 0.0;
}
$0 !~ pattern {
if ($1 == previous_date && other_minutes == "") {
other_minutes = $2 * 60 + $3;
# print ">> " $0 " [" other_minutes "]";
}
next;
}
$1 != previous_date {
if (previous_date != "") {
if (other_minutes != "" && other_minutes < previous_minutes + 30) {
# printf "Midpoint: %.2f -- %.2f\n", previous_minutes, other_minutes;
duration = get_duration(start, (previous_minutes + other_minutes) / 2);
} else {
duration = get_duration(start, previous_minutes + 15);
}
print_duration(previous_date, duration);
day_total += duration/60;
week_total += day_total;
printf "%s total %.2f\n", previous_date, day_total
if (previous_week != "" && $4 != previous_week) {
# printf "Week %d: %.2f\n", previous_week, week_total;
week_total = 0.0;
}
previous_week = $4;
}
previous_date = $1;
start = -1;
day_total = 0.0;
other_minutes = "";
# print "New date " $1;
}
{
minutes = $2 * 60 + $3;
# print "> " $0 " [" previous_minutes "/" other_minutes "/" minutes "]";
if (start < 0) {
start = minutes
} else if (other_minutes != "" && other_minutes < previous_minutes + 30) {
# printf "Midpoint: %.2f -- %.2f\n", previous_minutes, other_minutes;
duration = get_duration(start, (previous_minutes + other_minutes) / 2);
print_duration(previous_date, duration);
day_total += duration/60;
start = minutes
} else if (previous_minutes + 17 < minutes) {
duration = get_duration(start, previous_minutes + 15);
print_duration(previous_date, duration);
day_total += duration/60;
start = minutes
}
previous_minutes = minutes;
other_date = "";
other_minutes = ""
}
END {
if (start >= 0) {
if (other_minutes != "" && other_minutes < previous_minutes + 30) {
# printf "Midpoint: %.2f -- %.2f\n", previous_minutes, other_minutes;
duration = get_duration(start, (previous_minutes + other_minutes) / 2);
} else {
duration = get_duration(start, previous_minutes + 15);
}
print_duration(previous_date, duration);
day_total += duration/60;
week_total += day_total;
printf "%s total %.2f\n", previous_date, day_total
if (previous_week != "") {
printf "Week %d: %.2f\n", previous_week, week_total;
week_total = 0.0;
}
}
}