class CrePropertyMatcher::PropertyMatcher
Attributes
comparison_properties[RW]
reference_property[RW]
Public Class Methods
new(reference_property)
click to toggle source
# File lib/cre_property_matcher.rb, line 11 def initialize(reference_property) @reference_property = Property.new(reference_property) @comparison_properties = PropertyDataLoader.run_and_return_properties @features = [:@appraised_value, :@noi, :@ncf, :@uw_revenue, :@uw_expenses] @scales = scale_features end
Public Instance Methods
calculate_distances()
click to toggle source
# File lib/cre_property_matcher.rb, line 88 def calculate_distances props = get_suitable_comps reference.calculate_distance_from_neighbors(props, features, scales) end
comps()
click to toggle source
# File lib/cre_property_matcher.rb, line 22 def comps @comparison_properties end
features()
click to toggle source
# File lib/cre_property_matcher.rb, line 44 def features @features end
filter_by_feature(feature)
click to toggle source
# File lib/cre_property_matcher.rb, line 68 def filter_by_feature(feature) result = [] comps.each do |property| result << property.instance_variable_get(feature) end result end
get_k_nearest(k = 3)
click to toggle source
# File lib/cre_property_matcher.rb, line 97 def get_k_nearest(k = 3) sort_comps_by_distance.take(k) end
get_suitable_comps()
click to toggle source
# File lib/cre_property_matcher.rb, line 26 def get_suitable_comps suitable = [] comps.each do |property| all_features_not_nil = true features.each do |feature| unless property.instance_variable_get(feature) all_features_not_nil = false end end if all_features_not_nil suitable << property end end suitable end
head_comparison_properties(n = 6)
click to toggle source
# File lib/cre_property_matcher.rb, line 52 def head_comparison_properties(n = 6) result = [] 1.upto(n) do |index| result << comps[index] end result end
property_type_count()
click to toggle source
# File lib/cre_property_matcher.rb, line 60 def property_type_count count_hash = Hash.new(0) @comparison_properties.each do |property| count_hash[property.general_property_type] += 1 end count_hash end
reference()
click to toggle source
# File lib/cre_property_matcher.rb, line 18 def reference @reference_property end
scale_features()
click to toggle source
# File lib/cre_property_matcher.rb, line 76 def scale_features scales = {} features.each do |feature| array = filter_by_feature(feature).compact # p array scales[feature] = {min: array.min, max: array.max, range: array.max - array.min} end scales end
scales()
click to toggle source
# File lib/cre_property_matcher.rb, line 48 def scales @scales end
sort_comps_by_distance()
click to toggle source
# File lib/cre_property_matcher.rb, line 93 def sort_comps_by_distance comps.sort { |a, b| a.distance <=> b.distance } end