Fix js contents.
This commit is contained in:
parent
a56f6ba5e3
commit
9d2872b884
|
@ -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<obj.active_treatment.length;i++){
|
||||
var servive_ratio = round((1-(calculate_servive_ratio(obj.year,obj.lpv_real[i])))*100,2);
|
||||
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.'+obj.active_treatment[i]+' td.Additional_Benefit').html(round(benefit,2)+'%');
|
||||
$('.'+obj.active_treatment[i]+'.Additional_Benefit').html(Math.round(benefit));
|
||||
}
|
||||
}
|
||||
//$('.'+obj.active_treatment[0]+'.Overall_Survival').html(Math.round(obj.servive_ratio_arr[0]));
|
||||
};
|
||||
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.00004697183*( 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) +0.4305973*(result["N14"]-0.02176471) -0.4472885*(result["N29"]-0.02411765) +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<obj.active_treatment.length;i++){
|
||||
var servive_ratio = round((1-(calculate_servive_ratio(obj.year,obj.lpv_real[i])))*100,2);
|
||||
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.'+obj.active_treatment[i]+' td.Additional_Benefit').html(round(benefit,2)+'%');
|
||||
$('.'+obj.active_treatment[i]+'.Additional_Benefit').html(Math.round(benefit));
|
||||
}
|
||||
}
|
||||
//$('.'+obj.active_treatment[0]+'.Overall_Survival').html(Math.round(obj.servive_ratio_arr[0]));
|
||||
};
|
||||
|
||||
function calculate_servive_ratio(year,obj){
|
||||
var servive_ratio;
|
||||
|
||||
var A = obj['A'];
|
||||
switch(year) {
|
||||
case '1':
|
||||
servive_ratio = 0.8095037**( Math.exp(A) );
|
||||
break;
|
||||
|
||||
case '1.5':
|
||||
servive_ratio = 0.729158**( Math.exp(A) );
|
||||
break;
|
||||
|
||||
case '2':
|
||||
servive_ratio = 0.6717211**( Math.exp(A) );
|
||||
break;
|
||||
|
||||
case '2.5':
|
||||
servive_ratio = 0.6056773**( Math.exp(A) );
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('not found year.');
|
||||
}
|
||||
return servive_ratio;
|
||||
}
|
||||
/* auto add end */
|
||||
function calculate_servive_ratio(year,obj){
|
||||
var servive_ratio;
|
||||
var A = obj['A'];
|
||||
switch(year) {
|
||||
case '1':
|
||||
servive_ratio = 0.8095037**( Math.exp(A) );
|
||||
break;
|
||||
case '1.5':
|
||||
servive_ratio = 0.729158**( Math.exp(A) );
|
||||
break;
|
||||
case '2':
|
||||
servive_ratio = 0.6717211**( Math.exp(A) );
|
||||
break;
|
||||
case '2.5':
|
||||
servive_ratio = 0.6056773**( Math.exp(A) );
|
||||
break;
|
||||
default:
|
||||
console.log('not found year.');
|
||||
}
|
||||
return servive_ratio;
|
||||
}
|
||||
/* auto add end */
|
||||
function submit_fcn(){
|
||||
var post_json = get_input_data();
|
||||
if(post_json != null){
|
||||
|
|
|
@ -191,7 +191,7 @@ class Cancerpredictfields
|
|||
if property[:is_num] == 1
|
||||
js_code += "\t\t\t\tresult['#{@variable}'] = Number(result_json['#{@variable}']);\r\n"
|
||||
elsif property[:choice_fields].present?
|
||||
if property[:map_values].class == Array && property[:choice_fields].class == Array && property[:map_values].length == property[:choice_fields].length
|
||||
if property[:need_map_values] == 1
|
||||
js_code += "\t\t\t\tmap_values = #{property[:map_values]};\r\n"
|
||||
js_code += "\t\t\t\tresult['#{@variable}'] = map_values[Number(result_json['#{@variable}'']) - 1];\r\n"
|
||||
else
|
||||
|
@ -236,7 +236,7 @@ class Cancerpredictfields
|
|||
result = {};
|
||||
#{js_code}
|
||||
try{
|
||||
result['lpv'] = (#{formula});
|
||||
result['lpv'] = (#{formula.gsub(/\s{2,10}/," ")});
|
||||
}catch(e){result['lpv'] = \"error\"};
|
||||
console.log(result['lpv']);
|
||||
#{formula_variables.map{|v| "result['lpv_variable']['#{v}'] = #{v};"}.join("\r\n\t\t\t\t") }
|
||||
|
@ -259,26 +259,24 @@ class Cancerpredictfields
|
|||
};"
|
||||
@years = self.years
|
||||
switch_texts = "
|
||||
#{formula_variables.map{|v| "var #{v} = obj['#{v}'];"}.join("\r\n\t\t\t\t")}
|
||||
switch(year) {"
|
||||
#{formula_variables.map{|v| "var #{v} = obj['#{v}'];"}.join("\n ")}
|
||||
switch(year) {"
|
||||
@years.each do |year|
|
||||
year_index = @years.index(year)
|
||||
switch_texts +=
|
||||
"
|
||||
case '#{year}':
|
||||
servive_ratio = #{self.tmp_years_settings[year_index]};
|
||||
break;
|
||||
"
|
||||
case '#{year}':
|
||||
servive_ratio = #{self.tmp_years_settings[year_index]};
|
||||
break;"
|
||||
end
|
||||
switch_texts += "
|
||||
default:
|
||||
console.log('not found year.');
|
||||
}"
|
||||
default:
|
||||
console.log('not found year.');
|
||||
}"
|
||||
js_code = js_code +"
|
||||
|
||||
function calculate_servive_ratio(year,obj){
|
||||
var servive_ratio;
|
||||
#{switch_texts}
|
||||
var servive_ratio;#{switch_texts}
|
||||
return servive_ratio;
|
||||
}
|
||||
"
|
||||
|
|
Loading…
Reference in New Issue