Skip to content

Instantly share code, notes, and snippets.

@ehogberg
Created June 19, 2012 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehogberg/2954573 to your computer and use it in GitHub Desktop.
Save ehogberg/2954573 to your computer and use it in GitHub Desktop.
Postgres Hstore
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