Skip to content
Snippets Groups Projects
Commit 5c7d6bbf authored by spencerkee's avatar spencerkee
Browse files

Started a better way of adding inputs

parent 9bf3c174
No related branches found
No related tags found
No related merge requests found
......@@ -72,6 +72,18 @@ const recordingButtons = [
// recordStart,
]
const codeDataButtonIndexes = [
[14, 19], // Neutral
[15, 19], // Up
[15, 19], // Down
[15, 19], // Left
[15, 19], // Right
[0, 5], // A
[0, 5], // B
// [0, 5], // Select
// [0, 5], // Start
]
let recordingButtonIsHeldArr = [
false, // recordNetural
false, // recordUp
......@@ -84,6 +96,33 @@ let recordingButtonIsHeldArr = [
// false, // recordStart
]
function analyze(arr) {
// Find min length in arr
let minLength = Infinity;
arr.forEach(codeData => {
if (codeData.length < minLength) {
minLength = codeData.length;
}
});
let answer = "";
for (let i = 0; i < minLength; i++) {
let allSame = true;
let thisLetter = arr[0][i];
arr.forEach(codeData => {
if (codeData[i] !== thisLetter) {
allSame = false;
}
});
if (allSame) {
answer += thisLetter;
} else {
answer += "~";
}
}
console.log(answer);
return answer;
}
// Add a listener for each recording button to set the corresponding index in the array to true when pressed
recordingButtons.forEach((button, index) => {
button.onpointerdown = () => {
......@@ -96,7 +135,12 @@ recordingButtons.forEach((button, index) => {
// Sum the counts
let counts = Object.values(relevantRecordedData).map(data => data.count);
const sum = counts.reduce((partialSum, a) => partialSum + a, 0);
let threshold = sum * 0.40;
let threshold = 0;
if (index === 0) {
threshold = sum * 0.80;
} else {
threshold = sum * 0.40;
}
// Get sorted list of recordedData for this button
let sortedRecordedData = Object.entries(relevantRecordedData).sort((a, b) => b[1].count - a[1].count);
// Convert sortedRecordedData to an array of arrays
......@@ -112,11 +156,61 @@ recordingButtons.forEach((button, index) => {
if (accumulator > threshold) {
break;
}
bestValues.push(sortedRecordedData[i]);
bestValues.push([sortedRecordedData[i][0], getButtonReadouts(sortedRecordedData[i][0])]);
accumulator += sortedRecordedData[i][1];
}
bestValues.forEach((codeData, buttonReadout) => {
console.log('me');
});
let stringBestValues = bestValues.map(a => a[0]);
stringBestValues.forEach(codeData => {
let relevantSlice = codeData.substring(
codeDataButtonIndexes[index][0],
codeDataButtonIndexes[index][1]
);
// Check if relevantSlice is in codeDataButtonSubstrings[index]
if (!codeDataButtonSubstrings[index].includes(relevantSlice)) {
codeDataButtonSubstrings[index].push(relevantSlice);
console.log(`Adding ${relevantSlice} to codeDataButtonSubstrings[${index}]`);
}
});
// if (index === 0) {
// // TODO Only add unique ones.
// codeDataButtonSubstrings[0].push(...bestValues.map(codeData => codeData[0]));
// let junk = analyze(codeDataButtonSubstrings[0]);
// debugger;
// } else {
// let junk = analyze(codeDataButtonSubstrings[index]);
// let minDiff = Infinity;
// let minDiffString = "";
// bestValues.forEach(possibleInput => {
// // Find the string in codeDataButtonSubstrings[0] which differes from
// // possibleInput by the least characters
// codeDataButtonSubstrings[0].forEach(neutralCodeData => {
// let diff = 0;
// for (let i = 0; i < neutralCodeData.length; i++) {
// if (neutralCodeData[i] !== possibleInput[0][i]) {
// diff++;
// }
// }
// if (diff < minDiff) {
// minDiff = diff;
// minDiffString = neutralCodeData;
// }
// });
// });
debugger;
}
}
});
// let time;
......@@ -277,7 +371,21 @@ navigator.mediaDevices
});
let codeDataButtonSubstrings = [
[], // Neutral
// Indexes 15-19 inclusive for neutral input
[
"OONYS",
"OOQRS",
"OPQRS",
"OOQ/S",
"OOI3S",
"OPQ/S",
"OOZ6S",
"OOPOS",
"OPNYS",
"OOO5S",
"OOI3S",
"OOO5S",
], // Neutral
[], // Up
[], // Down
[
......@@ -291,32 +399,33 @@ let codeDataButtonSubstrings = [
"OP98S",
], // Left
[
"OO$:S",
"OPJMS",
"OOZ6S",
"OPZ6S",
"OPCHS",
"OPD S",
"OOD S",
"OPGTS",
"OO PS",
"OOYJS",
"OOFAS",
"OPH0S",
"OPDGS",
"OPDKS",
"OPXWS",
"OPU*S",
"OOGTS",
"OODKS",
// "OO$:S",
// "OPJMS",
// "OOZ6S",
// "OPZ6S",
// "OPCHS",
// "OPD S",
// "OOD S",
// "OPGTS",
// "OO PS",
// "OOYJS",
// "OOFAS",
// "OPH0S",
// "OPDGS",
// "OPDKS",
// "OPXWS",
// "OPU*S",
// "OOGTS",
// "OODKS",
], // Right
// Indexes 0-5 inclusive
[
"A7H",
"ANH",
"A8+",
"A8H",
"A9H",
"AO+",
// "A7H",
// "ANH",
// "A8+",
// "A8H",
// "A9H",
// "AO+",
], // A
[], // B
// [], // Select
......@@ -329,23 +438,32 @@ function getButtonReadouts(codeData) {
//a: qr.a, // don't reset a!
};
let directionComponent = codeData.substring(
codeDataButtonIndexes[0][0],
codeDataButtonIndexes[0][1]
);
let aComponent = codeData.substring(
codeDataButtonIndexes[5][0],
codeDataButtonIndexes[5][1]
);
// Left
if (
codeDataButtonSubstrings[3].some((substring) => codeData.includes(substring))
codeDataButtonSubstrings[3].some((substring) => directionComponent === substring)
) {
localQr.left = true;
}
// Right
if (
codeDataButtonSubstrings[4].some((substring) => codeData.includes(substring))
codeDataButtonSubstrings[4].some((substring) => directionComponent === substring)
) {
localQr.right = true;
}
// A button
if (
codeDataButtonSubstrings[5].some((substring) => codeData.includes(substring))
codeDataButtonSubstrings[5].some((substring) => aComponent === substring)
) {
localQr.a = true;
}
......
test.js 0 → 100644
function analyze(arr) {
// Find min length in arr
let minLength = arr.reduce((min, codeData) => {
return Math.min(min, codeData.length);
});
let answer = "";
for (let i = 0; i < minLength; i++) {
let allSame = true;
let thisLetter = arr[0][i];
arr[0].forEach(codeData => {
if (codeData[i] !== thisLetter) {
allSame = false;
}
});
if (allSame) {
answer += thisLetter;
} else {
answer += "!";
}
}
console.log(answer);
return answer;
}
A!Z2EFGHIJKLMNO!!!STUVWXY
1, 15, 16, 17
var neutral = ["AQZ2EFGHIJKLMNOONYSTUVWXY",
"AQZ2EFGHIJKLMNOOQRSTUVWXY",
"AQZ2EFGHIJKLMNOPQRSTUVWXY",
"AQZ2EFGHIJKLMNOOQ/STUVWXY",
"AKZ2EFGHIJKLMNOOI3STUVWXY",
"AQZ2EFGHIJKLMNOPQ/STUVWXY",
"AQZ2EFGHIJKLMNOOZ6STUVWXY",
"AKZ2EFGHIJKLMNOOPOSTUVWXY",
"AQZ2EFGHIJKLMNOPNYSTUVWXY",
"AQZ2EFGHIJKLMNOOO5STUVWXY",
"AQZ2EFGHIJKLMNOOI3STUVWXY",
"AKZ2EFGHIJKLMNOOO5STUVWXY"]
"AQZ2EFGHIJKLMNOONYS TUVWXY",
"AQZ2EFGHIJKLMNOOQRS TUVWXY",
"AQZ2EFGHIJKLMNOPQRS TUVWXY",
"AQZ2EFGHIJKLMNOOQ/S TUVWXY",
"AKZ2EFGHIJKLMNOOI3S TUVWXY",
"AQZ2EFGHIJKLMNOPQ/S TUVWXY",
"AQZ2EFGHIJKLMNOOZ6S TUVWXY",
"AKZ2EFGHIJKLMNOOPOS TUVWXY",
"AQZ2EFGHIJKLMNOPNYS TUVWXY",
"AQZ2EFGHIJKLMNOOO5S TUVWXY",
"AQZ2EFGHIJKLMNOOI3S TUVWXY",
"AKZ2EFGHIJKLMNOOO5S TUVWXY",
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment