diff --git a/app/assets/javascripts/cancer_predict.js b/app/assets/javascripts/cancer_predict.js index b2e2084..3026a19 100644 --- a/app/assets/javascripts/cancer_predict.js +++ b/app/assets/javascripts/cancer_predict.js @@ -385,7 +385,7 @@ $(document).ready(function(){ $('#cancer_predict_result_block').css('display','block'); var lpv_real = [result.responseJSON['lpv_variable']]; var lpv_dict={} - var lpv_calc=/*lpv_calc_formula_start*/{1: "0.8095037^( exp(lpv_current) )",1.5: "0.729158^( exp(lpv_current) )",2: "0.6717211^( exp(lpv_current) )", 2.5: "0.6056773^( exp(lpv_current) )"}/*lpv_calc_formula_end*/ + var lpv_calc=/*lpv_calc_formula_start*/{"1":"0.8095037**( Math.exp(lpv_current) )","1.5":"0.729158**( Math.exp(lpv_current) )","2":"0.6717211**( Math.exp(lpv_current) )","2.5":"0.6056773**( Math.exp(lpv_current) )"}/*lpv_calc_formula_end*/ active_treatment.push = function() { if(arguments.length == 1){ var year = $('#current_year').attr('value'); @@ -434,7 +434,8 @@ $(document).ready(function(){ if(index < this.length - 1){ for(var i = index + 1;i < this.length; i++){ change_object_variables(lpv_real[i] , lpv_dict[arguments[0]] , '-' , 'self'); - var servive_ratio = round((Math.exp(lpv_calc[year])**Math.exp(lpv_real[i]))*100,2); + var lpv_current = lpv_real[i]; + var servive_ratio = round(eval(lpv_calc[year])*100,2); servive_ratio_arr[i] = servive_ratio; var benefit = servive_ratio - ((i == index+1) ? servive_ratio_arr[index - 1] : servive_ratio_arr[i - 1]); $('tr.'+active_treatment[i]+' td.Overall_Survival').html(servive_ratio+'%'); @@ -592,170 +593,163 @@ $(document).ready(function(){ }; /* auto add start */ function calculate_first_lpv(result_json){ - result = {}; - var map_values , mapping_hash , temp_index ,temp_value , index , closest_value; + result = {}; + var map_values , mapping_hash , temp_index ,temp_value , index , closest_value; result['sex_value'] = (2 - Number(result_json['sex_value'])); result['age'] = Number(result_json['age']); mapping_hash = mapping_data_from_csv['age']; temp_index = 0; temp_value = result[age]; index = 0; - $.each(mapping_hash,function(k,v){ - if( i == 0 ){ - var index_val = v.indexOf(temp_value); - if( index_val != -1 ){ - temp_index = index_val; - }else{ - closest_value = v.get_nearest_value(temp_value); - temp_index = v.indexOf(closest_value) - } - } - result[k] = v[temp_index]; - index++; - }); + $.each(mapping_hash,function(k,v){ + if( i == 0 ){ + var index_val = v.indexOf(temp_value); + if( index_val != -1 ){ + temp_index = index_val; + }else{ + closest_value = v.get_nearest_value(temp_value); + temp_index = v.indexOf(closest_value) + } + } + result[k] = v[temp_index]; + index++; + }); result['calH'] = Number(result_json['calH']); mapping_hash = mapping_data_from_csv['calH']; temp_index = 0; temp_value = result[calH]; index = 0; - $.each(mapping_hash,function(k,v){ - if( i == 0 ){ - var index_val = v.indexOf(temp_value); - if( index_val != -1 ){ - temp_index = index_val; - }else{ - closest_value = v.get_nearest_value(temp_value); - temp_index = v.indexOf(closest_value) - } - } - result[k] = v[temp_index]; - index++; - }); + $.each(mapping_hash,function(k,v){ + if( i == 0 ){ + var index_val = v.indexOf(temp_value); + if( index_val != -1 ){ + temp_index = index_val; + }else{ + closest_value = v.get_nearest_value(temp_value); + temp_index = v.indexOf(closest_value) + } + } + result[k] = v[temp_index]; + index++; + }); result['calAH'] = Number(result_json['calAH']); mapping_hash = mapping_data_from_csv['calAH']; temp_index = 0; temp_value = result[calAH]; index = 0; - $.each(mapping_hash,function(k,v){ - if( i == 0 ){ - var index_val = v.indexOf(temp_value); - if( index_val != -1 ){ - temp_index = index_val; - }else{ - closest_value = v.get_nearest_value(temp_value); - temp_index = v.indexOf(closest_value) - } - } - result[k] = v[temp_index]; - index++; - }); + $.each(mapping_hash,function(k,v){ + if( i == 0 ){ + var index_val = v.indexOf(temp_value); + if( index_val != -1 ){ + temp_index = index_val; + }else{ + closest_value = v.get_nearest_value(temp_value); + temp_index = v.indexOf(closest_value) + } + } + result[k] = v[temp_index]; + index++; + }); result['calDH'] = Number(result_json['calDH']); mapping_hash = mapping_data_from_csv['calDH']; temp_index = 0; temp_value = result[calDH]; index = 0; - $.each(mapping_hash,function(k,v){ - if( i == 0 ){ - var index_val = v.indexOf(temp_value); - if( index_val != -1 ){ - temp_index = index_val; - }else{ - closest_value = v.get_nearest_value(temp_value); - temp_index = v.indexOf(closest_value) - } - } - result[k] = v[temp_index]; - index++; - }); + $.each(mapping_hash,function(k,v){ + if( i == 0 ){ + var index_val = v.indexOf(temp_value); + if( index_val != -1 ){ + temp_index = index_val; + }else{ + closest_value = v.get_nearest_value(temp_value); + temp_index = v.indexOf(closest_value) + } + } + result[k] = v[temp_index]; + index++; + }); result['fat'] = Number(result_json['fat']); mapping_hash = mapping_data_from_csv['fat']; temp_index = 0; temp_value = result[fat]; index = 0; - $.each(mapping_hash,function(k,v){ - if( i == 0 ){ - var index_val = v.indexOf(temp_value); - if( index_val != -1 ){ - temp_index = index_val; - }else{ - closest_value = v.get_nearest_value(temp_value); - temp_index = v.indexOf(closest_value) - } - } - result[k] = v[temp_index]; - index++; - }); + $.each(mapping_hash,function(k,v){ + if( i == 0 ){ + var index_val = v.indexOf(temp_value); + if( index_val != -1 ){ + temp_index = index_val; + }else{ + closest_value = v.get_nearest_value(temp_value); + temp_index = v.indexOf(closest_value) + } + } + result[k] = v[temp_index]; + index++; + }); result['N4'] = (2 - Number(result_json['N4'])); - result['O20'] = (2 - Number(result_json['O20'])); - result['O18'] = (2 - Number(result_json['O18'])); result['N12'] = (2 - Number(result_json['N12'])); result['N20'] = (2 - Number(result_json['N20'])); result['N31'] = (2 - Number(result_json['N31'])); result['O6'] = (2 - Number(result_json['O6'])); result['N34'] = (2 - Number(result_json['N34'])); - result['N46'] = (2 - Number(result_json['N46'])); result['N14'] = (2 - Number(result_json['N14'])); - result['N29'] = (2 - Number(result_json['N29'])); - result['N2'] = (2 - Number(result_json['N2'])); result['N26'] = (2 - Number(result_json['N26'])); + result['O3'] = (2 - Number(result_json['O3'])); + result['O20'] = (2 - Number(result_json['O20'])); + result['O18'] = (2 - Number(result_json['O18'])); result['O11'] = (2 - Number(result_json['O11'])); + result['N29'] = (2 - Number(result_json['N29'])); result['N6'] = (2 - Number(result_json['N6'])); result['O14'] = (2 - Number(result_json['O14'])); result['N43'] = (2 - Number(result_json['N43'])); - result['O3'] = (2 - Number(result_json['O3'])); result['O17'] = (2 - Number(result_json['O17'])); result['O9'] = (2 - Number(result_json['O9'])); - try{ - result['lpv'] = (A = 0.1327868* (result["sex_value"]- 0.4858824) + 0.0371720* (result["age_test1"] - 61.56000) -0.07447278* (result["age_test2"] - 13.10152) + 0.4315686* (result["age_test3"] - 0.9844332) + 0.0009163615*( result["calH_test1"] - 182.9347) -0.0007536899*( result["calH_test2"] - 124.8706) -0.0004697183*( result["calH_test3"] -80.75636) + 0.0001401325*( result["calAH_test1"] - 700.7824) -0.001349783*( result["calAH_test2"] - 634.2167) +0.001753832*( result["calAH_test3"] -419.3361) + 0.0001906046*( result["calDH_test1"] -835.2894) -0.000251567*( result["calDH_test2"] - 213.1630) -0.002173942*( result["fat_test1"] -108.4149)+0.003066541*( result["fat_test2"] - 28.33497) +0.6700708*(result["N4"]-0.3241176) +0.3336162*(result["O3"]-0.4994118) +0.1322476*(result["O20"]-0.1741176) +0.9084972*(result["O18"]-0.008823529) +0.2978388*(result["N12"]-0.1152941) +0.1777935*(result["N20"]-0.3582353) +1.588042*(result["N31"]-0.002352941) +0.2197419*(result["O6"]-0.07823529) +1.791159*(result["N34"]-0.001176471) -14.02639*(result["N46"]-0.003529412) +0.4305973*(result["N14"]-0.02176471) -0.4472885*(result["N29"]-0.02411765) -1.570431*(result["N20"]-0.0005882353) +0.2601319*(result["N26"]-0.04941176) -0.2364269*(result["O11"]-0.1164706) +0.1784179*(result["N6"]-0.1070588) +0.6023170*(result["O14"]-0.01294118) -1.031959*(result["N43"]-0.007058824) +0.4257809*(result["O17"]-0.01823529) +0.2002546*(result["O9"]-0.06176471)); - }catch(e){result['lpv'] = "error"}; - console.log(result['lpv']); - result['lpv_variable']['A'] = A; - return result; - }; - function calculate_and_change_result_value(obj){ - obj.servive_ratio_arr = []; - for(var i = 0;i