From 1d6d8aef19ce1c3f464ac74fa6b7ae2dfaeeea2e Mon Sep 17 00:00:00 2001 From: peterlu14 Date: Tue, 23 Jan 2024 15:48:22 +0800 Subject: [PATCH] refactor: refactor data handling, parsing, and comparison methods - Change the way to handle downloaded data, by adding 'bytea_data' to the attributes fetched and going through byte data instead of regular data - Add a 'parseByteData' method to replace the previous 'parseRawData' method - Ensure data normalization by parsing the downloaded data into integers - The change applies to both online and offline downloading - Minor update in timestamp comparison operation, with data parsed to integer before being compared. Signed-off-by: peterlu14 --- src/components/download/Download.vue | 29 ++++++++++++-------- src/components/download/DownloadOffline.vue | 28 ++++++++++++------- src/data/download/Download.js | 30 +++++++++++++++------ 3 files changed, 58 insertions(+), 29 deletions(-) diff --git a/src/components/download/Download.vue b/src/components/download/Download.vue index 55e35bdf..cae19eee 100644 --- a/src/components/download/Download.vue +++ b/src/components/download/Download.vue @@ -175,7 +175,7 @@ export default { // const rawID = this.downloadInfo.channelInfo[channel].downloadIDList[_idx][rowIndex] const rawIDList = this.downloadInfo.channelInfo[channel].downloadIDList[_idx].slice(rowIndex, rowIndex + 10) // console.log(channel, rawIDList) - rawIDList.length > 0 && requestArray.push(api.raw.getAttrByIDs(channel, rawIDList, 'id-channel-size-serial_number-start_time-end_time-data')) + rawIDList.length > 0 && requestArray.push(api.raw.getAttrByIDs(channel, rawIDList, 'id-channel-size-serial_number-start_time-end_time-data-bytea_data')) if (rawIDList.length === 0) columnNum -= 1 } } @@ -189,17 +189,24 @@ export default { const timeUnitScale = channelParamObj.time.unit[channelParamObj.time.downloadUnit] const channelUnitScale = channelParamObj[data.channel]?.unit[channelParamObj[data.channel]?.downloadUnit] // console.log('data', data) - const dataArray = data.data.split('"***"').slice(0, -1) - // console.log('dataArray', dataArray) - for (const raw of dataArray) { - const rawArray = raw.split(' ') - const newArray = rawArray[0] === '' ? [] : rawArray.map((ele, index) => { - // console.log((parseInt(ele) / timeUnitScale).toFixed(Math.log10(timeUnitScale))) - return (index % 2 === 0) ? String((parseInt(ele) / timeUnitScale).toFixed(Math.log10(timeUnitScale))) : channelUnitScale ? String((parseInt(ele) / channelUnitScale).toFixed(Math.log10(channelUnitScale))) : ele - }) - this.downloadInfo.channelInfo[data.channel].downloadDataBuffer[idx].push(...newArray) - // console.log('rawArray', rawArray) + const bytesData = new Int8Array(data.bytea_data.data) + // console.log('bytesData', bytesData) + const integers = [] + for (let i = 0; i < bytesData.length; i += 8) { + // Create a DataView for each 8-byte chunk + const view = new DataView(bytesData.buffer, i, 8) + // Read the integer as BigInt (assuming little-endian byte order) + const integer = view.getBigInt64(0) + integers.push(integer) } + const newArray = integers.map((ele, index) => { + return (index % 2 === 0) + ? String((parseInt(ele) / timeUnitScale).toFixed(Math.log10(timeUnitScale))) + : channelUnitScale ? String((parseInt(ele) / channelUnitScale).toFixed(Math.log10(channelUnitScale))) : ele + }) + this.downloadInfo.channelInfo[data.channel].downloadDataBuffer[idx].push(...newArray) + // // console.log('rawArray', rawArray) + // } } } requestArray.length = 0 diff --git a/src/components/download/DownloadOffline.vue b/src/components/download/DownloadOffline.vue index c2acfc3c..55c599db 100644 --- a/src/components/download/DownloadOffline.vue +++ b/src/components/download/DownloadOffline.vue @@ -174,7 +174,7 @@ export default { // const rawID = this.downloadInfo.channelInfo[channel].downloadIDList[_idx][rowIndex] const rawIDList = this.downloadInfo.channelInfo[channel].downloadIDList[_idx].slice(rowIndex, rowIndex + 10) // console.log(channel, rawIDList) - rawIDList.length > 0 && requestArray.push(api.raw.getAttrByIDs(channel, rawIDList, 'id-channel-size-serial_number-start_time-end_time-data')) + rawIDList.length > 0 && requestArray.push(api.raw.getAttrByIDs(channel, rawIDList, 'id-channel-size-serial_number-start_time-end_time-data-bytea_data')) if (rawIDList.length === 0) columnNum -= 1 } } @@ -189,16 +189,24 @@ export default { const timeUnitScale = channelParamObj.time.unit[channelParamObj.time.downloadUnit] const channelUnitScale = channelParamObj[data.channel]?.unit[channelParamObj[data.channel]?.downloadUnit] // console.log('data', data) - const dataArray = data.data.split('"***"').slice(0, -1) - // console.log('dataArray', dataArray) - for (const raw of dataArray) { - const rawArray = raw.split(' ') - const newArray = rawArray[0] === '' ? [] : rawArray.map((ele, index) => { - return (index % 2 === 0) ? String((parseInt(ele) / timeUnitScale).toFixed(Math.log10(timeUnitScale))) : channelUnitScale ? String((parseInt(ele) / channelUnitScale).toFixed(Math.log10(channelUnitScale))) : ele - }) - this.downloadInfo.channelInfo[data.channel].downloadDataBuffer[idx].push(...newArray) - // console.log('rawArray', rawArray) + const bytesData = new Int8Array(data.bytea_data.data) + // console.log('bytesData', bytesData) + const integers = [] + for (let i = 0; i < bytesData.length; i += 8) { + // Create a DataView for each 8-byte chunk + const view = new DataView(bytesData.buffer, i, 8) + // Read the integer as BigInt (assuming little-endian byte order) + const integer = view.getBigInt64(0) + integers.push(integer) } + const newArray = integers.map((ele, index) => { + return (index % 2 === 0) + ? String((parseInt(ele) / timeUnitScale).toFixed(Math.log10(timeUnitScale))) + : channelUnitScale ? String((parseInt(ele) / channelUnitScale).toFixed(Math.log10(channelUnitScale))) : ele + }) + this.downloadInfo.channelInfo[data.channel].downloadDataBuffer[idx].push(...newArray) + // // console.log('rawArray', rawArray) + // } } } requestArray.length = 0 diff --git a/src/data/download/Download.js b/src/data/download/Download.js index f5efc2ca..cbb4cf7c 100644 --- a/src/data/download/Download.js +++ b/src/data/download/Download.js @@ -48,11 +48,11 @@ export const download = { while (rawDataIDList.length >= 1000) { const _rawDataIDList = rawDataIDList.splice(0, 1000) - const _data = await api.raw.getAttrByIDs(channelID, _rawDataIDList, 'id-channel-size-serial_number-start_time-end_time-data') - prevLastTime = await this.parseRawData(_data.data, prevLastTime, meta, result[channelID]) + const _data = await api.raw.getAttrByIDs(channelID, _rawDataIDList, 'id-channel-size-serial_number-start_time-end_time-data-bytea_data') + prevLastTime = await this.parseByteData(_data.data, prevLastTime, meta, result[channelID]) } - const _data = await api.raw.getAttrByIDs(channelID, rawDataIDList, 'id-channel-size-serial_number-start_time-end_time-data') - prevLastTime = await this.parseRawData(_data.data, prevLastTime, meta, result[channelID]) + const _data = await api.raw.getAttrByIDs(channelID, rawDataIDList, 'id-channel-size-serial_number-start_time-end_time-data-bytea_data') + prevLastTime = await this.parseByteData(_data.data, prevLastTime, meta, result[channelID]) } return result }, @@ -62,8 +62,8 @@ export const download = { result[channelID] = [] const prevLastTime = 0 - const _data = await api.raw.getAttrByIDs(channelID, list, 'id-channel-size-serial_number-start_time-end_time-data') - await this.parseRawData(_data.data, prevLastTime, meta, result[channelID]) + const _data = await api.raw.getAttrByIDs(channelID, list, 'id-channel-size-serial_number-start_time-end_time-data-bytea_data') + await this.parseByteData(_data.data, prevLastTime, meta, result[channelID]) return result }, getMiniExistOrNotByID: async function (id, channel) { @@ -73,7 +73,7 @@ export const download = { rawByIDChannels: async function (id, channel, meta) { const data = [] const rawData = await api.raw.getByID(channel, id) - await this.parseRawData(rawData.data, null, meta, data) + await this.parseByteData(rawData.data, null, meta, data) return data }, rawSdDataByIDChannels: async function (id, channel, meta) { @@ -90,6 +90,20 @@ export const download = { const rawData = await api.mini.getByID(channel, id) return await this.parseMiniData(rawData, 'data_random', meta) }, + parseByteData: async function (rawData, prevLastTime, meta, dataArray) { + for (const raw of rawData) { + const bytesData = new Int8Array(raw.bytea_data.data) + const integers = [] + for (let i = 0; i < bytesData.length; i += 8) { + // Create a DataView for each 8-byte chunk + const view = new DataView(bytesData.buffer, i, 8) + // Read the integer as BigInt (assuming little-endian byte order) + const integer = view.getBigInt64(0) + integers.push(integer) + } + prevLastTime = this.parseDataWithTimeStamp(integers, prevLastTime, meta, dataArray) + } + }, parseRawData: async function (rawData, prevLastTime, meta, dataArray) { for (const raw of rawData) { if (raw.data !== null && raw.data.length > 0) { @@ -188,7 +202,7 @@ export const download = { if (meta !== undefined) { if (time <= parseInt(meta.time_duration)) { - const data = currentData[i + 1] + const data = parseInt(currentData[i + 1]) const tmpData = [time, data] dataArray.push(tmpData) }