Class: CrePropertyMatcher::PropertyMatcher
Instance Attribute Summary collapse
Instance Method Summary
collapse
#get_average_by_attribute, #get_average_by_reference_property_state, #get_average_by_reference_property_state_and_property_type, #get_average_for_all_by_property_type
Constructor Details
#initialize(reference_property) ⇒ PropertyMatcher
Returns a new instance of PropertyMatcher.
11
12
13
14
15
16
|
# 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
|
Instance Attribute Details
#comparison_properties ⇒ Object
Returns the value of attribute comparison_properties.
9
10
11
|
# File 'lib/cre_property_matcher.rb', line 9
def comparison_properties
@comparison_properties
end
|
#reference_property ⇒ Object
Returns the value of attribute reference_property.
9
10
11
|
# File 'lib/cre_property_matcher.rb', line 9
def reference_property
@reference_property
end
|
Instance Method Details
#calculate_distances ⇒ Object
86
87
88
89
|
# File 'lib/cre_property_matcher.rb', line 86
def calculate_distances
props = get_suitable_comps
reference.calculate_distance_from_neighbors(props, features, scales)
end
|
#comps ⇒ Object
22
23
24
|
# File 'lib/cre_property_matcher.rb', line 22
def comps
@comparison_properties
end
|
#features ⇒ Object
44
45
46
|
# File 'lib/cre_property_matcher.rb', line 44
def features
@features
end
|
#filter_by_feature(feature) ⇒ Object
68
69
70
71
72
73
74
|
# 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) ⇒ Object
95
96
97
|
# File 'lib/cre_property_matcher.rb', line 95
def get_k_nearest(k = 3)
sort_comps_by_distance.take(k)
end
|
#get_suitable_comps ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# 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) ⇒ Object
52
53
54
55
56
57
58
|
# 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 ⇒ Object
60
61
62
63
64
65
66
|
# 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 ⇒ Object
18
19
20
|
# File 'lib/cre_property_matcher.rb', line 18
def reference
@reference_property
end
|
#scale_features ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/cre_property_matcher.rb', line 76
def scale_features
scales = {}
features.each do |feature|
array = filter_by_feature(feature).compact
scales[feature] = {min: array.min, max: array.max, range: array.max - array.min}
end
scales
end
|
#scales ⇒ Object
48
49
50
|
# File 'lib/cre_property_matcher.rb', line 48
def scales
@scales
end
|
#sort_comps_by_distance ⇒ Object
91
92
93
|
# File 'lib/cre_property_matcher.rb', line 91
def sort_comps_by_distance
comps.sort { |a, b| a.distance <=> b.distance }
end
|