--- /dev/null
+#!/usr/bin/awk -f
+
+#
+# find timespan of inactivity
+#
+# provide evolution of speed in a column at standard input
+#
+# start point is when speed is lower with MAX_SPEED/RATE than maximum speed
+# that far; stop point is when download speed is higher with MAX_SPEED/RATE
+# than minimium speed that far
+#
+
+BEGIN {
+ MAX_SPEED = 100.0;
+ RATE = 0.15;
+ THRESHOLD = MAX_SPEED * RATE;
+ STATE_NO_STATE = 0;
+ STATE_GET_INACTIVITY = 1;
+ STATE_GET_ACTIVITY = 2;
+
+ state = STATE_GET_INACTIVITY;
+ max_speed_so_far = 0;
+ min_speed_so_far = MAX_SPEED;
+ counter = 0;
+ start_time = 0;
+ stop_time = 0;
+}
+
+{
+ curr_speed = $1;
+ if (state == STATE_GET_INACTIVITY) {
+ if (curr_speed > max_speed_so_far)
+ max_speed_so_far = curr_speed;
+ else if (curr_speed < max_speed_so_far - THRESHOLD) {
+ start = counter;
+ state = STATE_GET_ACTIVITY;
+ }
+ }
+ else if (state == STATE_GET_ACTIVITY) {
+ if (curr_speed < min_speed_so_far)
+ min_speed_so_far = curr_speed;
+ else if (curr_speed > min_speed_so_far + THRESHOLD) {
+ stop = counter;
+ state = STATE_NOSTATE;
+ }
+ }
+ counter++;
+}
+
+END {
+ printf "start: %d, stop: %d, diff: %d\n", start, stop, stop - start;
+}