'offensive_points_completed': 0,
'offensive_points_won': 0,
+ 'clean_holds': 0,
+
'defensive_points_completed': 0,
'defensive_points_won': 0,
+ 'clean_breaks': 0,
+
+ 'turnovers_won': 0,
+ 'turnovers_lost': 0,
+ 'their_clean_holds': 0,
+ 'their_clean_breaks': 0,
};
let globals = players['globals'];
let our_score = 0;
let their_score = 0;
+ let between_points = true;
let handler = null;
let handler_got_by_interception = false; // Only relevant if handler !== null.
let prev_handler = null;
let point_num = 0;
let game_started = null;
let last_goal = null;
+ let current_predominant_gender = null;
+ let current_num_players_on_field = null;
+
+ let we_lost_disc = false;
+ let they_lost_disc = false;
// The last used formations of the given kind, if any; they may be reused
// when the point starts, if nothing else is set.
keep = keep_event(players, formations_used_this_point, last_pull_was_ours, filters); // Recompute after in/out.
+ if (match['gender_rule_a']) {
+ if (type === 'restart' && !between_points) {
+ let predominant_gender = find_predominant_gender(players);
+ let num_players_on_field = find_num_players_on_field(players);
+ if (predominant_gender !== current_predominant_gender && current_predominant_gender !== null) {
+ console.log(match['description'] + ' ' + format_time(t) + ': Stoppage changed predominant gender from ' + current_predominant_gender + ' to ' + predominant_gender);
+ }
+ if (num_players_on_field !== current_num_players_on_field && current_num_players_on_field !== null) {
+ console.log(match['description'] + ' ' + format_time(t) + ': Stoppage changed number of players on field from ' + current_num_players_on_field + ' to ' + num_players_on_field);
+ }
+ current_predominant_gender = predominant_gender;
+ current_num_players_on_field = num_players_on_field;
+ } else if (type === 'pull' || type === 'their_pull') {
+ let predominant_gender = find_predominant_gender(players);
+ let num_players_on_field = find_num_players_on_field(players);
+ let changed = (predominant_gender !== current_predominant_gender);
+ if (point_num !== 0) {
+ let should_change = (point_num % 4 == 1 || point_num % 4 == 3); // ABBA changes on 1 and 3.
+ if (changed && !should_change) {
+ console.log(match['description'] + ' ' + format_time(t) + ': Gender ratio should have stayed the same, changed to predominance of ' + predominant_gender);
+ } else if (!changed && should_change) {
+ console.log(match['description'] + ' ' + format_time(t) + ': Gender ratio should have changed, remained predominantly ' + predominant_gender);
+ }
+ if (num_players_on_field !== current_num_players_on_field && current_num_players_on_field !== null) {
+ console.log(match['description'] + ' ' + format_time(t) + ': Number of players on field changed from ' + current_num_players_on_field + ' to ' + num_players_on_field);
+ }
+ }
+ current_predominant_gender = predominant_gender;
+ current_num_players_on_field = num_players_on_field;
+ }
+ }
+ if (match['gender_pull_rule']) {
+ if (type === 'pull') {
+ if (current_predominant_gender !== null &&
+ p.gender !== current_predominant_gender) {
+ console.log(match['description'] + ' ' + format_time(t) + ': ' + p.name + ' pulled, should have been ' + current_predominant_gender);
+ }
+ }
+ }
+
// Liveness management
if (type === 'pull' || type === 'their_pull' || type === 'restart') {
live_since = t;
+ between_points = false;
} else if (type === 'catch' && last_pull_was_ours === null) {
// Someone forgot to add the pull, so we'll need to wing it.
console.log(match['description'] + ' ' + format_time(t) + ': Missing pull on ' + our_score + '\u2013' + their_score + '; pretending to have one.');
live_since = t;
last_pull_was_ours = !offense;
+ between_points = false;
} else if (type === 'goal' || type === 'their_goal' || type === 'stoppage') {
+ if (type === 'goal') {
+ if (keep) ++p.touches;
+ }
for (const [q,p] of Object.entries(players)) {
if (p.on_field_since === null) {
continue;
puller = pull_started = null;
}
+ // Stats for clean holds or not (must be done before resetting we_lost_disc etc. below).
+ if (keep) {
+ if (type === 'goal' && !we_lost_disc) {
+ if (last_pull_was_ours === false) { // O point.
+ ++globals.clean_holds;
+ } else if (last_pull_was_ours === true) {
+ ++globals.clean_breaks;
+ }
+ } else if (type === 'their_goal' && !they_lost_disc) {
+ if (last_pull_was_ours === true) { // O point for them.
+ ++globals.their_clean_holds;
+ } else if (last_pull_was_ours === false) {
+ ++globals.their_clean_breaks;
+ }
+ }
+ }
+
// Offense/defense management
let last_offense = offense;
if (type === 'set_defense' || type === 'goal' || type === 'throwaway' || type === 'drop' || type === 'was_d' || type === 'stallout') {
offense = false;
+ we_lost_disc = true;
+ if (keep && type !== 'goal' && !(type === 'set_defense' && last_pull_was_ours === null)) {
+ ++globals.turnovers_lost;
+ }
} else if (type === 'set_offense' || type === 'their_goal' || type === 'their_throwaway' || type === 'defense' || type === 'interception') {
offense = true;
+ they_lost_disc = true;
+ if (keep && type !== 'their_goal' && !(type === 'set_offense' && last_pull_was_ours === null)) {
+ ++globals.turnovers_won;
+ }
+ }
+ if (type === 'goal' || type === 'their_goal') {
+ between_points = true;
+ we_lost_disc = false;
+ they_lost_disc = false;
}
if (last_offense !== offense && live_since !== null) {
// Switched offense/defense status, so attribute this drive as needed,
rows = make_table_playing_time(players);
} else if (chosen_category === 'per_point') {
rows = make_table_per_point(players);
+ } else if (chosen_category === 'team_wide') {
+ rows = make_table_team_wide(players);
}
rowsets.push(rows);
}
return 'playing_time';
} else if (window.location.hash === '#per_point') {
return 'per_point';
+ } else if (window.location.hash === '#team_wide') {
+ return 'team_wide';
} else {
return 'general';
}
function write_main_menu(chosen_category) {
let elems = [];
- if (chosen_category === 'general') {
- let span = document.createElement('span');
- span.innerText = 'General';
- elems.push(span);
- } else {
- let a = document.createElement('a');
- a.appendChild(document.createTextNode('General'));
- a.setAttribute('href', '#general');
- elems.push(a);
- }
-
- if (chosen_category === 'offense') {
- let span = document.createElement('span');
- span.innerText = 'Offense';
- elems.push(span);
- } else {
- let a = document.createElement('a');
- a.appendChild(document.createTextNode('Offense'));
- a.setAttribute('href', '#offense');
- elems.push(a);
- }
-
- if (chosen_category === 'defense') {
- let span = document.createElement('span');
- span.innerText = 'Defense';
- elems.push(span);
- } else {
- let a = document.createElement('a');
- a.appendChild(document.createTextNode('Defense'));
- a.setAttribute('href', '#defense');
- elems.push(a);
- }
-
- if (chosen_category === 'playing_time') {
- let span = document.createElement('span');
- span.innerText = 'Playing time';
- elems.push(span);
- } else {
- let a = document.createElement('a');
- a.appendChild(document.createTextNode('Playing time'));
- a.setAttribute('href', '#playing_time');
- elems.push(a);
- }
-
- if (chosen_category === 'per_point') {
- let span = document.createElement('span');
- span.innerText = 'Per point';
- elems.push(span);
- } else {
- let a = document.createElement('a');
- a.appendChild(document.createTextNode('Per point'));
- a.setAttribute('href', '#per_point');
- elems.push(a);
+ const categories = [
+ ['general', 'General'],
+ ['offense', 'Offense'],
+ ['defense', 'Defense'],
+ ['playing_time', 'Playing time'],
+ ['per_point', 'Per point'],
+ ['team_wide', 'Team-wide'],
+ ];
+ for (const [id, title] of categories) {
+ if (chosen_category === id) {
+ let span = document.createElement('span');
+ span.innerText = title;
+ elems.push(span);
+ } else {
+ let a = document.createElement('a');
+ a.appendChild(document.createTextNode(title));
+ a.setAttribute('href', '#' + id);
+ elems.push(a);
+ }
}
document.getElementById('mainmenu').replaceChildren(...elems);
return rows;
}
+function make_table_team_wide(players) {
+ let globals = players['globals'];
+
+ let rows = [];
+ {
+ let header = document.createElement('tr');
+ add_th(header, '');
+ add_th(header, 'Our team', 6);
+ add_th(header, 'Opponents', 6);
+ rows.push(header);
+ }
+
+ // Turnovers.
+ {
+ let row = document.createElement('tr');
+ let name = add_3cell(row, 'Turnovers generated', 'name');
+ add_3cell(row, globals.turnovers_won);
+ add_3cell(row, '');
+ add_3cell(row, globals.turnovers_lost);
+ add_3cell(row, '');
+ rows.push(row);
+ }
+
+ // Clean holds.
+ {
+ let row = document.createElement('tr');
+ let name = add_3cell(row, 'Clean holds', 'name');
+ let our_clean_holds = make_binomial_ci(globals.clean_holds, globals.offensive_points_completed, z);
+ let their_clean_holds = make_binomial_ci(globals.their_clean_holds, globals.defensive_points_completed, z);
+ our_clean_holds.desired = 0.3; // Arbitrary.
+ our_clean_holds.format = 'percentage';
+ their_clean_holds.desired = 0.3;
+ their_clean_holds.format = 'percentage';
+ add_3cell(row, globals.clean_holds + ' / ' + globals.offensive_points_completed);
+ add_3cell_ci(row, our_clean_holds);
+ add_3cell(row, globals.their_clean_holds + ' / ' + globals.defensive_points_completed);
+ add_3cell_ci(row, their_clean_holds);
+ rows.push(row);
+ }
+
+ // Clean breaks.
+ {
+ let row = document.createElement('tr');
+ let name = add_3cell(row, 'Clean breaks', 'name');
+ let our_clean_breaks = make_binomial_ci(globals.clean_breaks, globals.defensive_points_completed, z);
+ let their_clean_breaks = make_binomial_ci(globals.their_clean_breaks, globals.offensive_points_completed, z);
+ our_clean_breaks.desired = 0.3; // Arbitrary.
+ our_clean_breaks.format = 'percentage';
+ their_clean_breaks.desired = 0.3;
+ their_clean_breaks.format = 'percentage';
+ add_3cell(row, globals.clean_breaks + ' / ' + globals.defensive_points_completed);
+ add_3cell_ci(row, our_clean_breaks);
+ add_3cell(row, globals.their_clean_breaks + ' / ' + globals.offensive_points_completed);
+ add_3cell_ci(row, their_clean_breaks);
+ rows.push(row);
+ }
+
+ return rows;
+}
+
function make_table_offense(players) {
let rows = [];
{
return true;
}
-function find_gender_ratio_code(players) {
+// Returns a map of e.g. F => 4, M => 3.
+function find_gender_ratio(players) {
let map = {};
for (const [q,p] of Object.entries(players)) {
if (p.on_field_since === null) {
++map[gender];
}
}
+ return map;
+}
+
+function find_gender_ratio_code(players) {
+ let map = find_gender_ratio(players);
let all_genders = Array.from(Object.keys(map)).sort(
(a,b) => {
if (map[a] !== map[b]) {
return code;
}
+// null if none (e.g., if playing 3–3).
+function find_predominant_gender(players) {
+ let max = 0;
+ let predominant_gender = null;
+ for (const [gender, num] of Object.entries(find_gender_ratio(players))) {
+ if (num > max) {
+ max = num;
+ predominant_gender = gender;
+ } else if (num == max) {
+ predominant_gender = null; // At least two have the same.
+ }
+ }
+ return predominant_gender;
+}
+
+function find_num_players_on_field(players) {
+ let num = 0;
+ for (const [q,p] of Object.entries(players)) {
+ if (p.on_field_since !== null) {
+ ++num;
+ }
+ }
+ return num;
+}
+
function filter_passes(players, formations_used_this_point, last_pull_was_ours, filter) {
if (filter.type === 'player_any') {
for (const p of Array.from(filter.elements)) {