search for: date_trunc

Displaying 4 results from an estimated 4 matches for "date_trunc".

2012 Jan 22
4
undefined method `gsub!' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span
...= Chronic.parse(the_date, :guess => false) reports.sum_distance_by_date(date_range).each do |d| u[:m] << d end def self.sum_distance_by_date(time) time = time ? Date.parse(time) : Date.today.to_s reports = find_by_sql(["SELECT date_trunc(''day'', time), SUM(distance * 0.000621371192) AS sum FROM reports WHERE \"time\" = ? GROUP BY date_trunc(''day'', time)", time]) reports end Basically Chronic returns a range back, and I just want to be able to use that result inside the find_b...
2006 Feb 28
5
Problem with paginate, include and foreign keys
...t, ... foreign key (start_date_id) references start_dates (id), primary key (id) ); class StartDate < ActiveRecord::Base has_many :schedules end class Schedule < ActiveRecord::Base belongs_to :start_date end The ActiveRecord portion works as expected: condition = "date_trunc(''day'', start_date) between date(?) and date(?) - 1" Schedule.find( :all, :include => ''start_date'', :conditions => [condition, first,last] ) However, in schedules_controller.rb, this fails: @schedule_pages, @schedules = paginate( :sch...
2010 Mar 10
3
Help with aggregate and cor
...proach the following problem in R. I have observations of pairs of variables, v1, o1, v2, o2, etc, observed every 30 seconds. What I would like to do is compute the correlation matrix, but not for all my data, just for, say 5 minutes or 1 hour chunks. In sql, what I would say is select id, date_trunc('hour'::text, ts) as tshour, corr(n1,o1) as corr1 from raw30s where id = 1201087 and (ts between 'Mar 1, 2007' and 'Apr 1, 2007') group by id,tshour order by id,tshour; I've pulled data from PostgreSQL into R, and have a dataframe containing a...
2011 Dec 01
2
R, PostgresSQL and poor performance
...My query / code are as below # ----------------------------- library(''RPostgreSQL'') drv <- dbDriver("PostgreSQL") dbh <- dbConnect(drv,user="…",password="…",dbname="…",host="…") sql <- "select id, date, lon, lat, date_trunc(''day'' , date) as jday, extract(''hour'' from date) as hour, extract(''year'' from date) as year from observations where pt = 6 and date >= ''1990-01-01'' and date < ''1995-01-01'' and lon > 180 and lon < 2...