def chart_values(options = {}) sensor_unit = options[:sensor_unit] database_name = options[:database_name] description = options[:description] start_date = options[:start_date].to_time.to_s(:db) end_date = options[:end_date].to_time.to_s(:db) fahrenheit = (sensor_unit == "F" ? true : false) sql = " SELECT *, DATE_FORMAT(date, '%d-%m-%Y %H:%i:%s') AS date_f, DATE_FORMAT(date, '%Y%m%d%H%i%s') AS timestamp FROM #{database_name}.log WHERE channel_description = '#{description}' AND date BETWEEN '#{start_date}' AND '#{end_date}' AND mission_number = 0 GROUP BY date ORDER BY date ASC, serial_number ASC " # fetches the cache and if the cache is available returns that otherwise creates cached # version of this query # # # uses the params to give unique identifier to the cac # # cached content Rails.cache.fetch("#{sensor_unit}-#{database_name}-#{description}-#{start_date}-#{end_date}") do logs = Log.find_by_sql(sql) values = [] logs.each do |log| channel_value = log.channel_value channel_value = (fahrenheit == true ? ((channel_value * 9 / 5) + 32) : ((channel_value.to_f * 10).floor / 10.0)) value = { :description => log.channel_description, :record_type => log.type, :value => channel_value, :display_date => log.date, :date => log.date, :timestamp => log.timestamp } values << value unless values.detect { |v| v == value } end values end end