Clean up variable declarations
All checks were successful
Build Dev PWA / Build-PWA (push) Successful in 37s

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-10-11 20:20:00 -07:00
parent 874901086d
commit 726d56131c
8 changed files with 69 additions and 71 deletions

View File

@@ -75,14 +75,18 @@ async function localDetect(imageData) {
console.time('sw: post-process') console.time('sw: post-process')
const outputSize = res.shape[1] const outputSize = res.shape[1]
const output = {
detections: []
}
let rawBoxes = [] let rawBoxes = []
let rawScores = [] let rawScores = []
let getScores, getBox, boxCalc
for (var i = 0; i < rawRes.length; i++) { for (let i = 0; i < rawRes.length; i++) {
var getScores = rawRes[i].slice(4) getScores = rawRes[i].slice(4)
if (getScores.every( s => s < .05)) { continue } if (getScores.every( s => s < .05)) { continue }
var getBox = rawRes[i].slice(0,4) getBox = rawRes[i].slice(0,4)
var boxCalc = [ boxCalc = [
(getBox[0] - (getBox[2] / 2)) / modelWidth, (getBox[0] - (getBox[2] / 2)) / modelWidth,
(getBox[1] - (getBox[3] / 2)) / modelHeight, (getBox[1] - (getBox[3] / 2)) / modelHeight,
(getBox[0] + (getBox[2] / 2)) / modelWidth, (getBox[0] + (getBox[2] / 2)) / modelWidth,
@@ -101,7 +105,7 @@ async function localDetect(imageData) {
let boxes_data = [] let boxes_data = []
let scores_data = [] let scores_data = []
let classes_data = [] let classes_data = []
for (var c = 0; c < outputSize - 4; c++) { for (let c = 0; c < outputSize - 4; c++) {
structureScores = rawScores.map(x => x[c]) structureScores = rawScores.map(x => x[c])
tScores = tf.tensor1d(structureScores) tScores = tf.tensor1d(structureScores)
resBoxes = await tf.image.nonMaxSuppressionAsync(tBoxes,tScores,10,0.5,.05) resBoxes = await tf.image.nonMaxSuppressionAsync(tBoxes,tScores,10,0.5,.05)
@@ -109,7 +113,7 @@ async function localDetect(imageData) {
tf.dispose(resBoxes) tf.dispose(resBoxes)
if (validBoxes) { if (validBoxes) {
boxes_data.push(...rawBoxes.filter( (_, idx) => validBoxes.includes(idx))) boxes_data.push(...rawBoxes.filter( (_, idx) => validBoxes.includes(idx)))
var outputScores = structureScores.filter( (_, idx) => validBoxes.includes(idx)) let outputScores = structureScores.filter( (_, idx) => validBoxes.includes(idx))
scores_data.push(...outputScores) scores_data.push(...outputScores)
classes_data.push(...outputScores.fill(c)) classes_data.push(...outputScores.fill(c))
} }
@@ -120,11 +124,8 @@ async function localDetect(imageData) {
tf.dispose(tScores) tf.dispose(tScores)
tf.dispose(tRes) tf.dispose(tRes)
const valid_detections_data = classes_data.length const valid_detections_data = classes_data.length
var output = { for (let i =0; i < valid_detections_data; i++) {
detections: [] let [dLeft, dTop, dRight, dBottom] = boxes_data[i]
}
for (var i =0; i < valid_detections_data; i++) {
var [dLeft, dTop, dRight, dBottom] = boxes_data[i]
output.detections.push({ output.detections.push({
"top": dTop, "top": dTop,
"left": dLeft, "left": dLeft,
@@ -155,7 +156,7 @@ async function videoFrame (vidData) {
const rawRes = tf.transpose(res,[0,2,1]).arraySync()[0] const rawRes = tf.transpose(res,[0,2,1]).arraySync()[0]
if (rawRes) { if (rawRes) {
for (var i = 0; i < rawRes.length; i++) { for (let i = 0; i < rawRes.length; i++) {
let getScores = rawRes[i].slice(4) let getScores = rawRes[i].slice(4)
if (getScores.some( s => s > .5)) { if (getScores.some( s => s > .5)) {
let foundTarget = rawRes[i].slice(0,2) let foundTarget = rawRes[i].slice(0,2)

View File

@@ -58,7 +58,7 @@ export default {
}) })
if (eVid.data.coords) { if (eVid.data.coords) {
imageCtx.clearRect(0,0,imCanvas.width,imCanvas.height) imageCtx.clearRect(0,0,imCanvas.width,imCanvas.height)
for (var coord of eVid.data.coords) { for (let coord of eVid.data.coords) {
let pointX = (imCanvas.width - imgWidth) / 2 + (coord[0] / eVid.data.modelWidth) * imgWidth - 10 let pointX = (imCanvas.width - imgWidth) / 2 + (coord[0] / eVid.data.modelWidth) * imgWidth - 10
let pointY = (imCanvas.height - imgHeight) / 2 + (coord[1] / eVid.data.modelHeight) * imgHeight - 10 let pointY = (imCanvas.height - imgHeight) / 2 + (coord[1] / eVid.data.modelHeight) * imgHeight - 10
console.debug(`cx: ${pointX}, cy: ${pointY}`) console.debug(`cx: ${pointX}, cy: ${pointY}`)
@@ -72,8 +72,7 @@ export default {
const imCanvas = this.$refs.image_cvs const imCanvas = this.$refs.image_cvs
const imageCtx = imCanvas.getContext("2d") const imageCtx = imCanvas.getContext("2d")
const target = this.$refs.target_image const target = this.$refs.target_image
var imgWidth let imgWidth, imgHeight
var imgHeight
f7.utils.nextFrame(() => { f7.utils.nextFrame(() => {
imCanvas.width = imCanvas.clientWidth imCanvas.width = imCanvas.clientWidth
imCanvas.height = imCanvas.clientHeight imCanvas.height = imCanvas.clientHeight

View File

@@ -56,7 +56,7 @@
}, },
computed: { computed: {
commentText () { commentText () {
var text = f7.textEditor.get('.comment-editor').getValue() let text = f7.textEditor.get('.comment-editor').getValue()
if (this.userEmail) { if (this.userEmail) {
text += `\\n\\nSubmitted by: ${this.userEmail}` text += `\\n\\nSubmitted by: ${this.userEmail}`
} }
@@ -65,9 +65,9 @@
}, },
methods: { methods: {
sendFeedback () { sendFeedback () {
var self = this let self = this
var issueURL = `https://gitea.azgeorgis.net/api/v1/repos/Georgi_Lab/ALVINN_f7/issues?access_token=9af8ae15b1ee5a98afcb3083bb488e4cf3c683af` const issueURL = `https://gitea.azgeorgis.net/api/v1/repos/Georgi_Lab/ALVINN_f7/issues?access_token=9af8ae15b1ee5a98afcb3083bb488e4cf3c683af`
var xhr = new XMLHttpRequest() let xhr = new XMLHttpRequest()
xhr.open("POST", issueURL) xhr.open("POST", issueURL)
xhr.setRequestHeader('Content-Type', 'application/json') xhr.setRequestHeader('Content-Type', 'application/json')
xhr.setRequestHeader('accept', 'application/json') xhr.setRequestHeader('accept', 'application/json')

View File

@@ -227,7 +227,7 @@
classesList = classes classesList = classes
this.detectorLabels = classesList.map( l => { return {'name': l, 'detect': true} } ) this.detectorLabels = classesList.map( l => { return {'name': l, 'detect': true} } )
}) })
var loadServerSettings = localStorage.getItem('serverSettings') const loadServerSettings = localStorage.getItem('serverSettings')
if (loadServerSettings) serverSettings = JSON.parse(loadServerSettings) if (loadServerSettings) serverSettings = JSON.parse(loadServerSettings)
}, },
mounted () { mounted () {
@@ -284,7 +284,7 @@
} }
}, },
showResults () { showResults () {
var filteredResults = this.resultData.detections let filteredResults = this.resultData.detections
if (!filteredResults) return [] if (!filteredResults) return []
const allSelect = this.detectorLabels.every( s => { return s.detect } ) const allSelect = this.detectorLabels.every( s => { return s.detect } )
@@ -419,8 +419,8 @@
this.imageView.src = null this.imageView.src = null
this.$refs.image_cvs.style['background-image'] = 'none' this.$refs.image_cvs.style['background-image'] = 'none'
this.resultData = {} this.resultData = {}
var trackDetails = this.cameraStream.getVideoTracks()[0].getSettings() const trackDetails = this.cameraStream.getVideoTracks()[0].getSettings()
var vidElement = this.$refs.vid_viewer let vidElement = this.$refs.vid_viewer
vidElement.width = trackDetails.width vidElement.width = trackDetails.width
vidElement.height = trackDetails.height vidElement.height = trackDetails.height
if (!this.useWorkers) { if (!this.useWorkers) {
@@ -594,7 +594,7 @@
}) })
}, },
async submitData () { async submitData () {
var uploadData = this.showResults let uploadData = this.showResults
.filter( d => { return d.aboveThreshold && d.isSearched && !d.isDeleted }) .filter( d => { return d.aboveThreshold && d.isSearched && !d.isDeleted })
.map( r => { return {"top": r.top, "left": r.left, "bottom": r.bottom, "right": r.right, "label": r.label}}) .map( r => { return {"top": r.top, "left": r.left, "bottom": r.bottom, "right": r.right, "label": r.label}})
this.uploadUid = await this.uploadData(this.imageView.src.split(',')[1],uploadData,this.uploadUid) this.uploadUid = await this.uploadData(this.imageView.src.split(',')[1],uploadData,this.uploadUid)
@@ -622,7 +622,7 @@
let clickY = (e.offsetY - this.canvasOffset.y) / this.canvasZoom let clickY = (e.offsetY - this.canvasOffset.y) / this.canvasZoom
let boxEnd = boxCoords.splice(0, this.selectedChip) let boxEnd = boxCoords.splice(0, this.selectedChip)
boxCoords = boxCoords.concat(boxEnd) boxCoords = boxCoords.concat(boxEnd)
var findBox = boxCoords.findIndex( (r, i) => { const findBox = boxCoords.findIndex( (r, i) => {
let di = loopIndex(i) let di = loopIndex(i)
if (di == this.selectedChip ) return false if (di == this.selectedChip ) return false
return r.left <= clickX && return r.left <= clickX &&

View File

@@ -46,11 +46,11 @@ export default {
let rawBoxes = [] let rawBoxes = []
let rawScores = [] let rawScores = []
for (var i = 0; i < rawRes.length; i++) { for (let i = 0; i < rawRes.length; i++) {
var getScores = rawRes[i].slice(4) const getScores = rawRes[i].slice(4)
if (getScores.every( s => s < .05)) { continue } if (getScores.every( s => s < .05)) { continue }
var getBox = rawRes[i].slice(0,4) const getBox = rawRes[i].slice(0,4)
var boxCalc = [ const boxCalc = [
(getBox[0] - (getBox[2] / 2)) / modelWidth, (getBox[0] - (getBox[2] / 2)) / modelWidth,
(getBox[1] - (getBox[3] / 2)) / modelHeight, (getBox[1] - (getBox[3] / 2)) / modelHeight,
(getBox[0] + (getBox[2] / 2)) / modelWidth, (getBox[0] + (getBox[2] / 2)) / modelWidth,
@@ -69,7 +69,7 @@ export default {
let boxes_data = [] let boxes_data = []
let scores_data = [] let scores_data = []
let classes_data = [] let classes_data = []
for (var c = 0; c < outputSize - 4; c++) { for (let c = 0; c < outputSize - 4; c++) {
structureScores = rawScores.map(x => x[c]) structureScores = rawScores.map(x => x[c])
tScores = tf.tensor1d(structureScores) tScores = tf.tensor1d(structureScores)
resBoxes = await tf.image.nonMaxSuppressionAsync(tBoxes,tScores,10,0.5,.05) resBoxes = await tf.image.nonMaxSuppressionAsync(tBoxes,tScores,10,0.5,.05)
@@ -77,7 +77,7 @@ export default {
tf.dispose(resBoxes) tf.dispose(resBoxes)
if (validBoxes) { if (validBoxes) {
boxes_data.push(...rawBoxes.filter( (_, idx) => validBoxes.includes(idx))) boxes_data.push(...rawBoxes.filter( (_, idx) => validBoxes.includes(idx)))
var outputScores = structureScores.filter( (_, idx) => validBoxes.includes(idx)) let outputScores = structureScores.filter( (_, idx) => validBoxes.includes(idx))
scores_data.push(...outputScores) scores_data.push(...outputScores)
classes_data.push(...outputScores.fill(c)) classes_data.push(...outputScores.fill(c))
} }
@@ -88,11 +88,11 @@ export default {
tf.dispose(tScores) tf.dispose(tScores)
tf.dispose(tRes) tf.dispose(tRes)
const valid_detections_data = classes_data.length const valid_detections_data = classes_data.length
var output = { const output = {
detections: [] detections: []
} }
for (var i =0; i < valid_detections_data; i++) { for (let i =0; i < valid_detections_data; i++) {
var [dLeft, dTop, dRight, dBottom] = boxes_data[i] const [dLeft, dTop, dRight, dBottom] = boxes_data[i]
output.detections.push({ output.detections.push({
"top": dTop, "top": dTop,
"left": dLeft, "left": dLeft,
@@ -110,9 +110,9 @@ export default {
return output || { detections: [] } return output || { detections: [] }
}, },
getRemoteLabels() { getRemoteLabels() {
var self = this let self = this
var modelURL = `http://${this.serverSettings.address}:${this.serverSettings.port}/detectors` const modelURL = `http://${this.serverSettings.address}:${this.serverSettings.port}/detectors`
var xhr = new XMLHttpRequest() let xhr = new XMLHttpRequest()
xhr.open("GET", modelURL) xhr.open("GET", modelURL)
xhr.setRequestHeader('Content-Type', 'application/json') xhr.setRequestHeader('Content-Type', 'application/json')
xhr.timeout = 10000 xhr.timeout = 10000
@@ -124,8 +124,8 @@ export default {
f7.dialog.alert(`ALVINN has encountered an error: ${errorResponse.error}`) f7.dialog.alert(`ALVINN has encountered an error: ${errorResponse.error}`)
return return
} }
var detectors = JSON.parse(xhr.response).detectors const detectors = JSON.parse(xhr.response).detectors
var findLabel = detectors let findLabel = detectors
.find( d => { return d.name == self.detectorName } )?.labels .find( d => { return d.name == self.detectorName } )?.labels
.filter( l => { return l != "" } ).sort() .filter( l => { return l != "" } ).sort()
.map( l => { return {'name': l, 'detect': true} } ) .map( l => { return {'name': l, 'detect': true} } )
@@ -139,9 +139,9 @@ export default {
xhr.send() xhr.send()
}, },
remoteDetect() { remoteDetect() {
var self = this let self = this
var modelURL = `http://${this.serverSettings.address}:${this.serverSettings.port}/detect` const modelURL = `http://${this.serverSettings.address}:${this.serverSettings.port}/detect`
var xhr = new XMLHttpRequest() let xhr = new XMLHttpRequest()
xhr.open("POST", modelURL) xhr.open("POST", modelURL)
xhr.timeout = 10000 xhr.timeout = 10000
xhr.ontimeout = this.remoteTimeout xhr.ontimeout = this.remoteTimeout
@@ -158,7 +158,7 @@ export default {
self.uploadDirty = true self.uploadDirty = true
} }
var doodsData = { const doodsData = {
"detector_name": this.detectorName, "detector_name": this.detectorName,
"detect": { "detect": {
"*": 1 "*": 1
@@ -182,8 +182,7 @@ export default {
imCanvas.width = imCanvas.clientWidth imCanvas.width = imCanvas.clientWidth
imCanvas.height = imCanvas.clientHeight imCanvas.height = imCanvas.clientHeight
imageCtx.clearRect(0,0,imCanvas.width,imCanvas.height) imageCtx.clearRect(0,0,imCanvas.width,imCanvas.height)
var imgWidth let imgWidth, imgHeight
var imgHeight
const imgAspect = vidData.width / vidData.height const imgAspect = vidData.width / vidData.height
const rendAspect = imCanvas.width / imCanvas.height const rendAspect = imCanvas.width / imCanvas.height
if (imgAspect >= rendAspect) { if (imgAspect >= rendAspect) {
@@ -204,7 +203,7 @@ export default {
let rawCoords = [] let rawCoords = []
if (rawRes) { if (rawRes) {
for (var i = 0; i < rawRes.length; i++) { for (let i = 0; i < rawRes.length; i++) {
let getScores = rawRes[i].slice(4) let getScores = rawRes[i].slice(4)
if (getScores.some( s => s > .5)) { if (getScores.some( s => s > .5)) {
let foundTarget = rawRes[i].slice(0,2) let foundTarget = rawRes[i].slice(0,2)
@@ -214,7 +213,7 @@ export default {
} }
imageCtx.clearRect(0,0,imCanvas.width,imCanvas.height) imageCtx.clearRect(0,0,imCanvas.width,imCanvas.height)
for (var coord of rawCoords) { for (let coord of rawCoords) {
console.log(`x: ${coord[0]}, y: ${coord[1]}`) console.log(`x: ${coord[0]}, y: ${coord[1]}`)
let pointX = (imCanvas.width - imgWidth) / 2 + (coord[0] / modelWidth) * imgWidth -5 let pointX = (imCanvas.width - imgWidth) / 2 + (coord[0] / modelWidth) * imgWidth -5
let pointY = (imCanvas.height - imgHeight) / 2 + (coord[1] / modelHeight) * imgHeight -5 let pointY = (imCanvas.height - imgHeight) / 2 + (coord[1] / modelHeight) * imgHeight -5

View File

@@ -91,7 +91,7 @@
computed: { computed: {
otherIp () { otherIp () {
let filteredIps = {} let filteredIps = {}
for (var oldIp in this.serverSettings.previous) { for (let oldIp in this.serverSettings.previous) {
if (oldIp != this.serverSettings.address) { if (oldIp != this.serverSettings.address) {
filteredIps[oldIp] = this.serverSettings.previous[oldIp] filteredIps[oldIp] = this.serverSettings.previous[oldIp]
} }
@@ -109,12 +109,12 @@
} }
}, },
created () { created () {
var loadServerSettings = localStorage.getItem('serverSettings') const loadServerSettings = localStorage.getItem('serverSettings')
if (loadServerSettings) this.serverSettings = JSON.parse(loadServerSettings) if (loadServerSettings) this.serverSettings = JSON.parse(loadServerSettings)
if (!this.serverSettings.previous) this.serverSettings.previous = {} if (!this.serverSettings.previous) this.serverSettings.previous = {}
var loadThemeSettings = localStorage.getItem('themeSettings') const loadThemeSettings = localStorage.getItem('themeSettings')
if (loadThemeSettings) this.themeSettings = JSON.parse(loadThemeSettings) if (loadThemeSettings) this.themeSettings = JSON.parse(loadThemeSettings)
var loadOtherSettings = localStorage.getItem('otherSettings') const loadOtherSettings = localStorage.getItem('otherSettings')
if (loadOtherSettings) this.otherSettings = JSON.parse(loadOtherSettings) if (loadOtherSettings) this.otherSettings = JSON.parse(loadOtherSettings)
}, },
methods: { methods: {
@@ -136,7 +136,7 @@
) )
saveSetting.then( saveSetting.then(
() => { () => {
var toast = f7.toast.create({ const toast = f7.toast.create({
text: 'Settings saved', text: 'Settings saved',
closeTimeout: 2000 closeTimeout: 2000
}) })
@@ -144,7 +144,7 @@
this.isDirty = false; this.isDirty = false;
}, },
() => { () => {
var toast = f7.toast.create({ const toast = f7.toast.create({
text: 'ERROR: No settings saved', text: 'ERROR: No settings saved',
closeTimeout: 2000 closeTimeout: 2000
}) })

View File

@@ -63,7 +63,7 @@
return store() return store()
}, },
created () { created () {
var loadOtherSettings = localStorage.getItem('otherSettings') const loadOtherSettings = localStorage.getItem('otherSettings')
if (loadOtherSettings) this.otherSettings = JSON.parse(loadOtherSettings) if (loadOtherSettings) this.otherSettings = JSON.parse(loadOtherSettings)
fetch(`${this.isCordova ? 'https://localhost' : '.'}/models/thorax/descript.json`) fetch(`${this.isCordova ? 'https://localhost' : '.'}/models/thorax/descript.json`)
.then((mod) => { return mod.json() }) .then((mod) => { return mod.json() })

View File

@@ -5,8 +5,8 @@ export default {
newUid (length) { newUid (length) {
const uidLength = length || 16 const uidLength = length || 16
const uidChars = 'abcdefghijklmnopqrstuvwxyz0123456789' const uidChars = 'abcdefghijklmnopqrstuvwxyz0123456789'
var uid = [] let uid = []
for (var i = 0; i < uidLength; i++) { for (let i = 0; i < uidLength; i++) {
uid.push(uidChars.charAt(Math.floor(Math.random() * ((i < 4) ? 26 : 36)))) uid.push(uidChars.charAt(Math.floor(Math.random() * ((i < 4) ? 26 : 36))))
} }
return uid.join('') return uid.join('')
@@ -14,24 +14,23 @@ export default {
uploadData (imagePayload, classPayload, prevUid) { uploadData (imagePayload, classPayload, prevUid) {
let uploadImage = new Promise (resolve => { let uploadImage = new Promise (resolve => {
const dataUid = prevUid || this.newUid(16) const dataUid = prevUid || this.newUid(16)
var byteChars = window.atob(imagePayload) let byteChars = window.atob(imagePayload)
var byteArrays = [] let byteArrays = []
var len = byteChars.length
for (var offset = 0; offset < len; offset += 1024) { for (let offset = 0; offset < byteChars.length; offset += 1024) {
var slice = byteChars.slice(offset, offset + 1024) let slice = byteChars.slice(offset, offset + 1024)
var byteNumbers = new Array(slice.length) let byteNumbers = new Array(slice.length)
for (var i = 0; i < slice.length; i++) { for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i) byteNumbers[i] = slice.charCodeAt(i)
} }
var byteArray = new Uint8Array(byteNumbers) let byteArray = new Uint8Array(byteNumbers)
byteArrays.push(byteArray) byteArrays.push(byteArray)
} }
var imageBlob = new Blob(byteArrays, {type: 'image/jpeg'}) const imageBlob = new Blob(byteArrays, {type: 'image/jpeg'})
var xhrJpg = new XMLHttpRequest() let xhrJpg = new XMLHttpRequest()
var uploadUrl = `https://nextcloud.azgeorgis.net/public.php/webdav/${dataUid}.jpeg` let uploadUrl = `https://nextcloud.azgeorgis.net/public.php/webdav/${dataUid}.jpeg`
xhrJpg.open("PUT", uploadUrl) xhrJpg.open("PUT", uploadUrl)
xhrJpg.setRequestHeader('Content-Type', 'image/jpeg') xhrJpg.setRequestHeader('Content-Type', 'image/jpeg')
xhrJpg.setRequestHeader('X-Method-Override', 'PUT') xhrJpg.setRequestHeader('X-Method-Override', 'PUT')
@@ -39,8 +38,8 @@ export default {
xhrJpg.setRequestHeader("Authorization", "Basic " + btoa("LKBm3H6JdSaywyg:")) xhrJpg.setRequestHeader("Authorization", "Basic " + btoa("LKBm3H6JdSaywyg:"))
xhrJpg.send(imageBlob) xhrJpg.send(imageBlob)
var xhrTxt = new XMLHttpRequest() let xhrTxt = new XMLHttpRequest()
var uploadUrl = `https://nextcloud.azgeorgis.net/public.php/webdav/${dataUid}.txt` uploadUrl = `https://nextcloud.azgeorgis.net/public.php/webdav/${dataUid}.txt`
xhrTxt.open("PUT", uploadUrl) xhrTxt.open("PUT", uploadUrl)
xhrTxt.setRequestHeader('Content-Type', 'text/plain') xhrTxt.setRequestHeader('Content-Type', 'text/plain')
xhrTxt.setRequestHeader('X-Method-Override', 'PUT') xhrTxt.setRequestHeader('X-Method-Override', 'PUT')
@@ -51,7 +50,7 @@ export default {
resolve(dataUid) resolve(dataUid)
}) })
return uploadImage.then((newUid) => { return uploadImage.then((newUid) => {
var toast = f7.toast.create({ const toast = f7.toast.create({
text: 'Detections Uploaded: thank you.', text: 'Detections Uploaded: thank you.',
closeTimeout: 2000 closeTimeout: 2000
}) })