Last active
December 11, 2015 11:08
-
-
Save dmichael/4591766 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'squeel' | |
| class RealtimeMessage < ActiveRecord::Base | |
| # These attributes are "mass-assignable", that is, they come in directly from the serial port as XML | |
| attr_accessible :src, :dsb, :time, :tmprF, :sensor_num, :sensor_type, :radio_id, :ch1_watts, :ch2_watts, :ch3_watts, :mac_address | |
| def self.this_month | |
| now = Time.now | |
| first_of_month = Date.civil(now.year, now.month, 1) | |
| last_of_month = Date.civil(now.year, now.month, -1) | |
| self.where { # select all the records for this month (inclusive) | |
| (created_at >= first_of_month) & (created_at <= last_of_month) | |
| } | |
| .where { # Filter out bad records (which happens) | |
| (ch1_watts.not_eq nil) | (ch2_watts.not_eq nil) | (ch3_watts.not_eq nil) | |
| } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment