Correctly disregard all but the first station visited after allowed_time is up.
authorCMDR furrycat <elite@furrycat.net>
Wed, 27 Jan 2016 11:15:34 +0000 (06:15 -0500)
committerCMDR furrycat <elite@furrycat.net>
Wed, 27 Jan 2016 13:15:57 +0000 (08:15 -0500)
entry.js

index ae51f57..4247970 100644 (file)
--- a/entry.js
+++ b/entry.js
@@ -458,6 +458,47 @@ function do_stats(table) {
       break;
     }
   }
+
+  /* Times. */
+  var start_time = from_iso8601(real_date(get_cell_input(first_row(table), first_column(table)).value));
+  var finish_time = from_iso8601(real_date(get_cell_input(last_station, last_lap).value));
+  var raced_time = finish_time - start_time;
+  var bonus_time = calculate_bonus(complete_laps, start_time, allotted_time, table);
+  if (allotted_time && raced_time > allotted_time + bonus_time) {
+    /* Get stations past the deadline. */
+    var extras = [];
+    for (var j = last_lap; valid_column(table, j); j--) {
+      for (var i = last_row(table); valid_row(table, i); i--) {
+        var input = get_cell_input(i, j);
+        if (! input.value.match(input.pattern)) continue;
+        var station_time = from_iso8601(real_date(input.value));
+        var time = station_time - start_time;
+        if (time <= allotted_time) break;
+        /* Green highlight for stations visited within bonus time. */
+        if (time > allotted_time + bonus_time) extras.push(input);
+        else input.style.color = '#57ad63';
+      }
+    }
+    /* Only the first one counts. */
+    if (extras.length) {
+      extras.reverse();
+      var input = extras[0];
+      finish_time = from_iso8601(real_date(input.value));
+      var m = input.id.match(/^lap(\d+)station(\d+)$/);
+      last_lap = first_column(table) + parseInt(m[1]) - 1;
+      last_station = first_row(table) + parseInt(m[2]) - 1;
+      raced_time = finish_time - start_time;
+      if (last_station < last_row(table) - first_row(table) + 1) complete_laps = last_lap - first_column(table);
+      /* Orange highlight for stations disregarded .*/
+      for (var i = extras.length - 1; i; i--) extras[i].style.color = '#cc4300';
+      /* Blue highlight for first station visited after deadline. */
+      extras[0].style.color = '#3d8bcc';
+    }
+  }
+  var penalty_time = calculate_penalty(allotted_time, bonus_time, raced_time);
+  var total_time = calculate_total(allotted_time, bonus_time, penalty_time, raced_time);
+  var available_time = allotted_time + bonus_time;
+
   /* Find total distance. */
   var lap_distance = parseFloat(table.rows[summary_row(table)].cells[distance_column(table)].firstChild.innerHTML.replace(/Ly$/, ''));
   var total_distance = lap_distance * complete_laps;
@@ -473,14 +514,6 @@ function do_stats(table) {
     }
   }
 
-  var start_time = from_iso8601(real_date(get_cell_input(first_row(table), first_column(table)).value));
-  var finish_time = from_iso8601(real_date(get_cell_input(last_station, last_lap).value));
-  var raced_time = finish_time - start_time;
-  var bonus_time = calculate_bonus(complete_laps, start_time, allotted_time, table);
-  var penalty_time = calculate_penalty(allotted_time, bonus_time, raced_time);
-  var total_time = calculate_total(allotted_time, bonus_time, penalty_time, raced_time);
-  var available_time = allotted_time + bonus_time;
-
   /* Lap distance. */
   do_stat('lap_distance', lap_distance, String(lap_distance) + 'Ly');
   /* Complete laps. */
@@ -525,7 +558,9 @@ function validate(table, cloned) {
   for (var i = first_row(table); valid_row(table, i); i++) {
     for (var j = first_column(table); valid_column(table, j); j++) {
       var input = get_cell_input(i, j);
-      if (input) input.setCustomValidity("");
+      if (! input) contineu;
+      input.setCustomValidity("");
+      input.style.color = 'inherit';
     }
   }
 
@@ -582,7 +617,7 @@ function validate(table, cloned) {
         /* First lap must have stations. */
         if (no_stations_visited) {
           valid = false;
-          var input = get_cell_input(1, j);
+          var input = get_cell_input(first_row(table), j);
           input.setCustomValidity('Race not started');
         }
       }