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 <peterlu810516@gmail.com>
This commit is contained in:
peterlu14
2024-01-23 15:48:22 +08:00
parent 4f13ea68e7
commit 1d6d8aef19
3 changed files with 58 additions and 29 deletions
+18 -11
View File
@@ -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
+18 -10
View File
@@ -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
+22 -8
View File
@@ -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)
}