Fix bug.
This commit is contained in:
parent
96465e34f3
commit
360a86fecd
|
@ -679,108 +679,4 @@ class Admin::CancerpredictsController < OrbitAdminController
|
|||
return {}
|
||||
end
|
||||
end
|
||||
def auto_write_predict_js
|
||||
js_code = "var map_values , mapping_hash , temp_index ,temp_value , index , closest_value;\r\n"
|
||||
mapping_data_from_csv = YAML.load(@form_to_show.mapping_data_from_csv) rescue {}
|
||||
#js_code += "\t\t\t\tvar mapping_data_from_csv = #{mapping_data_from_csv.to_s.gsub("=>",":")};\r\n"
|
||||
variable_keys = []
|
||||
@form_to_show.form_show.each do |num,property|
|
||||
@variable = property[:variable]
|
||||
if @variable.present?
|
||||
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
|
||||
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
|
||||
if property[:revert_value].to_i != 1
|
||||
js_code += "\t\t\t\tresult['#{@variable}'] = Number(result_json['#{@variable}']) - 1;\r\n"
|
||||
else
|
||||
js_code += "\t\t\t\tresult['#{@variable}'] = (#{property[:choice_fields].length} - Number(result_json['#{@variable}']));\r\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
variable_keys.push(@variable)
|
||||
if property[:cancer_predict_mapping_file].present?
|
||||
if (mapping_data_from_csv != {} && !mapping_data_from_csv[@variable].blank?)
|
||||
variable_keys.concat(mapping_data_from_csv[@variable].keys)
|
||||
js_code += "\t\t\t\tmapping_hash = mapping_data_from_csv['#{@variable}'];\r\n"
|
||||
js_code += "\t\t\t\ttemp_index = 0;\r\n"
|
||||
js_code += "\t\t\t\ttemp_value = result[#{@variable}];\r\n"
|
||||
js_code += "\t\t\t\tindex = 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++;
|
||||
});\r\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
formula = @form_to_show.prediction_formula.gsub("\r\n"," ").gsub("^","**")
|
||||
variable_keys.each do |k|
|
||||
formula = formula.gsub(/#{k}?(-|\+|\*|\s|\=)/){ "result[\"#{k}\"]#{$1}" }
|
||||
end
|
||||
formula_variables = formula.enum_for(:scan,/([^\=]*)?=/).map { Regexp.last_match[1] }.map{|s| s.strip.split(/(\s*|;\r\n)/).last}
|
||||
js_code = "function calculate_first_lpv(result_json){
|
||||
result = {};
|
||||
#{js_code}
|
||||
try{
|
||||
result['lpv'] = (#{formula});
|
||||
}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") }
|
||||
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]));
|
||||
};"
|
||||
@years = @form_to_show.years
|
||||
switch_texts = "
|
||||
#{formula_variables.map{|v| "var #{v} = obj['#{v}'];"}.join("\r\n\t\t\t\t")}
|
||||
switch(year) {"
|
||||
@years.each do |year|
|
||||
year_index = @years.index(year)
|
||||
switch_texts +=
|
||||
"
|
||||
case '#{year}':
|
||||
servive_ratio = #{@form_to_show.years_settings[year_index].gsub('^','**').gsub('exp','Math.exp')};
|
||||
break;
|
||||
"
|
||||
end
|
||||
switch_texts += "
|
||||
default:
|
||||
console.log('not found year.');
|
||||
}"
|
||||
js_code = js_code +"
|
||||
|
||||
function calculate_servive_ratio(year,obj){
|
||||
var servive_ratio;
|
||||
#{switch_texts}
|
||||
return servive_ratio;
|
||||
}
|
||||
"
|
||||
return js_code
|
||||
end
|
||||
end
|
|
@ -64,7 +64,11 @@ class CancerpredictsController < ApplicationController
|
|||
@variable = property[:variable]
|
||||
if @variable.present?
|
||||
if property[:is_num] == 1
|
||||
result[@variable] = params['data'][@variable].to_f rescue 0.0
|
||||
if property[:is_float] == 1
|
||||
result[@variable] = params['data'][@variable].to_f rescue 0.0
|
||||
else
|
||||
result[@variable] = params['data'][@variable].to_i rescue 0
|
||||
end
|
||||
elsif property[:choice_fields].present?
|
||||
if property[:map_values].class == Array && property[:choice_fields].class == Array && property[:map_values].length == property[:choice_fields].length
|
||||
result[@variable] = property[:map_values][params['data'][@variable].to_i - 1]
|
||||
|
|
|
@ -103,6 +103,9 @@ class Cancerpredictfields
|
|||
scope :is_approved, ->{where(:approved => true)}
|
||||
#before_create :set_expire
|
||||
before_save do
|
||||
self.form_show.each do |num,property|
|
||||
property[:need_map_values] = (property[:map_values].class == Array && property[:choice_fields].class == Array && property[:map_values].length == property[:choice_fields].length) ? 1 : 0
|
||||
end
|
||||
result_keys = []
|
||||
self.form_show.each do |num,property|
|
||||
variable_name = property[:variable]
|
||||
|
@ -173,7 +176,7 @@ class Cancerpredictfields
|
|||
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
|
||||
if property[:revert_value].to_i != 1
|
||||
if property[:revert_value] != 1
|
||||
js_code += "\t\t\t\tresult['#{@variable}'] = Number(result_json['#{@variable}']) - 1;\r\n"
|
||||
else
|
||||
js_code += "\t\t\t\tresult['#{@variable}'] = (#{property[:choice_fields].length} - Number(result_json['#{@variable}']));\r\n"
|
||||
|
|
Loading…
Reference in New Issue