Created
June 19, 2012 14:41
-
-
Save ehogberg/2954573 to your computer and use it in GitHub Desktop.
Postgres Hstore
This file contains 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
class StatisticSummary < ActiveRecord::Base | |
attr_accessible :stats | |
belongs_to :domain | |
serialize :stats, ActiveRecord::Coders::Hstore | |
before_create :initialize_stats | |
private | |
def initialize_stats | |
r = Random.new | |
h = Hash.new | |
h.store "avg24h" , 24.times.collect {|i| r.rand(5.0).round(1)} | |
h.store "avg7d" , 7.times.collect {|i| r.rand(5.0).round(1)} | |
h.store "avg12h" , 12.times.collect {|i| r.rand(5.0).round(1)} | |
h.store "Vol24h", 24.times.collect {|i| r.rand(2000).round(0) + 50} | |
h.store "Vol7d", 7.times.collect {|i| 24 * (r.rand(2000).round(0) + 50)} | |
h.store "Vol12m", 12.times.collect {|i| (24 * 28) * (r.rand(2000).round(0) + 50 )} | |
self.stats = h | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment