fix: issue with tempchart/temphistory if the browser go into sleep mode
Signed-off-by: Stefan Dej <meteyou@gmail.com>
This commit is contained in:
5 files changed
+49
-11
No files matched your search
@@ -14,7 +14,7 @@ import { convertName } from '@/plugins/helpers'
|
||||
import Component from 'vue-class-component'
|
||||
import {Mixins, Watch} from 'vue-property-decorator'
|
||||
import BaseMixin from '../mixins/base'
|
||||
import {PrinterTempHistoryStateSerie} from '@/store/printer/tempHistory/types'
|
||||
import {PrinterTempHistoryStateSerie, PrinterTempHistoryStateSourceEntry} from '@/store/printer/tempHistory/types'
|
||||
|
||||
import { createComponent } from 'echarts-for-vue'
|
||||
import * as echarts from 'echarts'
|
||||
@@ -243,15 +243,24 @@ export default class TempChart extends Mixins(BaseMixin) {
|
||||
updateChart() {
|
||||
if (this.chart && this.isVisible) {
|
||||
//const t0 = performance.now()
|
||||
const limitDate = new Date(Date.now() - this.maxHistory * 1000)
|
||||
let newSource = [...this.source].filter((entry: PrinterTempHistoryStateSourceEntry) => {
|
||||
return entry.date >= limitDate
|
||||
})
|
||||
|
||||
this.chart?.setOption({
|
||||
dataset: {
|
||||
source: this.source
|
||||
source: newSource
|
||||
},
|
||||
})
|
||||
|
||||
//const t1 = performance.now()
|
||||
//window.console.debug(t1-t0)
|
||||
//window.console.debug('calc chart', (t1-t0).toFixed(), newSource.length, this.source.length)
|
||||
|
||||
// reset tempHistory if working sources are smaller than 80%
|
||||
if (this.source.length > 0 && newSource.length < this.maxHistory * 0.8) {
|
||||
this.$socket.emit('server.temperature_store', {}, { action: 'printer/tempHistory/init' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,20 +15,24 @@ import {
|
||||
import {RootState} from '@/store/types'
|
||||
|
||||
export const actions: ActionTree<PrinterTempHistoryState, RootState> = {
|
||||
reset({ commit }) {
|
||||
reset({ commit, state }) {
|
||||
if (state.updateSourceInterval !== null)
|
||||
clearInterval(state.updateSourceInterval)
|
||||
|
||||
commit('reset')
|
||||
},
|
||||
|
||||
init({ commit, rootGetters, dispatch }, payload) {
|
||||
window.console.debug('init printer/tempHistory')
|
||||
commit('reset')
|
||||
|
||||
const now = new Date()
|
||||
const allSensors = rootGetters['printer/getAvailableSensors'] ?? []
|
||||
const maxHistory = rootGetters['server/getConfig']('server', 'temperature_store_size') || 1200
|
||||
|
||||
if ('requestParams' in payload) delete payload.requestParams
|
||||
|
||||
if (payload !== undefined) {
|
||||
if ('requestParams' in payload) delete payload.requestParams
|
||||
|
||||
const objectKeys = Object.keys(payload)
|
||||
// eslint-disable-next-line
|
||||
const importData: any = {}
|
||||
@@ -198,13 +202,20 @@ export const actions: ActionTree<PrinterTempHistoryState, RootState> = {
|
||||
|
||||
commit('setInitSeries', series)
|
||||
|
||||
setInterval(() => {
|
||||
const updateSourceInterval = setInterval(() => {
|
||||
dispatch('updateSource')
|
||||
}, datasetInterval)
|
||||
|
||||
commit('setUpdateSourceInterval', updateSourceInterval)
|
||||
}
|
||||
},
|
||||
|
||||
updateSource({ commit, rootState, rootGetters }) {
|
||||
async updateSource({ commit, rootState, rootGetters, state }) {
|
||||
/*if (state.timeLastUpdate !== null) {
|
||||
const t0 = performance.now()
|
||||
window.console.debug('update Source', t0-state.timeLastUpdate)
|
||||
}*/
|
||||
|
||||
if (rootState?.printer?.heaters?.available_sensors?.length) {
|
||||
const data: PrinterTempHistoryStateSourceEntry = {
|
||||
date: new Date()
|
||||
@@ -222,10 +233,12 @@ export const actions: ActionTree<PrinterTempHistoryState, RootState> = {
|
||||
}
|
||||
})
|
||||
|
||||
commit('addToSource', {
|
||||
await commit('addToSource', {
|
||||
data: data,
|
||||
maxHistory: rootGetters['server/getConfig']('server', 'temperature_store_size') || 1200
|
||||
})
|
||||
}
|
||||
|
||||
//commit('saveLastDate', performance.now())
|
||||
},
|
||||
}
|
||||
@@ -8,6 +8,8 @@ export const getDefaultState = (): PrinterTempHistoryState => {
|
||||
return {
|
||||
source: [],
|
||||
series: [],
|
||||
timeLastUpdate: null,
|
||||
updateSourceInterval: null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,20 @@ export const mutations: MutationTree<PrinterTempHistoryState> = {
|
||||
},
|
||||
|
||||
addToSource(state, payload) {
|
||||
state.source.push(payload.data)
|
||||
while (state.source.length > payload.maxHistory) state.source.splice(0, 1)
|
||||
const newSource = [...state.source]
|
||||
newSource.push(payload.data)
|
||||
while (newSource.length > payload.maxHistory) newSource.splice(0, 1)
|
||||
|
||||
Vue.set(state, 'source', newSource)
|
||||
},
|
||||
|
||||
// function for debugging tempchart update interval (browser sleep)
|
||||
saveLastDate(state, payload) {
|
||||
Vue.set(state, 'timeLastUpdate', payload)
|
||||
},
|
||||
|
||||
setUpdateSourceInterval(state, payload) {
|
||||
Vue.set(state, 'updateSourceInterval', payload)
|
||||
},
|
||||
|
||||
setColor(state, payload) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
export interface PrinterTempHistoryState {
|
||||
source: PrinterTempHistoryStateSourceEntry[]
|
||||
series: PrinterTempHistoryStateSerie[]
|
||||
timeLastUpdate: number | null
|
||||
updateSourceInterval: number | null
|
||||
}
|
||||
|
||||
export interface PrinterTempHistoryStateSerie {
|
||||
|
||||
Reference in new issue
Block a user