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

191 lines
4.8 KiB
JavaScript
Raw Normal View History

2015-10-13 14:12:34 +02:00
import Ember from 'ember';
2015-10-28 05:53:20 -04:00
import ENV from '../config/environment';
2015-10-13 14:12:34 +02:00
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-26 12:41:50 -04:00
voltage203937: [],
loadGenProfiles: [],
2015-10-26 14:56:29 -04:00
totalPValue: [],
2015-10-23 07:20:10 -04:00
2015-10-26 14:56:29 -04:00
_freezeState: false,
2015-10-23 08:52:29 -04:00
initState: function() {
return this.get('state') === 1;
}.property('state'),
eventState: function() {
return this.get('state') === 2;
}.property('state'),
2015-10-26 14:56:29 -04:00
initButtonState: function() {
return this.get('state') === 1 || this.get('state') === 0;
}.property('state'),
eventButtonState: function() {
return this.get('state') === 2 || this.get('state') === 0;
}.property('state'),
2015-10-28 05:53:20 -04:00
showExtendedView: function() {
2015-10-28 06:15:20 -04:00
return (ENV.APP.SHOW_EXTENDED_VIEW === 'true');
2015-10-28 05:53:20 -04:00
}.property(),
2015-10-26 12:41:50 -04:00
_updateController: function() {
// update attribute values
this._updateAttributes();
// get new data file control state from store
2015-10-26 14:56:29 -04:00
if (this._freezeState === false) {
var control = this.store.peekRecord('data-file-control', 'DataFileControl');
2015-10-28 05:53:20 -04:00
var reload = control.get('ForceReload');
2015-10-28 05:53:20 -04:00
if (reload === false || reload === 'false') {
if (control.get('Filename') === '/share/data/m1_S1_ElectricalGrid_data.txt') {
// state 1
if (this.get('state') !== 1) {
this.set('state', 1);
Ember.debug('update state (1)');
}
} else {
// state 2
if (this.get('state') !== 2) {
this.set('state', 2);
Ember.debug('update state (2)');
}
2015-10-26 14:56:29 -04:00
}
}
2015-10-27 07:09:22 -04:00
var status = control.get('Status');
2015-10-28 05:53:20 -04:00
2015-10-27 07:09:22 -04:00
/*Ember.debug('status: ' + status + ', reload: ' + reload);*/
if ((status === 'EOF') && ((reload === false) || (reload) === 'false')) {
2015-10-26 14:56:29 -04:00
if (this.get('state') === 1) {
control.set('ForceReload', true);
} else {
control.set('Filename', '/share/data/m1_S1_ElectricalGrid_data.txt');
this.set('state', 1);
}
2015-10-26 14:56:29 -04:00
control.save();
Ember.debug('update control: ' + control.get('Filename') + ', ' + control.get('ForceReload'));
}
}
2015-10-26 14:56:29 -04:00
2015-10-28 05:53:20 -04:00
Ember.run.later(this, this._updateController, ENV.APP.UPDATE_RATE);
2015-10-26 12:41:50 -04:00
}.on('init'),
_updateAttributes: function() {
// check for model and properties
if (!this.model) {
Ember.debug('controller model not found');
return false;
}
var entity = this.model.findBy('id', 'S3_ElectricalGrid');
if (!entity) {
Ember.debug('controller entity S3 not found');
return false;
}
var properties = entity.get('properties');
if (!properties) {
2015-10-26 14:56:29 -04:00
Ember.debug('controller properties not found');
2015-10-26 12:41:50 -04:00
return false;
}
// update attributes
var attr_freq575 = properties.findBy('name', 'Freq_575');
2015-10-26 14:56:29 -04:00
if (attr_freq575) {
2015-10-26 12:41:50 -04:00
this.set('freq575Value', attr_freq575.get('currentValue'));
2015-10-26 14:56:29 -04:00
} else {
Ember.debug('controller freq575 not found');
2015-10-26 12:41:50 -04:00
}
var attr_voltage203937 = properties.findBy('name', 'Voltage203937');
if (attr_voltage203937) {
this.set('voltage203937', [
{
label: 'RMS voltage [pu]',
data: attr_voltage203937.get('values'),
color: 'rgb(51, 153, 255)'
}
]);
} else {
Ember.debug('controller voltage203937 not found');
}
var attr_loadProfile = properties.findBy('name', 'LoadProfile');
var attr_genProfile = properties.findBy('name', 'GenProfile');
if (attr_loadProfile && attr_genProfile) {
2015-10-26 14:56:29 -04:00
this.set('loadGenProfiles', [
2015-10-26 12:41:50 -04:00
{
label: 'Total consumption [MW]',
data: attr_loadProfile.get('values'),
color: "rgb(51, 153, 255)"
},
{
label: 'Total PV generation [MW]',
data: attr_genProfile.get('values'),
color: "rgb(255, 91, 51)"
}
]);
} else {
Ember.debug('controller loadGenProfile not found');
}
2015-10-26 14:56:29 -04:00
var attr_totalP = properties.findBy('name', 'TotalP_DS');
if (attr_totalP) {
this.set('totalPValue', [
{
bars: { show: true },
2015-10-27 07:09:22 -04:00
data: [[0, attr_totalP.get('currentValue')]]
2015-10-26 14:56:29 -04:00
}
]);
} else {
Ember.debug('controller totalP not found');
}
2015-10-26 12:41:50 -04:00
return true;
},
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');
2015-10-26 14:56:29 -04:00
this.set('state', 1);
} else {
2015-10-22 15:44:25 -04:00
control.set('Filename', '/share/data/m2_S1_ElectricalGrid_data.txt');
2015-10-26 14:56:29 -04:00
this.set('state', 2);
}
2015-10-26 14:56:29 -04:00
this._freezeState = true;
Ember.run.later(this, function() {
this._freezeState = false;
}, 1000);
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
});