diff --git a/app/controllers/admin/cancerpredicts_controller.rb b/app/controllers/admin/cancerpredicts_controller.rb index cd2f2eb..a6169eb 100644 --- a/app/controllers/admin/cancerpredicts_controller.rb +++ b/app/controllers/admin/cancerpredicts_controller.rb @@ -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{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"