Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added analog metrics. #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/stats/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export interface OverallType extends PlayerIndexedType {
successfulConversions: RatioType;
inputsPerMinute: RatioType;
digitalInputsPerMinute: RatioType;
joystickDistanceTraveled: number;
NikhilNarayana marked this conversation as resolved.
Show resolved Hide resolved
joystickMetersTraveled: number;
joystickAverageVelocity: RatioType;
openingsPerKill: RatioType;
damagePerOpening: RatioType;
neutralWinRatio: RatioType;
Expand Down
12 changes: 12 additions & 0 deletions src/stats/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface PlayerInput {
cstickInputCount: number;
buttonInputCount: number;
triggerInputCount: number;
joystickDistanceTraveled: number;
}

export class InputComputer implements StatComputer<PlayerInput[]> {
Expand All @@ -41,6 +42,7 @@ export class InputComputer implements StatComputer<PlayerInput[]> {
cstickInputCount: 0,
buttonInputCount: 0,
triggerInputCount: 0,
joystickDistanceTraveled: 0,
};
this.state.set(indices, playerState);
});
Expand Down Expand Up @@ -115,6 +117,12 @@ function handleInputCompute(
state.inputCount += 1;
state.triggerInputCount += 1;
}

// Track the distance that the joystick has traveled. These are in unit coordinates and can
// be converted into meters, provided the controller being used has a standard gamecube stick.
const deltaX = playerFrame.joystickX - prevPlayerFrame.joystickX;
const deltaY = playerFrame.joystickY - prevPlayerFrame.joystickY;
state.joystickDistanceTraveled += getJoystickAnalogDistance(deltaX, deltaY);
}

function countSetBits(x: number): number {
Expand All @@ -131,6 +139,10 @@ function countSetBits(x: number): number {
return count;
}

function getJoystickAnalogDistance(x: number, y: number): number {
return Math.sqrt(x * x + y * y)
}

function getJoystickRegion(x: number, y: number): JoystickRegion {
let region = JoystickRegion.DZ;

Expand Down
8 changes: 8 additions & 0 deletions src/stats/overall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export function generateOverallStats(
const totalDamage = _.sumBy(opponentStocks, "currentPercent") || 0;
const killCount = opponentEndedStocks.length;

const analogDistance = _.get(playerInputs, "joystickDistanceTraveled");
// Distance from stick top to gyro center is ~2cm. Distance from center to edge of gate is ~.47 rad.
// If there are more detailed measurements that have been taken, this is the place to use them.
const metersTraveled = analogDistance * (.02 * .47);

return {
playerIndex: playerIndex,
opponentIndex: opponentIndex,
Expand All @@ -56,6 +61,9 @@ export function generateOverallStats(
successfulConversions: getRatio(successfulConversionCount, conversionCount),
inputsPerMinute: getRatio(inputCounts.total, gameMinutes),
digitalInputsPerMinute: getRatio(inputCounts.buttons, gameMinutes),
joystickDistanceTraveled: analogDistance,
joystickMetersTraveled: metersTraveled,
joystickAverageVelocity: getRatio(metersTraveled, gameMinutes * 60),
openingsPerKill: getRatio(conversionCount, killCount),
damagePerOpening: getRatio(totalDamage, conversionCount),
neutralWinRatio: getOpeningRatio(conversionsByPlayerByOpening, playerIndex, opponentIndex, "neutral-win"),
Expand Down