1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-16 00:00:03 +01:00
VILLASweb/app/controllers/lab-mashup.js

134 lines
3.1 KiB
JavaScript
Raw Normal View History

2015-10-13 14:12:34 +02:00
import Ember from 'ember';
export default Ember.Controller.extend({
freq575GreenZones: [{from: 49.5, to: 50.5}],
2015-10-22 15:44:25 -04:00
freq575YellowZones: [{from: 49, to: 49.5}, {from: 50.5, to: 51}],
2015-10-22 16:18:42 -04:00
freq575AlarmZones: [{from: 49, to: 49.5}, {from: 50.5, to: 51}],
2015-10-23 07:20:10 -04:00
freq575Value: 0,
2015-10-23 08:52:29 -04:00
_waitForStateUpdate: false,
init: function() {
2015-10-22 15:44:25 -04:00
this.set('state', 1);
2015-10-22 15:44:25 -04:00
Ember.run.later(this, this._updateState, 100);
},
2015-10-13 14:12:34 +02:00
S1Entity: function() {
return this.model.findBy('id', 'S1_ElectricalGrid');
2015-10-13 14:12:34 +02:00
}.property('model.[]'),
2015-10-22 15:44:25 -04:00
Voltage203937: function() {
var entity = this.model.findBy('id', 'S1_ElectricalGrid');
2015-10-23 07:20:10 -04:00
2015-10-22 15:44:25 -04:00
if (entity) {
return [
{
2015-10-23 07:20:10 -04:00
label: 'RMS voltage [pu]',
2015-10-22 15:44:25 -04:00
data: entity.get('properties').findBy('name', 'Voltage203937').get('values'),
color: "rgb(51, 153, 255)"
}
];
} else {
return {};
}
}.property('model.[]'),
2015-10-23 07:20:10 -04:00
Freq575Observer: function() {
Ember.run.later(this, this.Freq575Observer, 100);
if (this.model) {
var entity = this.model.findBy('id', 'S1_ElectricalGrid');
if (entity) {
var attribute = entity.get('properties').findBy('name', 'Freq_575');
this.set('freq575Value', attribute.get('currentValue'));
}
}
2015-10-23 07:20:10 -04:00
}.on('init'),
2015-10-22 15:44:25 -04:00
LoadGenProfiles: function() {
var entity = this.model.findBy('id', 'S1_ElectricalGrid');
if (entity) {
return [
{
label: 'Total consumption [MW]',
data: entity.get('properties').findBy('name', 'LoadProfile').get('values'),
color: "rgb(51, 153, 255)"
},
{
label: 'Total PV generation [MW]',
data: entity.get('properties').findBy('name', 'GenProfile').get('values'),
color: "rgb(255, 91, 51)"
}
];
} else {
return [];
}
}.property('model.[]'),
initState: function() {
return this.get('state') === 1;
}.property('state'),
eventState: function() {
return this.get('state') === 2;
}.property('state'),
2015-10-22 15:44:25 -04:00
_updateState: function() {
var control = this.store.peekRecord('data-file-control', 'DataFileControl');
var updated = false;
2015-10-22 15:44:25 -04:00
if (control.get('Filename') === '/share/data/m1_S1_ElectricalGrid_data.txt') {
if (this.get('state') !== 1) {
2015-10-22 15:44:25 -04:00
this.set('state', 1);
}
} else {
if (this.get('state') !== 2) {
2015-10-22 15:44:25 -04:00
this.set('state', 2);
}
}
if (control.get('Status') === 'EOF') {
if (this.get('state') === 1) {
control.set('ForceReload', true);
} else {
2015-10-22 15:44:25 -04:00
control.set('Filename', '/share/data/m1_S1_ElectricalGrid_data.txt');
}
updated = true;
}
if (updated) {
2015-10-22 15:44:25 -04:00
control.save();
}
2015-10-22 15:44:25 -04:00
Ember.run.later(this, this._updateState, 100);
},
2015-10-22 15:44:25 -04:00
_updateDataFileControl: function(state) {
var control = this.store.peekRecord('data-file-control', 'DataFileControl');
2015-10-22 15:44:25 -04:00
if (state === 1) {
control.set('Filename', '/share/data/m1_S1_ElectricalGrid_data.txt');
} else {
2015-10-22 15:44:25 -04:00
control.set('Filename', '/share/data/m2_S1_ElectricalGrid_data.txt');
}
2015-10-22 15:44:25 -04:00
console.log("changed data control");
control.set('ForceReload', true);
control.save();
2015-10-22 15:44:25 -04:00
},
actions: {
resetData: function() {
2015-10-22 15:44:25 -04:00
this._updateDataFileControl(1);
},
eventData: function() {
2015-10-22 15:44:25 -04:00
this._updateDataFileControl(2);
}
}
2015-10-13 14:12:34 +02:00
});