Skip to content

Commit

Permalink
3.5.4 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWoodward committed Jul 7, 2022
1 parent 46df011 commit 5af1436
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 66 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ SplitsBrowser changelog:
3.5.1: Add support for viewing relay events in common-controls-only mode.
3.5.2: Fix issues loading event with negative cumulative times (#80).
3.5.3: Fix issues with relay events (#81, #82).
3.5.4: Add flag controlling whether to permit zero-second splits (#83), fix other bug (#84).
2 changes: 1 addition & 1 deletion js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@

// Tell ESLint not to complain that this is redeclaring a constant.
/* eslint no-redeclare: "off", no-unused-vars: "off" */
var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Messages: {} };
var SplitsBrowser = { Version: "3.5.4", Model: {}, Input: {}, Controls: {}, Messages: {} };
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "splitsbrowser",
"version": "3.5.3",
"version": "3.5.4",
"license": "GPL-2.0",
"repository": {
"type": "git",
Expand Down
23 changes: 13 additions & 10 deletions splitsbrowser.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

// Tell ESLint not to complain that this is redeclaring a constant.
/* eslint no-redeclare: "off", no-unused-vars: "off" */
var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Messages: {} };
var SplitsBrowser = { Version: "3.5.4", Model: {}, Input: {}, Controls: {}, Messages: {} };

/*
* SplitsBrowser - Assorted utility functions.
Expand Down Expand Up @@ -869,6 +869,11 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
var referenceSplit = referenceCumTimes[index + 1] - referenceCumTimes[index];
if (referenceSplit > 0) {
percentsBehind.push(100 * (splitTime - referenceSplit) / referenceSplit);
} else if (referenceSplit === 0) {
// A zero-time control is likely to be a timed-out road crossing where a limited amount
// of time was permitted and later removed. Add another point at the same position as the
// previous.
percentsBehind.push(percentsBehind.length === 0 ? 0 : percentsBehind[percentsBehind.length - 1]);
} else {
percentsBehind.push(null);
}
Expand All @@ -890,11 +895,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
throwInvalidData("Cannot determine time loss when there is a NaN value in the fastest splits");
}

if (fastestSplitTimes.some(function (split) { return split === 0; })) {
// Someone registered a zero split on this course. In this
// situation the time losses don't really make sense.
this.timeLosses = this.splitTimes.map(function () { return NaN; });
} else if (this.isOKDespiteMissingTimes || this.splitTimes.some(isNaNStrict)) {
if (this.isOKDespiteMissingTimes || this.splitTimes.some(isNaNStrict)) {
// There are some missing or dubious times. Unfortunately
// this means we cannot sensibly calculate the time losses.
this.timeLosses = this.splitTimes.map(function () { return NaN; });
Expand All @@ -905,15 +906,17 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
// (split[i] - fastest[i])/fastest[i]. A control's split ratio
// is its time loss rate plus 1. Not subtracting one at the start
// means that we then don't have to add it back on at the end.
// We also exclude any controls where the fastest split is zero.

var splitRatios = this.splitTimes.map(function (splitTime, index) {
return splitTime / fastestSplitTimes[index];
});
var splitRatios = this.splitTimes.filter(function (splitTime, index) { return fastestSplitTimes[index] !== 0; })
.map(function (splitTime, index) { return splitTime / fastestSplitTimes[index]; });

splitRatios.sort(d3.ascending);

var medianSplitRatio;
if (splitRatios.length % 2 === 1) {
if (splitRatios.length === 0) {
medianSplitRatio = NaN;
} else if (splitRatios.length % 2 === 1) {
medianSplitRatio = splitRatios[(splitRatios.length - 1) / 2];
} else {
var midpt = splitRatios.length / 2;
Expand Down
4 changes: 2 additions & 2 deletions splitsbrowser.data.min.js

Large diffs are not rendered by default.

88 changes: 43 additions & 45 deletions splitsbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

// Tell ESLint not to complain that this is redeclaring a constant.
/* eslint no-redeclare: "off", no-unused-vars: "off" */
var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Messages: {} };
var SplitsBrowser = { Version: "3.5.4", Model: {}, Input: {}, Controls: {}, Messages: {} };

/*
* SplitsBrowser - Assorted utility functions.
Expand Down Expand Up @@ -1065,6 +1065,11 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
var referenceSplit = referenceCumTimes[index + 1] - referenceCumTimes[index];
if (referenceSplit > 0) {
percentsBehind.push(100 * (splitTime - referenceSplit) / referenceSplit);
} else if (referenceSplit === 0) {
// A zero-time control is likely to be a timed-out road crossing where a limited amount
// of time was permitted and later removed. Add another point at the same position as the
// previous.
percentsBehind.push(percentsBehind.length === 0 ? 0 : percentsBehind[percentsBehind.length - 1]);
} else {
percentsBehind.push(null);
}
Expand All @@ -1086,11 +1091,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
throwInvalidData("Cannot determine time loss when there is a NaN value in the fastest splits");
}

if (fastestSplitTimes.some(function (split) { return split === 0; })) {
// Someone registered a zero split on this course. In this
// situation the time losses don't really make sense.
this.timeLosses = this.splitTimes.map(function () { return NaN; });
} else if (this.isOKDespiteMissingTimes || this.splitTimes.some(isNaNStrict)) {
if (this.isOKDespiteMissingTimes || this.splitTimes.some(isNaNStrict)) {
// There are some missing or dubious times. Unfortunately
// this means we cannot sensibly calculate the time losses.
this.timeLosses = this.splitTimes.map(function () { return NaN; });
Expand All @@ -1101,15 +1102,17 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
// (split[i] - fastest[i])/fastest[i]. A control's split ratio
// is its time loss rate plus 1. Not subtracting one at the start
// means that we then don't have to add it back on at the end.
// We also exclude any controls where the fastest split is zero.

var splitRatios = this.splitTimes.map(function (splitTime, index) {
return splitTime / fastestSplitTimes[index];
});
var splitRatios = this.splitTimes.filter(function (splitTime, index) { return fastestSplitTimes[index] !== 0; })
.map(function (splitTime, index) { return splitTime / fastestSplitTimes[index]; });

splitRatios.sort(d3.ascending);

var medianSplitRatio;
if (splitRatios.length % 2 === 1) {
if (splitRatios.length === 0) {
medianSplitRatio = NaN;
} else if (splitRatios.length % 2 === 1) {
medianSplitRatio = splitRatios[(splitRatios.length - 1) / 2];
} else {
var midpt = splitRatios.length / 2;
Expand Down Expand Up @@ -2900,6 +2903,19 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
return result.getControlIndexesAroundOmittedCumulativeTimes();
}

/**
* Wraps an index-around-omitted-cumulative-times function and returns a
* function that filters out any range it returned that covers the start.
* @param {Function} func The function to wrap.
* @return {Function} Function that wraps the given function and filters out
* any ranges it returned that cover the start.
*/
function excludeIfCoveringStart(func) {
return function (result) {
return func(result).filter(function (range) { return range.start > 0; });
};
}

/**
* Returns indexes around the given competitor's omitted split times.
* @param {Result} result The result to get the indexes for.
Expand Down Expand Up @@ -2938,7 +2954,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
isRaceGraph: false,
isResultsTable: false,
minViewableControl: 1,
indexesAroundOmittedTimesFunc: getIndexesAroundOmittedCumulativeTimes
indexesAroundOmittedTimesFunc: excludeIfCoveringStart(getIndexesAroundOmittedCumulativeTimes)
},
SplitPosition: {
nameKey: "SplitPositionChartType",
Expand All @@ -2947,7 +2963,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
isRaceGraph: false,
isResultsTable: false,
minViewableControl: 1,
indexesAroundOmittedTimesFunc: getIndexesAroundOmittedSplitTimes
indexesAroundOmittedTimesFunc: excludeIfCoveringStart(getIndexesAroundOmittedSplitTimes)
},
PercentBehind: {
nameKey: "PercentBehindChartType",
Expand Down Expand Up @@ -3290,9 +3306,12 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess

/**
* Construct a Repairer, for repairing some data.
* @constructor
* @param {Boolean} permitZeroSplits Whether to permit zero-second splits.
*/
var Repairer = function () {
var Repairer = function (permitZeroSplits) {
this.madeAnyChanges = false;
this.permitZeroSplits = permitZeroSplits;
};

/**
Expand All @@ -3307,7 +3326,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
* @return {Object|null} Object containing indexes of non-ascending entries, or
* null if none found.
*/
function getFirstNonAscendingIndexes(cumTimes) {
Repairer.prototype.getFirstNonAscendingIndexes = function (cumTimes) {
if (cumTimes.length === 0 || cumTimes[0] !== 0) {
throwInvalidData("cumulative times array does not start with a zero cumulative time");
}
Expand All @@ -3318,7 +3337,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
var time = cumTimes[index];
if (isNotNullNorNaN(time)) {
// This entry is numeric.
if (time <= cumTimes[lastNumericTimeIndex]) {
if (time < cumTimes[lastNumericTimeIndex] || (time === cumTimes[lastNumericTimeIndex] && (!this.permitZeroSplits || lastNumericTimeIndex < index - 1))) {
return {first: lastNumericTimeIndex, second: index};
}

Expand All @@ -3328,26 +3347,6 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess

// If we get here, the entire array is in strictly-ascending order.
return null;
}


/**
* Remove, by setting to NaN, any cumulative time that is equal to the
* previous cumulative time.
* @param {Array} cumTimes Array of cumulative times.
*/
Repairer.prototype.removeCumulativeTimesEqualToPrevious = function (cumTimes) {
var lastCumTime = cumTimes[0];
for (var index = 1; index + 1 < cumTimes.length; index += 1) {
if (cumTimes[index] !== null) {
if (cumTimes[index] === lastCumTime) {
cumTimes[index] = NaN;
this.madeAnyChanges = true;
} else {
lastCumTime = cumTimes[index];
}
}
}
};

/**
Expand All @@ -3364,7 +3363,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
*/
Repairer.prototype.removeCumulativeTimesCausingNegativeSplits = function (cumTimes) {

var nonAscIndexes = getFirstNonAscendingIndexes(cumTimes);
var nonAscIndexes = this.getFirstNonAscendingIndexes(cumTimes);
while (nonAscIndexes !== null && nonAscIndexes.second + 1 < cumTimes.length) {

// So, we have a pair of cumulative times that are not in strict
Expand Down Expand Up @@ -3405,7 +3404,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
adjustedCumTimes[first - 1] = NaN;
}

var nextNonAscIndexes = getFirstNonAscendingIndexes(adjustedCumTimes);
var nextNonAscIndexes = this.getFirstNonAscendingIndexes(adjustedCumTimes);
if (nextNonAscIndexes === null || nextNonAscIndexes.first > second) {
progress = true;
cumTimes = adjustedCumTimes;
Expand Down Expand Up @@ -3451,8 +3450,6 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
Repairer.prototype.repairResult = function (result) {
var cumTimes = result.originalCumTimes.slice(0);

this.removeCumulativeTimesEqualToPrevious(cumTimes);

cumTimes = this.removeCumulativeTimesCausingNegativeSplits(cumTimes);

if (!result.completed()) {
Expand Down Expand Up @@ -3491,9 +3488,10 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
/**
* Attempt to carry out repairs to the data in an event.
* @param {Event} eventData The event data to repair.
* @param {Boolean} permitZeroSplits Whether zero-second splits are permitted.
*/
function repairEventData(eventData) {
var repairer = new Repairer();
function repairEventData(eventData, permitZeroSplits) {
var repairer = new Repairer(permitZeroSplits);
repairer.repairEventData(eventData);
}

Expand All @@ -3502,7 +3500,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
*
* This is used if the input data has been read in a format that requires
* the data to be checked, but the user has opted not to perform any such
* reparations and wishes to view the
* reparations and wishes to view the original data.
* @param {Event} eventData The event data to repair.
*/
function transferResultData(eventData) {
Expand Down Expand Up @@ -11857,7 +11855,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
/*
* SplitsBrowser Viewer - Top-level class that runs the application.
*
* Copyright (C) 2000-2021 Dave Ryder, Reinhard Balling, Andris Strazdins,
* Copyright (C) 2000-2022 Dave Ryder, Reinhard Balling, Andris Strazdins,
* Ed Nash, Luke Woodward
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -12554,7 +12552,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
if (showOriginalData) {
transferResultData(this.eventData);
} else {
repairEventData(this.eventData);
repairEventData(this.eventData, this.options && this.options.permitZeroSplits);
}

this.eventData.determineTimeLosses();
Expand Down Expand Up @@ -12711,7 +12709,7 @@ var SplitsBrowser = { Version: "3.5.3", Model: {}, Input: {}, Controls: {}, Mess
showLoadFailureMessage("LoadFailedUnrecognisedData", {});
} else {
if (eventData.needsRepair()) {
repairEventData(eventData);
repairEventData(eventData, options && options.permitZeroSplits);
}

if (typeof options === "string") {
Expand Down
10 changes: 5 additions & 5 deletions splitsbrowser.min.js

Large diffs are not rendered by default.

0 comments on commit 5af1436

Please sign in to comment.