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

Upgrade missing widgets to simulation model data

This commit is contained in:
Markus Grigull 2018-05-04 10:14:05 +02:00
parent 00ce63c7a0
commit f794d14aad
3 changed files with 37 additions and 38 deletions

View file

@ -34,9 +34,13 @@ class WidgetLamp extends Component {
}
componentWillReceiveProps(nextProps) {
// update value
const simulator = nextProps.widget.simulator;
if (nextProps.simulationModel == null) {
return;
}
const simulator = nextProps.simulationModel.simulator;
// update value
if (nextProps.data == null || nextProps.data[simulator] == null || nextProps.data[simulator].output.values == null) {
this.setState({ value: '' });
return;

View file

@ -37,13 +37,17 @@ class WidgetPlotTable extends Component {
}
componentWillReceiveProps(nextProps) {
if (nextProps.simulationModel == null) {
return;
}
// Update internal selected signals state with props (different array objects)
if (this.props.widget.signals !== nextProps.widget.signals) {
this.setState( {signals: nextProps.widget.signals});
}
// Identify if there was a change in the preselected signals
if (nextProps.simulation && (JSON.stringify(nextProps.widget.preselectedSignals) !== JSON.stringify(this.props.widget.preselectedSignals) || this.state.preselectedSignals.length === 0)) {
if (JSON.stringify(nextProps.widget.preselectedSignals) !== JSON.stringify(this.props.widget.preselectedSignals) || this.state.preselectedSignals.length === 0) {
// Update the currently selected signals by intersecting with the preselected signals
// Do the same with the plot values
var intersection = this.computeIntersection(nextProps.widget.preselectedSignals, nextProps.widget.signals);
@ -60,35 +64,24 @@ class WidgetPlotTable extends Component {
}
updatePreselectedSignalsState(nextProps) {
const simulator = nextProps.widget.simulator;
// Create checkboxes using the signal indices from simulation model
const preselectedSignals = nextProps.simulationModel.outputMapping.reduce(
// Loop through simulation model signals
(accum, model_signal, signal_index) => {
// Append them if they belong to the current selected type
if (nextProps.widget.preselectedSignals.indexOf(signal_index) > -1) {
accum.push(
{
index: signal_index,
name: model_signal.name,
type: model_signal.type
}
)
}
return accum;
}, []);
// get simulation model
const simulationModel = nextProps.simulation.models.find((model) => {
return (model.simulator === simulator);
});
let preselectedSignals = [];
// Proceed if a simulation model is available
if (simulationModel) {
// Create checkboxes using the signal indices from simulation model
preselectedSignals = simulationModel.outputMapping.reduce(
// Loop through simulation model signals
(accum, model_signal, signal_index) => {
// Append them if they belong to the current selected type
if (nextProps.widget.preselectedSignals.indexOf(signal_index) > -1) {
accum.push(
{
index: signal_index,
name: model_signal.name,
type: model_signal.type
}
)
}
return accum;
}, []);
}
this.setState({ preselectedSignals: preselectedSignals });
this.setState({ preselectedSignals });
}
updateSignalSelection(signal_index, checked) {
@ -100,10 +93,10 @@ class WidgetPlotTable extends Component {
}
render() {
var checkBoxes = [];
let checkBoxes = [];
// Data passed to plot
let simulator = this.props.widget.simulator;
const simulator = this.props.simulationModel.simulator;
let simulatorData = [];
if (this.props.data[simulator] != null) {

View file

@ -35,12 +35,14 @@ class WidgetPlot extends React.Component {
}
componentWillReceiveProps(nextProps) {
const simulator = nextProps.widget.simulator;
const simulation = nextProps.simulation;
if (nextProps.simulationModel == null) {
return;
}
const simulator = nextProps.simulationModel.simulator;
// Proceed if a simulation with models and a simulator are available
if (simulator && nextProps.data[simulator] != null && nextProps.data[simulator] != null && simulation && simulation.models.length > 0) {
const model = simulation.models.find(model => model.simulator === simulator);
if (simulator && nextProps.data[simulator] != null && nextProps.data[simulator] != null) {
const chosenSignals = nextProps.widget.signals;
const data = nextProps.data[simulator].output.values.filter((values, index) => (
@ -48,7 +50,7 @@ class WidgetPlot extends React.Component {
));
// Query the signals that will be displayed in the legend
const legend = model.outputMapping.reduce( (accum, model_signal, signal_index) => {
const legend = nextProps.simulationModel.outputMapping.reduce( (accum, model_signal, signal_index) => {
if (chosenSignals.includes(signal_index)) {
accum.push({ index: signal_index, name: model_signal.name, type: model_signal.type });
}