|
"use strict"; |
|
|
|
const formOptions = document.querySelector("#options-form-compare"); |
|
let compareBtn = document.querySelector('#compare-btn'); |
|
let metricsDashboardContainer = document.querySelector("#metrics-dashboard-container"); |
|
let vtContainer = document.querySelector("#main-vt-container"); |
|
const inputExactMatch = document.querySelector("#exact-match"); |
|
const inputInsert = document.querySelector("#insertion"); |
|
const inputDelSubts = document.querySelector("#delSubts"); |
|
|
|
function showHideSpinner() { |
|
let spinnerLoad = document.querySelector("#spinner-compare"); |
|
|
|
const currentState = () => { |
|
spinnerLoad.style['display'] = "none"; |
|
document.querySelector('#message-compare-btn').textContent = " Compare"; |
|
compareBtn.removeAttribute('disabled'); |
|
} |
|
|
|
const loadState = () => { |
|
spinnerLoad.style['display'] = ""; |
|
document.querySelector('#message-compare-btn').textContent = " Release the Kraken...! π"; |
|
compareBtn.setAttribute('disabled', "true"); |
|
} |
|
|
|
return (spinnerLoad.style['display'] === "none") ? loadState() : currentState() |
|
} |
|
|
|
|
|
function getTextAreaValue() { |
|
return [document.querySelector('#reference').value, |
|
document.querySelector('#prediction').value]; |
|
} |
|
|
|
|
|
function serializeFormData(reference, prediction) { |
|
let inputs = formOptions.getElementsByTagName('input'); |
|
let data = { |
|
reference: reference, |
|
prediction: prediction, |
|
preprocessingOpts: "", |
|
vtOpt:0 |
|
}; |
|
|
|
Object.values(inputs).forEach(input =>{ |
|
input.checked |
|
? input.name !== "optVT" |
|
? data.preprocessingOpts += input.value |
|
: data.vtOpt = 1 |
|
: input; |
|
}); |
|
|
|
return data |
|
} |
|
|
|
function tabulate(columns, scores){ |
|
let table = d3.select('#table-result-container').append('table').attr('class', 'dataframe data table table-hover table-bordered'); |
|
let thead = table.append('thead'); |
|
let tbody = table.append('tbody'); |
|
|
|
thead.append('tr').selectAll('th').data(columns).enter().append('th').text(function (column) { |
|
return column; |
|
}); |
|
let rows = tbody.selectAll('tr').data(scores).enter().append('tr'); |
|
|
|
rows.selectAll('td').data(function (row, i) { |
|
return row; |
|
}).enter().append('td').html(function (d) { |
|
if ((typeof d === "string") && (d !== "Γ")) { |
|
d = "<b>" + d + "</b>"; |
|
} |
|
return d; |
|
}); |
|
} |
|
|
|
function populateVersusText(reference, comparaison, prediction){ |
|
[{reference:reference}, {comparaison: comparaison}, {prediction: prediction}].forEach(version => { |
|
document.querySelector(`#vt-${Object.keys(version)[0]}`).innerHTML = Object.values(version)[0].join(''); |
|
}); |
|
} |
|
|
|
function versusTextSelector(){ |
|
[inputExactMatch, inputInsert, inputDelSubts].forEach(btn => { |
|
btn.addEventListener('click', function (event) { |
|
document.querySelectorAll("."+event.target.id).forEach(item => { |
|
(event.target.checked) ? item.classList.remove('clear') : item.classList.add('clear'); |
|
}); |
|
}) |
|
}) |
|
} |
|
|
|
function fileJSLoader (file, id){ |
|
|
|
try{ |
|
document.querySelector("#"+id).remove(); |
|
}catch (e) {} |
|
|
|
let scriptElement = document.createElement("script"); |
|
|
|
scriptElement.id = "dynamic-vt-script"; |
|
scriptElement.type = "text/javascript"; |
|
scriptElement.src = "static/"+file; |
|
|
|
document.getElementById("head").appendChild(scriptElement); |
|
} |
|
|
|
function sendFormToResults() { |
|
|
|
let textAreaValues = getTextAreaValue(); |
|
let reference = textAreaValues[0]; |
|
let prediction = textAreaValues[1]; |
|
if (reference !== "" && prediction !== "") { |
|
|
|
metricsDashboardContainer.style.display = 'none'; |
|
|
|
vtContainer.style.display = 'none'; |
|
|
|
showHideSpinner(); |
|
|
|
try{ |
|
document.querySelector('.dataframe').remove(); |
|
}catch (e) {} |
|
|
|
fetch('/compute_results',{ |
|
method: 'POST', |
|
headers: { |
|
'Accept': 'application/json', |
|
'Content-Type': 'application/json' |
|
}, |
|
|
|
body:JSON.stringify(serializeFormData(reference, prediction)) |
|
}) |
|
.then(response => response.json()) |
|
.then(function (response) { |
|
tabulate(response.columns, response.scores); |
|
metricsDashboardContainer.style.display = ''; |
|
if (response.comparaison.length !== 0){ |
|
populateVersusText(response.reference, response.comparaison, response.prediction) |
|
vtContainer.style.display = ''; |
|
versusTextSelector(); |
|
|
|
|
|
fileJSLoader("js/dynamicVT.min.js", "dynamic-vt-script"); |
|
}else{ |
|
vtContainer.style.display = 'none'; |
|
} |
|
showHideSpinner("hide"); |
|
}).catch(function(){ |
|
showHideSpinner("hide"); |
|
}); |
|
} |
|
} |
|
|
|
compareBtn.addEventListener("click", function () { |
|
sendFormToResults(); |
|
}); |