Class: Pacing::Normalizer
- Inherits:
-
Object
- Object
- Pacing::Normalizer
- Defined in:
- lib/pacing/normalizer.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#services ⇒ Object
Returns the value of attribute services.
Instance Method Summary collapse
- #active_services(services) ⇒ Object
- #discipline_data(services, discipline) ⇒ Object
- #disciplines_cleaner(disciplines) ⇒ Object
- #feeding_discipline ⇒ Object
-
#initialize(services, date) ⇒ Normalizer
constructor
A new instance of Normalizer.
- #normalize ⇒ Object
- #normalize_to_monthly_frequency(services) ⇒ Object
- #occupational_discipline ⇒ Object
- #parse_date(date) ⇒ Object
- #physical_discipline ⇒ Object
- #same_interval(services) ⇒ Object
- #speech_discipline ⇒ Object
Constructor Details
#initialize(services, date) ⇒ Normalizer
Returns a new instance of Normalizer.
9 10 11 12 |
# File 'lib/pacing/normalizer.rb', line 9 def initialize(services, date) @date = date @services = active_services(services) end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
7 8 9 |
# File 'lib/pacing/normalizer.rb', line 7 def date @date end |
#services ⇒ Object
Returns the value of attribute services.
7 8 9 |
# File 'lib/pacing/normalizer.rb', line 7 def services @services end |
Instance Method Details
#active_services(services) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/pacing/normalizer.rb', line 198 def active_services(services) services.filter do |school_plan_service| within = true begin if !(parse_date(school_plan_service[:start_date]) <= parse_date(date) && parse_date(date) <= parse_date(school_plan_service[:end_date])) within = false end rescue => exception end within end end |
#discipline_data(services, discipline) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/pacing/normalizer.rb', line 118 def discipline_data(services, discipline) services.each do |service| discipline[:start_date] = parse_date(service[:start_date]) < parse_date(discipline[:start_date]) ? service[:start_date] : discipline[:start_date] discipline[:end_date] = parse_date(service[:end_date]) > parse_date(discipline[:end_date]) ? service[:end_date] : discipline[:end_date] discipline[:frequency] += service[:frequency].to_i discipline[:completed_visits_for_current_interval] = service[:completed_visits_for_current_interval] if service[:completed_visits_for_current_interval] > discipline[:completed_visits_for_current_interval] discipline[:time_per_session_in_minutes] = service[:time_per_session_in_minutes] > discipline[:time_per_session_in_minutes] ? service[:time_per_session_in_minutes] : discipline[:time_per_session_in_minutes] discipline[:interval] = service[:interval] discipline[:extra_sessions_allowable] += service[:extra_sessions_allowable].to_i discipline[:interval_for_extra_sessions_allowable] = service[:interval_for_extra_sessions_allowable] end discipline end |
#disciplines_cleaner(disciplines) ⇒ Object
193 194 195 196 |
# File 'lib/pacing/normalizer.rb', line 193 def disciplines_cleaner(disciplines) # use the fake arbitrary reset date to remove unrequired disciplines disciplines.filter { |discipline| !discipline.empty? } end |
#feeding_discipline ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/pacing/normalizer.rb', line 93 def feeding_discipline discipline = { :school_plan_type => 'IEP', :start_date => "01-01-2100", # some arbitrary start date :end_date => "01-01-2000", # some arbitrary end date :type_of_service => 'Feeding Therapy', :frequency => 0, :interval => '', :time_per_session_in_minutes => 0, :completed_visits_for_current_interval => 0, :extra_sessions_allowable => 0, :interval_for_extra_sessions_allowable => '' } discipline_services = services.filter do |service| ["feeding therapy", "feeding"].include?(service[:type_of_service].downcase) end return {} if discipline_services.empty? discipline_services = normalize_to_monthly_frequency(discipline_services) discipline_data(discipline_services, discipline) end |
#normalize ⇒ Object
14 15 16 |
# File 'lib/pacing/normalizer.rb', line 14 def normalize { school_plan_services: disciplines_cleaner([speech_discipline, occupational_discipline, physical_discipline, feeding_discipline]) } end |
#normalize_to_monthly_frequency(services) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/pacing/normalizer.rb', line 154 def normalize_to_monthly_frequency(services) # average business days for each interval interval_average_days = { "weekly" => 5, "per week" => 5, "monthly" => 22, "per month" => 22, "yearly" => 210, "per year" => 210 # take away average holidays period with is 2.5 months } return services if same_interval(services) services.map do |service| if !(service[:interval] == "monthly") # weekly(5 days) = frequency # weekly # monthly(20 days) = frequency * monthly # yearly(200 days) f = service[:frequency] service[:frequency] = ((service[:frequency] * interval_average_days["monthly"].to_f) / interval_average_days[service[:interval]]).round service[:interval] = "monthly" end service end services end |
#occupational_discipline ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pacing/normalizer.rb', line 43 def occupational_discipline discipline = { :school_plan_type => 'IEP', :start_date => "01-01-2100", # some arbitrary start date :end_date => "01-01-2000", # some arbitrary end date :type_of_service => 'Occupational Therapy', :frequency => 0, :interval => '', :time_per_session_in_minutes => 0, :completed_visits_for_current_interval => 0, :extra_sessions_allowable => 0, :interval_for_extra_sessions_allowable => '' } discipline_services = services.filter do |service| ["occupation therapy", "occupational therapy", "occupation"].include?(service[:type_of_service].downcase) end return {} if discipline_services.empty? discipline_services = normalize_to_monthly_frequency(discipline_services) discipline_data(discipline_services, discipline) end |
#parse_date(date) ⇒ Object
186 187 188 189 190 191 |
# File 'lib/pacing/normalizer.rb', line 186 def parse_date(date) begin Date.strptime(date, '%m-%d-%Y') rescue => exception end end |
#physical_discipline ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pacing/normalizer.rb', line 68 def physical_discipline discipline = { :school_plan_type => 'IEP', :start_date => "01-01-2100", # some arbitrary start date :end_date => "01-01-2000", # some arbitrary end date :type_of_service => 'Physical Therapy', :frequency => 0, :interval => '', :time_per_session_in_minutes => 0, :completed_visits_for_current_interval => 0, :extra_sessions_allowable => 0, :interval_for_extra_sessions_allowable => '' } discipline_services = services.filter do |service| ["physical therapy", "physical"].include?(service[:type_of_service].downcase) end return {} if discipline_services.empty? discipline_services = normalize_to_monthly_frequency(discipline_services) discipline_data(discipline_services, discipline) end |
#same_interval(services) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/pacing/normalizer.rb', line 140 def same_interval(services) interval = services[0].nil? ? "" : services[0][:interval] same = true services.each do |service| if interval != service[:interval] # puts "this happened for real? interval #{interval} and service interval #{service[:interval]} #{services}" same = false end end same end |
#speech_discipline ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pacing/normalizer.rb', line 18 def speech_discipline discipline = { :school_plan_type => 'IEP', :start_date => "01-01-2100", # some arbitrary start date :end_date => "01-01-2000", # some arbitrary end date :type_of_service => 'Speech Therapy', :frequency => 0, :interval => '', :time_per_session_in_minutes => 0, :completed_visits_for_current_interval => 0, :extra_sessions_allowable => 0, :interval_for_extra_sessions_allowable => '' } discipline_services = services.filter do |service| ["pragmatic language", "speech and language", "language", "speech", "language therapy", "speech therapy", "speech and language therapy", "speech language therapy"].include?(service[:type_of_service].downcase) end return {} if discipline_services.empty? discipline_services = normalize_to_monthly_frequency(discipline_services) discipline_data(discipline_services, discipline) end |