Class: Recorder::Application

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/application.rb

Instance Method Summary collapse

Instance Method Details

#get_data(period = :whole) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/application.rb', line 120

def get_data(period=:whole)
  @data = Data.order('created_at DESC')
  weight_data,bodyfat_data=[],[]
  today = Date.today
  week_before=Time.parse((today-7).strftime)
  month_before=Time.parse((today-28).strftime)
  recent=Time.parse('2016-8-26')
  @data.each{|d|
    case period
    when :whole
    when :recent
      next if d.date < recent
    when :week
      next if d.date < week_before
    when :month
      next if d.date < month_before
    end
    weight_data << [d.date,d.weight]
    bodyfat_data << [d.date,d.bodyfat]
  }
  return weight_data,bodyfat_data
end