Display percent similarity

This commit is contained in:
ConfusedPolarBear 2022-05-30 03:24:19 -05:00
parent 19660cb1b2
commit 872451cc7e

View File

@ -75,6 +75,7 @@
// first and second episodes to fingerprint & compare // first and second episodes to fingerprint & compare
var lhs = []; var lhs = [];
var rhs = []; var rhs = [];
var diffCount = []; // count of bits that are different
// seasons grouped by show // seasons grouped by show
var shows = {}; var shows = {};
@ -91,8 +92,8 @@
async function onLoad() { async function onLoad() {
shows = await getJson("Intros/Shows"); shows = await getJson("Intros/Shows");
// add all show names to the selects // sort all show names & add to the select
for (var show in shows) { for (var show of shows) {
addItem(selectShow, show, show); addItem(selectShow, show, show);
} }
@ -232,20 +233,24 @@
const y = e.clientY - rect.top; const y = e.clientY - rect.top;
const shift = Number(txtOffset.value); const shift = Number(txtOffset.value);
let lTime, rTime; let lTime, rTime, diffPos;
if (shift < 0) { if (shift < 0) {
lTime = y * 0.128; lTime = y * 0.128;
rTime = (y + shift) * 0.128; rTime = (y + shift) * 0.128;
diffPos = y + shift;
} else { } else {
lTime = (y - shift) * 0.128; lTime = (y - shift) * 0.128;
rTime = y * 0.128; rTime = y * 0.128;
diffPos = y - shift;
} }
diffPos = Math.floor(diffPos);
lTime = Math.round(lTime * 100) / 100; lTime = Math.round(lTime * 100) / 100;
rTime = Math.round(rTime * 100) / 100; rTime = Math.round(rTime * 100) / 100;
const times = document.querySelector("span#timestamps"); const times = document.querySelector("span#timestamps");
times.textContent = lTime + ", " + rTime; times.textContent = lTime + ", " + rTime + " similarity is " + diffCount[diffPos];
times.style.position = "relative"; times.style.position = "relative";
times.style.left = "25px"; times.style.left = "25px";
@ -280,16 +285,21 @@
} }
} }
// if rendering the XOR of the fingerprints, log the result // if rendering the XOR of the fingerprints, count how many bits are different at each timecode
if (xor) { if (xor) {
diffCount = [];
for (let i = 0; i < fp.length; i++) { for (let i = 0; i < fp.length; i++) {
let count = 0; let count = 0;
for (let j = 0; j < 32; j++) { for (let j = 0; j < 32; j++) {
count += (fp[i] & (1 << j)); if (fp[i] & (1 << j)) {
count++;
}
} }
console.debug(count); // push the percentage similarity
diffCount[i] = 100 - (count * 100) / 32;
} }
} }