After user submit,user can change input data,to see the result change.
This commit is contained in:
parent
7982622ca8
commit
788f495c29
|
@ -164,7 +164,7 @@ $(document).ready(function(){
|
|||
$('#cancer_predict_result_block').css('display','none');
|
||||
$('#danger_texts').remove();
|
||||
});
|
||||
$('#cancer_table_submit').click(function(){
|
||||
function get_input_data(){
|
||||
var flag;
|
||||
flag = 1;
|
||||
for(var i = 0;i < $('#cancer_table .cancer_form_field').length;i++){
|
||||
|
@ -202,9 +202,13 @@ $(document).ready(function(){
|
|||
post_json[name] = index;
|
||||
};
|
||||
};
|
||||
post_json['locale'] = I18n.locale;
|
||||
var result = $.post("/cancerpredictResult",{"data":post_json});
|
||||
result.done(function(){
|
||||
return post_json;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
};
|
||||
function set_result(result){
|
||||
if(result.responseJSON.lpv != "error"){
|
||||
var load_heml = $('#result_table_content').html(result.responseJSON.table);
|
||||
load_heml.ready(function(){
|
||||
$('#result_table_content .cancer_years').eq(0).addClass('active');
|
||||
|
@ -214,7 +218,6 @@ $(document).ready(function(){
|
|||
$('#result_table_content .cancer_years').off('click').on('click',function(){
|
||||
try{
|
||||
$(this).parent().find('.cancer_years').removeClass('active');
|
||||
//$('#result_text_content .cancer_years').eq($(this).attr('index')).click();
|
||||
}catch{};
|
||||
$(this).addClass('active');
|
||||
$('#current_year').attr('index',$(this).attr('index'));
|
||||
|
@ -286,7 +289,6 @@ $(document).ready(function(){
|
|||
for(var i = 0;i<add_choices.length;i++){
|
||||
add_choices_transform.push($('[for="'+add_choices[i]+'"]').html())
|
||||
};
|
||||
console.log(add_choices_transform);
|
||||
var add_choices_str = add_choices_transform.slice(0,add_choices_transform.length-1).join('、');
|
||||
if(add_choices_transform.length >= 2)
|
||||
add_choices_str += ('以及'+add_choices_transform[add_choices_transform.length-1])
|
||||
|
@ -367,8 +369,6 @@ $(document).ready(function(){
|
|||
if(!active_treatment.includes($(this).parent().attr('id'))){
|
||||
click_flag = true;
|
||||
active_treatment.push($(this).parent().attr('id'));
|
||||
console.log(active_treatment);
|
||||
console.log(servive_ratio_arr);
|
||||
click_flag = false;
|
||||
};
|
||||
}
|
||||
|
@ -390,37 +390,150 @@ $(document).ready(function(){
|
|||
if(active_treatment.includes($(this).parent().attr('id'))){
|
||||
click_flag = true;
|
||||
active_treatment = active_treatment.remove_item_from_array($(this).parent().attr('id'));
|
||||
console.log(active_treatment);
|
||||
console.log(servive_ratio_arr);
|
||||
click_flag = false;
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
$('#current_year').change(function(){
|
||||
$('.surgery_year').html($(this).attr('value'));
|
||||
year = $(this).attr('value');
|
||||
$('.surgery_year').html(year);
|
||||
$('.cancer_years').removeClass('active');
|
||||
$('#result_text_content .cancer_years').eq($(this).attr("index")).addClass('active');
|
||||
$('#result_table_content .cancer_years').eq($(this).attr("index")).addClass('active');
|
||||
var year = $(this).attr('value');
|
||||
servive_ratio_arr = [];
|
||||
for(var i = 0;i<active_treatment.length;i++){
|
||||
var servive_ratio = Math.round((Math.exp(lpv_calc[year])**Math.exp(lpv_real[i]))*100);
|
||||
var benefit = servive_ratio - servive_ratio_arr[servive_ratio_arr.length-1];
|
||||
servive_ratio_arr.push(servive_ratio);
|
||||
$('tr.'+active_treatment[i]+' td.Overall_Survival').html(servive_ratio+'%');
|
||||
$('.'+active_treatment[i]+'.Overall_Survival').html(servive_ratio);
|
||||
var obj = {"servive_ratio_arr":servive_ratio_arr,"active_treatment":active_treatment,"lpv_real":lpv_real,"lpv_calc":lpv_calc,"year":year}
|
||||
calculate_and_change_result_value(obj);
|
||||
servive_ratio_arr = obj.servive_ratio_arr;
|
||||
active_treatment = obj.active_treatment;
|
||||
lpv_real = obj.lpv_real;
|
||||
lpv_calc = obj.lpv_calc;
|
||||
year = obj.year;
|
||||
});
|
||||
$('#cancer_table .cancer_form_field').off('change').on('change',function(){
|
||||
var obj = {"servive_ratio_arr":servive_ratio_arr,"active_treatment":active_treatment,"lpv_real":lpv_real,"lpv_calc":lpv_calc,"year":year}
|
||||
after_submit_change_func(obj);
|
||||
servive_ratio_arr = obj.servive_ratio_arr;
|
||||
active_treatment = obj.active_treatment;
|
||||
lpv_real = obj.lpv_real;
|
||||
lpv_calc = obj.lpv_calc;
|
||||
year = obj.year;
|
||||
});
|
||||
$('#cancer_table .cancer_form_field').click(function(){
|
||||
$(this).change();
|
||||
});
|
||||
$('select.select_num').off('click').on('click',function(){
|
||||
$(this).change();
|
||||
var obj = {"servive_ratio_arr":servive_ratio_arr,"active_treatment":active_treatment,"lpv_real":lpv_real,"lpv_calc":lpv_calc,"year":year}
|
||||
after_submit_change_func(obj);
|
||||
servive_ratio_arr = obj.servive_ratio_arr;
|
||||
active_treatment = obj.active_treatment;
|
||||
lpv_real = obj.lpv_real;
|
||||
lpv_calc = obj.lpv_calc;
|
||||
year = obj.year;
|
||||
});
|
||||
$('.num_only').on('input', function() {
|
||||
if( Number($(this).val()) < $(this).data('range')[0] || $(this).val() == "" || (Number($(this).val()) > $(this).data('range')[1] && $(this).data('range')[1] != undefined) ){
|
||||
$(this).css('color','#f24a69');
|
||||
$(this).addClass('cancertable_empty');
|
||||
}else{
|
||||
$(this).css('color','#333');
|
||||
$(this).removeClass('cancertable_empty');
|
||||
if($('.cancertable_empty').length == 0){
|
||||
$('#danger_texts').remove();
|
||||
};
|
||||
var obj = {"servive_ratio_arr":servive_ratio_arr,"active_treatment":active_treatment,"lpv_real":lpv_real,"lpv_calc":lpv_calc,"year":year};
|
||||
after_submit_change_func(obj);
|
||||
servive_ratio_arr = obj.servive_ratio_arr;
|
||||
active_treatment = obj.active_treatment;
|
||||
lpv_real = obj.lpv_real;
|
||||
lpv_calc = obj.lpv_calc;
|
||||
year = obj.year;
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
function calculate_and_change_result_value(obj){
|
||||
obj.servive_ratio_arr = [];
|
||||
for(var i = 0;i<obj.active_treatment.length;i++){
|
||||
var servive_ratio = Math.round((Math.exp(obj.lpv_calc[obj.year])**Math.exp(obj.lpv_real[i]))*100);
|
||||
var benefit = servive_ratio - obj.servive_ratio_arr[obj.servive_ratio_arr.length-1];
|
||||
obj.servive_ratio_arr.push(servive_ratio);
|
||||
$('tr.'+obj.active_treatment[i]+' td.Overall_Survival').html(servive_ratio+'%');
|
||||
$('.'+obj.active_treatment[i]+'.Overall_Survival').html(servive_ratio);
|
||||
if(i != 0){
|
||||
$('tr.'+active_treatment[i]+' td.Additional_Benefit').html(benefit+'%');
|
||||
$('.'+active_treatment[i]+'.Additional_Benefit').html(benefit);
|
||||
$('tr.'+obj.active_treatment[i]+' td.Additional_Benefit').html(benefit+'%');
|
||||
$('.'+obj.active_treatment[i]+'.Additional_Benefit').html(benefit);
|
||||
}
|
||||
}
|
||||
$('.'+active_treatment[0]+'.Overall_Survival').html(servive_ratio_arr[0]);
|
||||
$('.survive_person').html(servive_ratio+'%');
|
||||
$('.'+obj.active_treatment[0]+'.Overall_Survival').html(obj.servive_ratio_arr[0]);
|
||||
};
|
||||
function after_submit_change_func(obj){
|
||||
var post_json = get_input_data();
|
||||
if(post_json != null){
|
||||
var new_lpv = calculate_first_lpv(post_json)['lpv'];
|
||||
var old_lpv = obj.lpv_real[0];
|
||||
obj.lpv_real = obj.lpv_real.map(original_value=>(original_value+new_lpv-old_lpv));
|
||||
calculate_and_change_result_value(obj);
|
||||
};
|
||||
};
|
||||
function calculate_first_lpv(result_json){
|
||||
result = {}
|
||||
result['age1'] = -Math.pow((Number(result_json['age'])/100),-0.5);
|
||||
result['age2'] = -Math.pow((Number(result_json['age'])/100),-0.5)*Math.log(result_json['age']/100);
|
||||
result['size1'] = -Math.log(Number(result_json['size'])/10);
|
||||
result['nposit'] = -Math.pow(((Number(result_json['ratio'])+0.1)/0.1),0.5);
|
||||
if( Number(result_json['grade']) == 2)
|
||||
result['grade_2'] = 1;
|
||||
else
|
||||
result['grade_2'] = 0;
|
||||
if( Number(result_json['grade']) == 3)
|
||||
result['grade_3'] = 1;
|
||||
else
|
||||
result['grade_3'] = 0;
|
||||
if( Number(result_json['subtype']) == 2)
|
||||
result['subtype_HER2'] = 1;
|
||||
else
|
||||
result['subtype_HER2'] = 0;
|
||||
if( Number(result_json['subtype']) == 3)
|
||||
result['subtype_triple'] = 1;
|
||||
else
|
||||
result['subtype_triple'] = 0;
|
||||
if( Number(result_json['pstage']) == 2)
|
||||
result['pstage_2'] = 1;
|
||||
else
|
||||
result['pstage_2'] = 0;
|
||||
if( Number(result_json['pstage']) == 3)
|
||||
result['pstage_3'] = 1;
|
||||
else
|
||||
result['pstage_3'] = 0;
|
||||
if( Number(result_json['pstage']) == 4)
|
||||
result['pstage_4'] = 1;
|
||||
else
|
||||
result['pstage_4'] = 0;
|
||||
if( Number(result_json['lvi']) == 1)
|
||||
result['lvi_yes'] = 1;
|
||||
else
|
||||
result['lvi_yes'] = 0;
|
||||
try{
|
||||
result['lpv'] = ((result['age1']-0.7276655)*(10.87)+(result['age2']+0.4540707)*8.968+(result['size1']-0.643632)*0.7678+(result['nposit']-1.346932)*0.5339+
|
||||
result['grade_2']*0.4795+result['grade_3']*0.818+result['subtype_HER2']*0.1806+result['subtype_triple']*0.6457+result['pstage_2']*0.5311+
|
||||
result['pstage_3']*1.134+result['pstage_4']*2.172+result['lvi_yes']*0.3321-0.04);
|
||||
}catch{result['lpv'] = "error"};
|
||||
return result;
|
||||
};
|
||||
function submit_fcn(){
|
||||
var post_json = get_input_data();
|
||||
if(post_json != null){
|
||||
post_json['locale'] = I18n.locale;
|
||||
var result = $.post("/cancerpredictResult",{"data":post_json});
|
||||
result.done(function(){
|
||||
set_result(result);
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
};
|
||||
};
|
||||
$('#cancer_table_submit').click(function(){
|
||||
submit_fcn();
|
||||
});
|
||||
for(var i = 0;i < $('.result_tab').length;i++){
|
||||
$('.result_tab').eq(i).attr('index',i)
|
||||
|
@ -439,7 +552,6 @@ $(document).ready(function(){
|
|||
return event.keyCode>=48&&event.keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46:false);
|
||||
});
|
||||
$('.float_num').off('keyup').on('keyup',function(){
|
||||
console.log($(this).val());
|
||||
this.value = this.value.replace(/[^\d.]/g,'');
|
||||
});
|
||||
$('.num_only').on('input', function() {
|
||||
|
|
Loading…
Reference in New Issue