class DangerSense::Detect_Danger

Public Class Methods

decision_tree() click to toggle source
# File lib/danger_sense.rb, line 7
def self.decision_tree
  repo_name = File.read("data/configuration_file.txt")

  write_code = '
    require "decisiontree"
  
    def threshold_reached
      repo_name = File.read("data/configuration_file.txt")
    
      system("git clone #{repo_name}")
    end
  
    input = File.read("data/decision_tree/input.txt").strip.to_f
    
    attribute = ["Danger"]
    
    training = [
      [13.75,      "Very Low"], [20.625, "Somewhat Low"], [27.5,     "Normal Low"],
      [37.3125,      "Medium"], [54.0,           "High"], [67.5,         "Urgent"],
      [81.0,         "Danger"], [94.5,       "Critical"], [108.0,     "Automatic"],
    ]
    
    dec_tree = DecisionTree::ID3Tree.new(attribute, training, 1, :continuous); dec_tree.train
    test = [input]
 
    decision      = dec_tree.predict(test)
    true_decision = test.last
    
    puts decision
    
    if decision == "Automatic"
      t = threshold_reached
    else
      puts "All things are accounted for..."
    end
  '
  
  open("danger_threshold.rb", "w") { |f|
    f.puts write_code
  }
  
  system("ruby danger_threshold.rb; shred --remove danger_threshold.rb")
end