Class: Heart::MetricsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/heart/metrics_controller.rb

Instance Method Summary collapse

Instance Method Details

#fetchObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/heart/metrics_controller.rb', line 17

def fetch
  method = "fetch_" + params[:attribute].to_s
  params[:enddate] = (params[:enddate].nil?) ? params[:fulldate] : params[:enddate]
  startdate = Date.parse(params[:fulldate].to_s)
  enddate = Date.parse(params[:enddate].to_s)
  startdate.upto(enddate) do |date|
    @metric = Heart::Metric.find_or_create(date,0)
    isometric = Heart::Isometric.find_or_create(date,0)

    @metric.send(method)

    @metric.save
    isometric.send(params[:attribute.to_s]+"=", Time.now) unless method == "fetch_all"
    isometric.save unless method == "fetch_all"
  end
end

#indexObject



6
7
8
# File 'app/controllers/heart/metrics_controller.rb', line 6

def index
  @metrics = Heart::Metric.recently_added
end

#showObject



10
11
12
13
14
15
# File 'app/controllers/heart/metrics_controller.rb', line 10

def show
  #restrict the range of dates to prevent a lot useless metric records
  params[:fulldate] = Date.yesterday unless params[:fulldate] <= Date.yesterday.to_s
  @metric = Heart::Metric.find_or_create(params[:fulldate],0)
  @isometric = Heart::Isometric.find_or_create(params[:fulldate],0)
end