Skip to content

Commit 66b41fb

Browse files
committed
updated virtual in status display
1 parent 2eea04d commit 66b41fb

File tree

6 files changed

+165
-14
lines changed

6 files changed

+165
-14
lines changed

blueprint/status.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
url: '/getdata/',
163163
type: 'GET',
164164
success: function (response) {
165-
console.log(response);
165+
//console.log(response);
166166
let currentTime = new Date();
167167
let currentUTCTime = currentTime.toUTCString();
168168

@@ -181,7 +181,13 @@
181181
//console.log("Looping calc");
182182
//console.log(this.id);
183183
parse_calc(this.id, response);
184-
//console.log($(this).attr('data-formula'));
184+
});
185+
186+
// Loop through virtual_
187+
$('[id^=virtual_]').each(function( index ) {
188+
//console.log("Looping calc");
189+
//console.log(this.id);
190+
parse_virtual(this.id, response);
185191
});
186192

187193
},

js_plugins/calc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function parse_calc(key, response) {
3434
var finalstring = "";
3535
var pattern = /\[(.*?)\]/g;
3636
var teststring = myformula.split(/[\[\]]+/);
37-
console.log("Test String");
37+
//console.log("Test String");
3838
//console.log(teststring);
3939
//console.log(finalstring);
4040

js_plugins/virtual.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,108 @@
11
$(function(){
22

33
/** BORA-JS **/
4+
});
5+
6+
/*
7+
var retval = eval( "parse_" + response[key]["widget"].replace(/-/g, "_") + "('" + key + "','" + response[key]["value"] + "','" + response[key]["timestamp"] +"','" + response[key]["invalid"] + "')" );
8+
*/
9+
10+
function parse_virtual(id, response) {
11+
//console.log(invalid); // invalid value is in milliseconds
12+
//console.log("Inside parse_virtual()");
13+
//console.log(id);
14+
15+
var key = $("#" + id).attr("data-virtual-id");
16+
//console.log(key);
17+
//console.log(response);
18+
var value = response[key]["value"];
19+
var timestamp = response[key]["timestamp"];
20+
var invalid = response[key]["invalid"];
21+
22+
let currentTime = new Date();
23+
let currentTimeMillis = currentTime.getTime();
24+
25+
var data_decimal_numbers = parseInt($("#" + id).attr("data-decimal-numbers"));
26+
var data_smaller_than = $("#" + id).attr("data-smaller-than");
27+
var data_larger_than = $("#" + id).attr("data-larger-than");
28+
29+
var delta = (currentTimeMillis - timestamp) / 1000.0;
30+
// since delta is converted to seconds, we need to convert invalid to seconds as well
31+
invalid = invalid / 1000.0;
32+
33+
34+
if (data_decimal_numbers != undefined && data_decimal_numbers > 0) {
35+
value = (Math.round(value * 100) / 100).toFixed(data_decimal_numbers);
36+
}
37+
38+
if (data_smaller_than != undefined && value < data_smaller_than) {
39+
$("#" + id + "> .value").css('color', 'red');
40+
$("#" + id + "> .unit-name").css('color', 'red');
41+
} else {
42+
$("#" + id + "> .value").css('color', 'green');
43+
$("#" + id + "> .unit-name").css('color', 'green');
44+
}
45+
46+
if (data_larger_than != undefined && value > data_larger_than) {
47+
$("#" + id + "> .value").css('color', 'red');
48+
$("#" + id + "> .unit-name").css('color', 'red');
49+
} else {
50+
$("#" + id + "> .value").css('color', 'green');
51+
$("#" + id + "> .unit-name").css('color', 'green');
52+
}
53+
54+
if (data_exp != undefined && data_exp == "true") {
55+
if (data_decimal_numbers != undefined && data_decimal_numbers > 0) {
56+
value = parseFloat(value).toExponential(data_decimal_numbers);
57+
} else {
58+
value = parseFloat(value).toExponential();
59+
}
60+
}
61+
62+
if (invalid != undefined && invalid < delta) {
63+
$("#" + id + "> .value").css('color', 'grey');
64+
$("#" + id + "> .unit-name").css('color', 'grey');
65+
}
66+
67+
$("#"+id).attr('tooltip', key + "\nDeltaTime: " + parseFloat(delta).toFixed(3) + " s (" + parseFloat(delta / 60.0).toFixed(3) + " min)");
68+
69+
$("#" + id + " > .value").text(value);
70+
}
71+
72+
var win_width = $(document).width();
73+
var win_height = $(document).height();
74+
75+
$(".virtualbox").hover(function(){
76+
var trend_time_end = Math.floor(Date.now() / 1000);
77+
var trend_time_start = trend_time_end - 3600;
78+
var key = $(this).attr('data-virtual-id');
79+
var data_adei = "https://adei-katrin.kaas.kit.edu/adei/";
80+
var data_query = $("#" + key).attr('data-query');
81+
82+
data_query = data_query.split("?")[1];
83+
84+
const urlParams = new URLSearchParams("?"+data_query);
85+
86+
var output_query = "db_server="+urlParams.get('db_server')+"&db_name="+urlParams.get('db_name')+"&db_group="+urlParams.get('db_group')+"&db_mask="+urlParams.get('db_mask');
87+
88+
if ($("#" + key).attr('data-trend') == "true") {
89+
$('#'+key + '> .popup').remove();
90+
$('#'+ key).append('<span class="popup" style="top:0; left:250px;"><img src="' + data_adei + 'services/getimage.php?' + output_query + '&window='+ trend_time_start.toString() +'-'+ trend_time_end.toString() + '&frame_width=600&frame_height=400" width="600px" height="400px"/></span>');
91+
var key_left = parseInt($("#" + key).css("left"));
92+
var pos_left = key_left + 850;
93+
var key_top = parseInt($("#" + key).css("top"));
94+
var pos_top = key_top + 400;
95+
if(pos_left > win_width) {
96+
$("#" + key + " .popup").css({
97+
'right':'250px',
98+
'left': ''
99+
});
100+
}
101+
if(pos_top > win_height) {
102+
$("#" + key + " .popup").css({
103+
'bottom':'0px',
104+
'top': ''
105+
});
106+
}
107+
}
4108
});

template/adei.html

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
{% if data['style'][key]['type'] == "adei" %}
2-
<div id='{{ key }}' onclick="open_adei_page('{{ key }}')" class="databox" tooltip="" data-query="{{ data['varname'][key]['url'] }}" data-type="{{ data['style'][key]['type'] }}" data-decimal-numbers="{{ data['style'][key]['div']['data-decimal-numbers'] }}" data-smaller-than="{{ data['style'][key]['div']['data-smaller-than'] }}" data-larger-than="{{ data['style'][key]['div']['data-larger-than'] }}" data-exp="{{ data['style'][key]['div']['data-exp'] }}" data-link-adei="{{ data['style'][key]['div']['data-link-adei'] }}" data-trend="{{ data['style'][key]['div']['data-trend'] }}" style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
2+
<div
3+
id='{{ key }}'
4+
onclick="open_adei_page('{{ key }}')"
5+
class="databox"
6+
tooltip=""
7+
data-query="{{ data['varname'][key]['url'] }}"
8+
data-type="{{ data['style'][key]['type'] }}"
9+
data-decimal-numbers="{{ data['style'][key]['div']['data-decimal-numbers'] }}"
10+
data-smaller-than="{{ data['style'][key]['div']['data-smaller-than'] }}"
11+
data-larger-than="{{ data['style'][key]['div']['data-larger-than'] }}"
12+
data-exp="{{ data['style'][key]['div']['data-exp'] }}"
13+
data-link-adei="{{ data['style'][key]['div']['data-link-adei'] }}"
14+
data-trend="{{ data['style'][key]['div']['data-trend'] }}"
15+
style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
316
data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
4-
height:{{ data['style'][key]['height'] }}px; font-size:14px; font-weight: {{ data['style'][key]['div']['font-weight'] }}; background-color: {{ data['style'][key]['div']['background-color'] }};' data-type='adei'>
17+
height:{{ data['style'][key]['height'] }}px; font-size:14px; font-weight: {{ data['style'][key]['div']['font-weight'] }}; background-color: {{ data['style'][key]['div']['background-color'] }};'>
518
<span style='color: #000; font-size: {{ data['style'][key]['div']['font-size'] }}; font-weight: {{ data['style'][key]['div']['font-weight'] }};' class='text-name'>{{ data['style'][key]['div']['text-name'] }}</span>
619
<span style='color: #000; font-size: {{ data['style'][key]['div']['font-size'] }}; font-weight: {{ data['style'][key]['div']['font-weight'] }};' class='value'>XXX.XX</span>
720
<span style='color: #000; font-size: {{ data['style'][key]['div']['font-size'] }}; font-weight: {{ data['style'][key]['div']['font-weight'] }};' class='unit-name'>{{ data['style'][key]['div']['unit-name'] }}</span>

template/virtual.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
{% if data['style'][key]['type'] == "virtual" %}
2-
<div id='{{ key }}' data-type="{{ data['style'][key]['type'] }}" data-virtual-id="{{ data['style'][key]['div']['data-virtual-id'] }}" data-decimal-numbers="{{ data['style'][key]['div']['data-decimal-numbers'] }}" data-smaller-than="{{ data['style'][key]['div']['data-smaller-than'] }}" data-larger-than="{{ data['style'][key]['div']['data-larger-than'] }}" style='position: absolute; top: {{ data['style'][key]['top'] }};
3-
left:{{ data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px; height:{{ data['style'][key]['height'] }}px; font-size: {{ data['style'][key]['div']['font-size'] }}; font-weight: {{ data['style'][key]['div']['font-weight'] }};'>
4-
<span class='text_name'>{{ data['style'][key]['div']['text-name'] }}</span> <span class='value'>XXX.XX</span> <span class='unit_name'>{{ data['style'][key]['div']['unit-name'] }}</span>
2+
<div
3+
id='{{ key }}'
4+
onclick="open_adei_page('{{ data['style'][key]['div']['data-virtual-id'] }}')"
5+
class="virtualbox"
6+
tooltip=""
7+
data-virtual-id="{{ data['style'][key]['div']['data-virtual-id'] }}"
8+
data-type="{{ data['style'][key]['type'] }}"
9+
data-decimal-numbers="{{ data['style'][key]['div']['data-decimal-numbers'] }}"
10+
data-smaller-than="{{ data['style'][key]['div']['data-smaller-than'] }}"
11+
data-larger-than="{{ data['style'][key]['div']['data-larger-than'] }}"
12+
style='position: absolute; top: {{ data['style'][key]['top'] }}; left:{{
13+
data['style'][key]['left'] }}; width:{{ data['style'][key]['width'] }}px;
14+
height:{{ data['style'][key]['height'] }}px; font-size:14px; font-weight: {{ data['style'][key]['div']['font-weight'] }}; background-color: {{ data['style'][key]['div']['background-color'] }};'>
15+
<span style='color: #000; font-size: {{ data['style'][key]['div']['font-size'] }}; font-weight: {{ data['style'][key]['div']['font-weight'] }};' class='text-name'>{{ data['style'][key]['div']['text-name'] }}</span>
16+
<span style='color: #000; font-size: {{ data['style'][key]['div']['font-size'] }}; font-weight: {{ data['style'][key]['div']['font-weight'] }};' class='value'>XXX.XX</span>
17+
<span style='color: #000; font-size: {{ data['style'][key]['div']['font-size'] }}; font-weight: {{ data['style'][key]['div']['font-weight'] }};' class='unit-name'>{{ data['style'][key]['div']['unit-name'] }}</span>
518
</div>
619
{% else %}
720
{% end %}
21+

typedef/virtual.yaml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,27 @@
4141
"type": "select"
4242
"optional": "No"
4343
"data": "No"
44-
"width":
44+
"exp":
4545
"value": ""
46-
"type": "string"
47-
"optional": "No"
48-
"data": "No"
49-
"height":
46+
"type": "bool"
47+
"optional": "Yes"
48+
"data": "Yes"
49+
"link_adei":
5050
"value": ""
51-
"type": "string"
51+
"type": "bool"
52+
"optional": "Yes"
53+
"data": "Yes"
54+
"trend":
55+
"value": ""
56+
"type": "bool"
57+
"optional": "Yes"
58+
"data": "Yes"
59+
"background_color":
60+
"value":
61+
- 255
62+
- 255
63+
- 255
64+
- 0
65+
"type": "color"
5266
"optional": "No"
5367
"data": "No"

0 commit comments

Comments
 (0)