var plural_DF_list; var special_model_list; function gui_init() { $.ajaxSetup({ async: false, cache: false, dataType: 'html', error: function(jqXHR, error, responseText) { console.log(error) alert ("[ "+ this.url +" ] Can't do because: " + responseText ); }, }); bind_pwd_check_model(); add_new_project(); menu_component_show(false); plural_DF_list = ajax_get_plural_df_list(); special_model_list = ajax_get_create_model_without_select_feature_list(); /*************************************************************************/ /* p_id:-1, add a new project p_id:-2, select a project */ if(p_id == -1) { $('#alertMessage').text('Please add a project.'); //bind add project btn with newPorjectModal $('#project_pull_down_menu').on('click',function() { $('#newPorjectModal').modal('show'); }); return } else if(p_id == -2){ update_project_list_handler(); $('#alertMessage').text('Please select a project.'); return } /*************************************************************************/ } var chart = []; var updatedata = []; function update_monitor_data(div, data, symbol, data_length, subscript, chartN) { var null_flag = 0; for (var value of data[0]) { if (value === null) { null_flag = 1; } } if (null_flag == 0) { var num_of_axis = data[0].length - 1; var div_width = div.width() - 20; var timestamp_width = 120; var axis_width = (div_width - timestamp_width) / num_of_axis - 1; var table_width = timestamp_width + axis_width * num_of_axis; if (div.children('.table-header').find('td').length != data_length || stage_changed == symbol) { div.empty(); stage_changed = ""; } if (div.children('.table-header').length == 0) { //generate chart var arrays = [['x']]; for(var i = 1; i < data[0].length; i++){ if(symbol == 'z') label = symbol + subscript; else label = symbol + i + subscript; arrays.push([label]); } chart[chartN] = c3.generate({ bindto: '#chart' + chartN, size: { height: 190 }, data: { x: 'x', xFormat: '%H:%M:%S', columns: arrays }, legend: { position: 'right', item: { onclick: function (id) {} } }, axis: { x: { type: 'timeseries', tick: { rotate: 75, format: '%H:%M:%S' } } } }); updatedata[chartN] = []; // generate header var table_header = $('', { 'class': 'table table-bordered table-condensed table-header', 'style': 'float: left; position: absolute; background: #E9E9E9; margin-bottom:0px; margin-top:0px; width: ' + table_width, }); var tr = $(''); var td = $('
', {'style': 'width: '+timestamp_width}).text('Timestamp'); td.appendTo(tr); for (i=1; i', {'style': 'width: '+axis_width}); $('
', { 'style': 'overflow: hidden; height: 1.4em', }).append("

"+symbol + "F

").appendTo(td); td.appendTo(tr); } else{ var td = $('
', {'style': 'width: '+axis_width}); $('
', { 'style': 'overflow: hidden; height: 1.4em', }).append("

"+symbol+""+i+subscript+"

").appendTo(td); td.appendTo(tr); } } tr.appendTo(table_header); table_header.appendTo(div); // insert one row { var tbl_div = $('
', { 'class': 'monitor_data_inner_div', }); tbl_div.appendTo(div); var tbl = $('', { 'class': 'table table-bordered table-condensed table-hover', 'style': 'min-height: 30px; margin: 0; width: ' + table_width, }); var tr = $(''); var td = $('
', {'style': 'width: '+timestamp_width}).text('00:00:00'); //timestamp td.appendTo(tr); for (j=1; j', {'style': 'width: '+axis_width}); $('
', { 'style': 'overflow: hidden; height: 1.4em', }).text(data[0][j]).appendTo(td); td.appendTo(tr); } tr.appendTo(tbl); tbl.appendTo(tbl_div); } } var last_time = div.children('.monitor_data_inner_div').last().find('td').first().text(); if (last_time != data[0][0]) { // insert data var tbl_div = $('
', { 'class': 'monitor_data_inner_div', }); tbl_div.appendTo(div); var tbl = $('', { 'class': 'table table-bordered table-condensed table-hover', 'style': 'min-height: 30px; margin: 0; width: ' + table_width, }); for (i=0; i'); // timestamp. var td = $('
', {'style': 'width: '+timestamp_width}).text(data[i][0]); //timestamp td.appendTo(tr); if(div.children('.monitor_data_inner_div').length > 0) { //first row is old data, don;t show if(updatedata[chartN].length == 0) updatedata[chartN].push(['x', data[i][0]]); else { updatedata[chartN][0].push(data[i][0]); if(updatedata[chartN][0].length > 16) updatedata[chartN][0].splice(1, 1); } } // other axis. for (j=1; j 0) { //first row is old data, don;t show if(updatedata[chartN][0].length == 2) updatedata[chartN].push([label, data[i][j]]); else { updatedata[chartN][j].push(data[i][j]); if(updatedata[chartN][j].length > 16) updatedata[chartN][j].splice(1, 1); } } var td = $('', {'style': 'width: '+axis_width}); $('
', { 'style': 'overflow: hidden; height: 1.4em', }).text(data[i][j]).appendTo(td); td.appendTo(tr); } tr.appendTo(tbl); } tbl.appendTo(tbl_div); } if(isTabHidden == false && updatedata[chartN].length != 0) { var length = 0; if(chart[chartN].x()[label]) length = Math.max(0, chart[chartN].data.shown()[0].values.length + updatedata[chartN][0].length - 1 - 15); chart[chartN].flow({ columns: updatedata[chartN], duration: 150, length: length }); updatedata[chartN].length = 0; } if (i == 0) { div.text('No data received now.'); } var scroll_height = div.get(0).scrollHeight; div.parents('.div-intro-block').scrollTop(scroll_height); } } function stop_and_continue_event_handler(is_sim) { $('.stop_continue_button').unbind('click'); $('.stop_continue_button').on('click', function(e) { var dfo_id = $(this).parent().find('select.input-df-select option:selected').attr('name'); if ($(this).text() == 'Step') { if (is_sim == true ) ajax_toggle_execution_mode(dfo_id); $(this).text('Continue'); $('button#step-button').attr('disabled','disabled'); $('button#step-button').css('color','rgb(187, 177, 177)'); $('button#specific-send-button').attr('disabled','disabled'); $('button#specific-send-button').css('color','rgb(187, 177, 177)'); pull_monitored_data(1000,'Continue'); } else if ($(this).text() == 'Continue') { if (is_sim == true ) ajax_toggle_execution_mode(dfo_id); $(this).text('Step'); $('button#step-button').removeAttr('disabled'); $('button#step-button').removeAttr('style'); $('button#specific-send-button').removeAttr('disabled'); $('button#specific-send-button').removeAttr('style'); } }); } function step_event_handler(is_sim) { $('.input-step-button').unbind('click'); $('.input-step-button').on('click', function(e) { var dfo_id = $(this).parent().find('select.input-df-select option:selected').attr('name'); if (is_sim == true ) ajax_push_random_data(dfo_id); sleep(0.5); pull_monitored_data(1000, 'Step'); }); } function send_event_handler() { $('.input-send-button').unbind('click'); $('.input-send-button').on('click', function(e) { var dfo_id = $(this).parent().parent().find('select.input-df-select option:selected').attr('name'); var data = $('.push-data-input').val(); ajax_push_user_input_data(dfo_id, data); sleep(0.5); pull_monitored_data(1000, 'Step'); }); } function table_or_chart_event_handler(id, father) { $(id).unbind('click'); $(id).on('click', function(e) { if($(this).text() == 'Chart') { $(this).text('Table'); $("father svg").hide(); $("father table").show(); } else { $(this).text('Chart'); $("father table").hide(); $("father svg").show(); } }); } function pull_monitored_data(delay, exec_mode) { var na_id = $('.div-idf-monitor-outer').find('label').attr('name'); var idfo_id = $('.div-idf-monitor-outer').find('select.input-df-select option:selected').attr('name'); var in_stage = $('.div-idf-monitor-outer select.step-select option:selected').text(); var odfo_id = $('.div-odf-monitor-outer').find('select.output-df-select option:selected').attr('name'); var out_stage = $('.div-odf-monitor-outer select.step-select option:selected').text(); var execution_mode = $('.input-step-button').attr('disabled'); var is_multiple_join = $('.div-idf-monitor-outer select.step-select option').eq(3).text() == 'Normalization'; if (execution_mode == undefined ) execution_mode = 'Step'; else { execution_mode = 'Continue'; } if (exec_mode == 'Step' ) execution_mode = 'Continue'; var data_path_info = {'na_id': Number(na_id), 'idfo_id': Number(idfo_id), 'i_substage': in_stage, 'o_substage': out_stage, 'odfo_id': Number(odfo_id), 'execution_mode': execution_mode, 'is_multiple_join': is_multiple_join}; data_path_info = JSON.stringify(data_path_info); $.ajax({ url: '/pull_monitored_data', //TODO timeout: delay, type:'POST', data: {data_path_info:data_path_info}, error: function(request,error) { monitor_timer = setTimeout(function() { if ($('.div-idf-monitor-outer').length != 0 || $('.div-odf-monitor-outer').length != 0) { pull_monitored_data(delay, 'Continue'); } }, delay); }, success: function(data) { var data_info = $.parseJSON(data); var i_subscript = ""; if (in_stage == "Input" ) i_subscript = ""; else i_subscript = ','+in_stage[0]; var o_subscript = ""; if (in_stage == "Scaling" ) o_subscript = ""; else o_subscript = ','+out_stage[0]; if ($('.div-idf-monitor-outer').find('.monitor_data_div').length > 0) { var div = $('.div-idf-monitor-outer').find('.monitor_data_div'); div.attr('id', 'chart0'); if (data_info['in'].length != 0){ update_monitor_data(div, data_info['in'], 'x', data_info['in'][0].length, i_subscript, 0); if($(idf_tableorchart).text() == 'Chart'){ $(".div-idf-monitor-outer table").hide(); $(".div-idf-monitor-outer svg").show(); } else{ $(".div-idf-monitor-outer svg").hide(); $(".div-idf-monitor-outer table").show(); } } } if (!$('.div-join-monitor-outer').hasClass('join-mointor-hidden')) { var div = $('.div-join-monitor-outer').find('.monitor_data_div'); div.attr('id', 'chart1'); if (data_info['join'].length != 0){ update_monitor_data(div, data_info['join'], 'z', data_info['join'][0].length, 'F', 1); if($(join_tableorchart).text() == 'Chart'){ $(".div-join-monitor-outer table").hide(); $(".div-join-monitor-outer svg").show(); } else{ $(".div-join-monitor-outer svg").hide(); $(".div-join-monitor-outer table").show(); } } } if ($('.div-odf-monitor-outer').find('.monitor_data_div').length > 0) { var div = $('.div-odf-monitor-outer').find('.monitor_data_div'); div.attr('id', 'chart2'); if (data_info['out'].length != 0){ update_monitor_data(div, data_info['out'], 'y', data_info['out'][0].length, o_subscript, 2); if($(odf_tableorchart).text() == 'Chart'){ $(".div-odf-monitor-outer table").hide(); $(".div-odf-monitor-outer svg").show(); } else{ $(".div-odf-monitor-outer svg").hide(); $(".div-odf-monitor-outer table").show(); } } } if (execution_mode == 'Continue') monitor_timer = setTimeout(function() { if ($('.div-idf-monitor-outer').length != 0 || $('.div-odf-monitor-outer').length != 0) { pull_monitored_data(delay, 'Continue'); } }, delay); else clearTimeout(monitor_timer); } }); }; function feature_change_event_handler(df_type, is_multiple_join) { $('.'+df_type+'-df-select').change(function() { var dfo_id = $(this).find('option:selected').attr('name'); if (df_type == 'input') { var simulator_mode = ajax_get_simulator_mode(dfo_id); step_event_handler(simulator_mode['is_sim']); stop_and_continue_event_handler(simulator_mode['is_sim']); if (simulator_mode['execution_mode'] == 'Continue') { $(this).siblings().filter('button.stop_continue_button').text('Continue'); $('button#step-button').attr('disabled','disabled'); $('button#step-button').css('color','rgb(187, 177, 177)'); $('button#specific-send-button').attr('disabled','disabled'); $('button#specific-send-button').css('color','rgb(187, 177, 177)'); } else $(this).siblings().filter('button.stop_continue_button').text('Step'); if (simulator_mode['is_sim'] == true ) { if ($('#specific-send-button').length ==0) { var div_log_block_outer = $('.div-add-function-outer')[0]; var input_text_label = $('