1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

add support for vectors of samples (closes #107)

This commit is contained in:
Steffen Vogel 2017-09-20 12:46:32 +02:00
parent 5a027a1af7
commit b6613ab0cd
2 changed files with 49 additions and 27 deletions

View file

@ -76,20 +76,19 @@ class SimulatorDataDataManager {
}
onMessage(event, node) {
var message = this.bufferToMessage(event.data);
var msgs = this.bufferToMessageArray(event.data);
if (message !== null) {
if (msgs.length > 0) {
AppDispatcher.dispatch({
type: 'simulatorData/data-changed',
data: message,
data: msgs,
node: node
});
}
}
bufferToMessage(blob) {
bufferToMessage(data) {
// parse incoming message into usable data
var data = new DataView(blob);
if (data.byteLength === 0) {
return null;
}
@ -97,11 +96,10 @@ class SimulatorDataDataManager {
let OFFSET_TYPE = 2;
let OFFSET_VERSION = 4;
var id = data.getUint8(1);
var bits = data.getUint8(0);
var length = data.getUint16(0x02, 1);
var id = data.getUint8(1);
var values = new Float32Array(data.buffer, data.byteOffset + 0x10, length);
var bytes = length * 4 + 16;
return {
version: (bits >> OFFSET_VERSION) & 0xF,
@ -109,10 +107,29 @@ class SimulatorDataDataManager {
length: length,
sequence: data.getUint32(0x04, 1),
timestamp: data.getUint32(0x08, 1) * 1e3 + data.getUint32(0x0C, 1) * 1e-6,
values: values,
values: new Float32Array(data.buffer, data.byteOffset + 0x10, length),
blob: new DataView( data.buffer, data.byteOffset + 0x00, bytes),
id: id
};
}
bufferToMessageArray(blob) {
/* some local variables for parsing */
var offset = 0;
var msgs = [];
/* for every msg in vector */
while (offset < blob.byteLength) {
var msg = this.bufferToMessage(new DataView(blob, offset));
if (msg !== undefined) {
msgs.push(msg);
offset += msg.blob.byteLength;
}
}
return msgs;
}
}
export default new SimulatorDataDataManager();

View file

@ -36,7 +36,7 @@ class SimulationDataStore extends ReduceStore {
}
reduce(state, action) {
var i;
var i, j;
switch (action.type) {
case 'simulatorData/open':
@ -59,29 +59,34 @@ class SimulationDataStore extends ReduceStore {
return state;
}
let index = action.node.simulators.findIndex(simulator => simulator.id === action.data.id);
if (index === -1 || state[action.node._id][index] == null) {
return state;
}
// loop over all samples in a vector
for (j = 0; j < action.data.length; j++) {
let smp = action.data[j];
// add data to simulator
for (i = 0; i < action.data.length; i++) {
while (state[action.node._id][index].values.length < i + 1) {
state[action.node._id][index].values.push([]);
let index = action.node.simulators.findIndex(simulator => simulator.id === smp.id);
if (index === -1 || state[action.node._id][index] == null) {
return state;
}
state[action.node._id][index].values[i].push({ x: action.data.timestamp, y: action.data.values[i] });
// add data to simulator
for (i = 0; i < smp.length; i++) {
while (state[action.node._id][index].values.length < i + 1) {
state[action.node._id][index].values.push([]);
}
// erase old values
if (state[action.node._id][index].values[i].length > MAX_VALUES) {
const pos = state[action.node._id][index].values[i].length - MAX_VALUES;
state[action.node._id][index].values[i].splice(0, pos);
state[action.node._id][index].values[i].push({ x: smp.timestamp, y: smp.values[i] });
// erase old values
if (state[action.node._id][index].values[i].length > MAX_VALUES) {
const pos = state[action.node._id][index].values[i].length - MAX_VALUES;
state[action.node._id][index].values[i].splice(0, pos);
}
}
}
// update metadata
state[action.node._id][index].timestamp = action.data.timestamp;
state[action.node._id][index].sequence = action.data.sequence;
// update metadata
state[action.node._id][index].timestamp = smp.timestamp;
state[action.node._id][index].sequence = smp.sequence;
}
// explicit call to prevent array copy
this.__emitChange();