Skip to content
Snippets Groups Projects
Commit a7d59498 authored by Marek Trtik's avatar Marek Trtik
Browse files

Allow to add stick in the ImageDialog.

parent 9a54138a
No related branches found
No related tags found
No related merge requests found
......@@ -61,7 +61,7 @@
@keyup.right="deselectLabel"
>
</dropdown>
<plus-box-icon class="icon" />
<plus-box-icon class="icon" @click="onAddStick" />
<div>Add stake {{ selectLabel.name }}</div>
<undo-icon class="icon" @click="onRevertChangeToSticks" />
<div>
......@@ -116,6 +116,8 @@ import EyeOffIcon from 'icons/EyeOff'
import PlusBoxIcon from 'icons/PlusBox'
import UndoIcon from 'icons/Undo'
import DatasetService from '@/services/DatasetService'
export default {
name: 'ImageDialog',
components: {
......@@ -166,6 +168,52 @@ export default {
id: 0,
name: ''
}
},
onAddStick() {
const stickId = this.selectLabel.id
if (!this.$store.getters.stickIDs.includes(stickId.toString())) {
console.log("ImageDialog.onAddStick(): no stick selected => ignoring")
return
}
if (Object.hasOwnProperty.call(this.$store.getters.sticksByImageName(this.cameraID, this.imageName), stickId.toString())) {
DatasetService.multipostBegin()
this.$store.dispatch('setFlagStickVisible', {
cameraID: this.cameraID,
imageName: this.imageName,
stickID: stickId,
flagState: true
})
this.$store.dispatch('setFlagStickCorrectedByUser', {
cameraID: this.cameraID,
imageName: this.imageName,
stickID: stickId,
flagState: true
})
DatasetService.multipostEnd()
return
}
const stickName = this.selectLabel.name
let positionMean = this.$store.getters.getMeanStickPosition(stickId, this.cameraID)
if (positionMean == null) {
positionMean = {
top: [50,50],
bottom: [150, 150]
}
}
this.$store.dispatch('addStick', {
cameraID: this.cameraID,
imageName: this.imageName,
stickID: stickId,
stickData: {
"top": positionMean.top,
"bottom": positionMean.bottom,
"snowHeight": 0,
"visible": true,
"correctedByUser": true,
"discardedByUser": false,
"createdByUser": true
}
})
}
},
computed: {
......
......@@ -89,6 +89,9 @@ export default {
setFlagStickVisible(cameraID, imageName, stickID, flagState) {
return this.xpost("/db/data/@" + cameraID + "/" + imageName + "/sticks/" + stickID + "/visible", flagState)
},
addStick(cameraID, imageName, stickID, stickData) {
return this.xpost("/db/data/@" + cameraID + "/" + imageName + "/sticks/" + stickID, stickData)
},
multipostBegin() {
useMultipost = true;
return Promise.resolve('Success')
......
......@@ -110,6 +110,7 @@ export default {
dispatch('updateSnowHeightAverage', { cameraID, imageName, stickID })
}
}
dispatch('computePositionMeanOfSticks', cameraID)
})
},
buildImageChronology({ commit, state }, cameraID) {
......@@ -129,6 +130,42 @@ export default {
}
commit('SET_IMAGE_CHRONOLOGY', { cameraID, chronology })
},
computePositionMeanOfSticks({ commit, state }, cameraID) {
const counts = {}
const positionMeans = {}
for (const [imageName, imageProps] of Object.entries(state.data[cameraID])) {
if (imageProps.weatherConditions != 1)
continue;
for (const [stickId, stickInfo] of Object.entries(imageProps.sticks)) {
if (!stickInfo.visible || stickInfo.discardedByUser)
continue
if (!Object.hasOwnProperty.call(positionMeans, stickId))
positionMeans[stickId] = {}
if (!Object.hasOwnProperty.call(positionMeans[stickId], cameraID))
positionMeans[stickId][cameraID] = {}
const cameraPositionMeans = positionMeans[stickId][cameraID]
if (!Object.hasOwnProperty.call(cameraPositionMeans, 'top')) {
cameraPositionMeans['top'] = [0, 0]
cameraPositionMeans['bottom'] = [0, 0]
}
cameraPositionMeans['top'][0] += stickInfo.top[0]
cameraPositionMeans['top'][1] += stickInfo.top[1]
cameraPositionMeans['bottom'][0] += stickInfo.bottom[0]
cameraPositionMeans['bottom'][1] += stickInfo.bottom[1]
if (!Object.hasOwnProperty.call(counts, stickId))
counts[stickId] = 1
else
++counts[stickId]
}
}
for (const [stickId, count] of Object.entries(counts)) {
positionMeans[stickId][cameraID]['top'][0] /= count
positionMeans[stickId][cameraID]['top'][1] /= count
positionMeans[stickId][cameraID]['bottom'][0] /= count
positionMeans[stickId][cameraID]['bottom'][1] /= count
commit('SET_STICK_MEAN_POSITION', { stickId, cameraID, meanPosition: positionMeans[stickId][cameraID] })
}
},
updateSnowHeightAverage({ commit, state }, { cameraID, imageName, stickID }) {
// If the stick is not visible, but there was snow in the picture, don't trust the average and therefore don't measure it.
......@@ -481,5 +518,30 @@ export default {
commit('SET_PENDING_CHANGES', { value })
})
})
},
addStick({ commit, state }, { cameraID, imageName, stickID, stickData }) {
if (Object.hasOwnProperty.call(state.data[cameraID][imageName].sticks, stickID)) {
console.error("store.addStick(): ERROR: passed stick already exists => insertion has FAILED.")
return
}
if (!Object.hasOwnProperty.call(stickData, 'top') ||
!Object.hasOwnProperty.call(stickData, 'bottom') ||
!Object.hasOwnProperty.call(stickData, 'snowHeight') ||
!Object.hasOwnProperty.call(stickData, 'visible') ||
!Object.hasOwnProperty.call(stickData, 'correctedByUser') ||
!Object.hasOwnProperty.call(stickData, 'discardedByUser') ||
!Object.hasOwnProperty.call(stickData, 'createdByUser')) {
console.error("store.addStick(): ERROR: passed stick data are wrong => insertion has FAILED.")
return
}
const webCmd = () =>
DatasetService.addStick(cameraID, imageName, stickID, stickData)
commit('ADD_STICK', {
cameraID,
imageName,
stickID,
stickData,
webCmd
})
}
}
......@@ -232,5 +232,12 @@ export default {
getSnowHightAverage: state => (cameraID, imageName, stickID) => {
// In hours
return state.data[cameraID][imageName].sticks[stickID].snowHeightAverage
},
getMeanStickPosition: state => (stickId, cameraID) => {
try {
return state.sticks[stickId].positionMean[cameraID]
} catch (err) {
return null
}
}
}
......@@ -15,6 +15,12 @@ export default new Vuex.Store({
//Format: stickID: {
// x: number,
// y: number,
// positionMean: {
// cameraID: {
// top: [number, number],
// bottom: [number, number],
// }
//}
// statusGUI: 'full' | 'compact' | 'minimized',
// lengthCm: number,
// labels: {cameraID: 'label', cameraID: 'label'},
......
......@@ -32,6 +32,12 @@ export default {
SET_ACTIVE_POINT(state, { stickID, cameraID, imageNames }) {
Vue.set(state, 'activePoint', { stickID, cameraID, imageNames })
},
SET_STICK_MEAN_POSITION(state, { stickId, cameraID, meanPosition }) {
const stickInfo = state.sticks[stickId]
if (!Object.hasOwnProperty.call('positionMean'))
stickInfo['positionMean'] = {}
stickInfo.positionMean[cameraID] = meanPosition
},
SET_IMAGE_DATE_TIME(state, { cameraID, imageName, dateTimeString, webCmd }) {
_sendPostRequest(state, webCmd)
state.data[cameraID][imageName].dateTime = dateTimeString
......@@ -170,5 +176,9 @@ export default {
},
SET_PENDING_CHANGES(state, { value }) {
state.server.hasPendingChanges = value
},
addStick(state, { cameraID, imageName, stickID, stickData, webCmd }) {
_sendPostRequest(state, webCmd)
state.data[cameraID][imageName].sticks[stickID] = stickData
}
}
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