poormans_trends 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/helpers/poormans_trends/home_helper.rb +12 -1
- data/lib/poormans_trends/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d018821162681b694a444515295d402d93e8e6d
|
|
4
|
+
data.tar.gz: dc4b4029504c0f1971728cb8eef61b6f37a3c2f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ca116d70ee840bf9679aaf503f4a7320fc474ef61c9878d2f139dcd5eafe94310ece234a19107957d70608788a5c9a92b6ec5f711ec3fb9f4f5f0f36680c9b6
|
|
7
|
+
data.tar.gz: ae73a49f8e49d4966c1615488355e1f2fab16f4e5dcdb5669e836d37a95ae41c0b4f07918ce66aa071c4abde2ea720a8bb6f796577621f11204011c96424e946
|
|
@@ -12,9 +12,20 @@ module PoormansTrends
|
|
|
12
12
|
}.sort {|a,b| b.count <=> a.count}
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
def group_by_date_sql(colname)
|
|
16
|
+
case ActiveRecord::Base.connection
|
|
17
|
+
when ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
|
18
|
+
"#{colname}::date"
|
|
19
|
+
when ActiveRecord::ConnectionAdapters::MysqlAdapter
|
|
20
|
+
"DATE(#{colname})"
|
|
21
|
+
else
|
|
22
|
+
raise Exception.new("Unsupported adapter: #{ActiveRecord::Base.connection.class.name}")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
15
26
|
def data_for(klass, colname, start_at, end_at = 1.day.ago)
|
|
16
27
|
timezone_offset = nil
|
|
17
|
-
db = klass.where("#{colname} >= ?", start_at).group(
|
|
28
|
+
db = klass.where("#{colname} >= ?", start_at).group(group_by_date_sql(colname)).count.inject({}) do |sum,(k,v)|
|
|
18
29
|
timezone_offset ||= k.to_time.beginning_of_day - Time.zone.parse(k.to_s).beginning_of_day
|
|
19
30
|
sum.merge(k.to_time.to_i * 1000 => v)
|
|
20
31
|
end
|