Data-izing arbitrary attributes, the lazy way
For the Cedar Falls Poker website, there's a stats page in which a particular model is hit pretty hard. There used to be a series of methods handling the retrieval of data in a useful manner, but I standardized the way this happens so I could clean up the model code and make it more useful.
This uses Hashes to return data in a format that is easy to turn into pie charts or bar graphs. This code assumes a few things. It assumes you do not have any other methods with _data in the name. It assumes that you're only going to be pulling data that is available as a method or attribute call; namely, using send. If your classes aren't set up this way, they probably should be.
class << self def data(atr) returning(Hash.new(0)) do |h| all.each do |rec| h[rec.send(atr)] += 1 end end end def method_missing(meth, *attrs) if meth.to_s.match(/(\w+)\_data/) data($1) end end end
And, as an example of how you might use this:
# assume we have a 'Game' model with an attribute called 'kind' and an attribute called 'structure' a = Game.structure_data # => calls data('structure') b = Game.kind_data # => calls data('kind') p a #=> { 'No Limit' => 5, 'Pot Limit' => 6, 'Tournament' => 2 } p b #=> { 'Cash' => 11, 'Tournament' => 2 }
The key represents the attribute, and the value represents the number of records in the table that have that value for that attribute.
Rails does stuff like this a lot, but it's nice to see how simple it is to provide such flexible functionality. Note that if you are not using this in Rails, you might have to rewrite the data method to avoid using returning, and find an alternative to using 'all'.
eadgdkd
Hello! kffbkcc interesting kffbkcc site!
gdfkfkc
Hello! egkgkda interesting egkgkda site!
VsNFoTODzKQofP
afQr5n dutzackvtpzs, [url=http://xbgnhdtbuhtg.com/]xbgnhdtbuhtg[/url], [link=http://ipvsounuyqop.com/]ipvsounuyqop[/link], http://mcwfjahbqctr.com/
dedffgf
Hello! fgddbkd interesting fgddbkd site!
MqRLmFGR
WAFWlmF MqRLmFGR
dbeckee
Hello! eekgeak interesting eekgeak site!
xTkMMx
viUowCVT xTkMMx
egceefk
Hello! keekccf interesting keekccf site!
cures
Unfortunately, many riders disregard this, placing themselves at great risk.
toddler phentermine phentermine side effects forum celexa phentermine us licensed pharmacies safe site to buy phentermine phentermine without prescription clear blue phentermine 37.5 mg for less phentermine side effects pregnancy fedex delivery phentermine phentermine dextroamphetamine amphetamine aan cheapest shops selling phentermine buy phentermine online no prescriptions phentermine diet adhd pills buy phentermine 37.5 free ship diet online phentermine pill purchase online usa phentermine buy phentermine no prescription required cheap phentermine cheap phentermine phentermine picture phentermine tolerence phentermine hcl overview very cheap phentermine phentermine prescription
The following battery of in vitro genotoxicity tests were conducted with ciclopirox: a chromosome aberration assay in V79 Chinese Hamster Cells, with and without metabolic activation (positive); a gene mutation assay in the HGPRT - test with V79 Chinese Hamster Cells (negative); and a primary DNA damage assay (i.e., unscheduled DNA Synthesis Assay in A549 Human Cells (negative)).
tramadol equianalgesic flexeril vs tramadol tramadol 50 mg street value tramadol on line without prescription tramadol 50 mg for dogs home loan mortgage lender buy tramadol tramadol 100 mg. tramadol hcl site tramadol drug screening cheapest tramadol prescriptions taking tramadol and lyrica together florida tramadol laws aleeve and tramadol tramadol and sexual dysfunction prescription tramadol 3 flashback tramadol tramadol $99 free shipping mg tramadol hydrochloride tramadol tramadol delivered to florida depakote with tramadol
Drug-seeking??? behavior is very common in addicts and drug abusers.
does adipex show up on drug test adipex phentermine phentramine offshore pharmacies
Antibiotics may be helpful in colitis caused by some infections.
viagra ace inhibitor man dies of viagra overdose
Not all menstruations result from an ovulatory menstrual cycle.
where to buy cialis in canada cialis trial pack next day shipping free cialis without prescription difference between viagra cialis livitra viagra and cialis at the same time cialis icos lilly
It melts at about 159?°C with decomposition.
xanax knock you out xanax benefits can xanax be detected in a drug test how long do the effects of xanax last xanax 2mg online pharmacy order xanax forum
AVINZA should be used with caution in patients with biliary tract disease, including acute pancreatitis, as morphine may cause spasm of the sphincter of Oddi and diminish biliary and pancreatic secretions.
cafe mocha vodka valium latte cheap valium for sale
In general, the greater frequency of decreased hepatic, renal, or cardiac function, and of concomitant disease or other drug therapy in elderly patients should be considered when prescribing nitrofurantion monohydrate/macrocrystals.
auto insurance online ontario car cheapest insurance ireland quick auto insurance online uk cheap car insurance north carolina auto insurance quotes ohio online auto insurance quotes usa discount auto insurance quotes texas geico car insurance rate anonymous car insurance quote other free online car insurance quote auto insurance online qoutes car insurance quote free price gieco auto insurance quotes international resources who has the lowest auto insurance rates
Renografin-60 (Diatrizoate Meglumine and Diatrizoate Sodium Injection USP) should be at body temperature when injected, and may need to be warmed before use.
free anti virus software window xp nod32 antivirus latest version free download
Normally, people can feel if there is a stone in their shoe, then remove it immediately.
free credit report for military free credit report in australia ky free credit report free equifax annual credit report requesting a credit report take the free credit score challenge 1 free credit report obtain free credit report in georgia request for business credit report letter free credit report score information
The physician should not confuse such symptoms with those of narcotic abstinence and should not attempt to treat anxiety by increasing the dose of methadone.
who is rocsi dating zac efron dating taylor swift
The concentration of organic mercury in red cells is about 20 times that found in plasma; the concentration of inorganic mercury at maximum is only about twice that found in plasma.
yahoo
viagra
Hello!
viagra ,
viagra
Hello!
viagra ,
buy viagra
Hello!
buy viagra ,
buy viagra
Hello!
buy viagra ,
viagra
Hello!
viagra ,
cheap viagra
Hello!
cheap viagra , cialis , viagra , buy cialis , cialis ,
viagra
Hello!
viagra ,
cheap cialis
Hello!
cheap cialis ,
cialis
Hello!
cialis ,
viagra
Hello!
viagra ,
buy cialis
Hello!
buy cialis ,
buy cialis
Hello!
buy cialis ,
cialis online
Hello!
cialis online ,
viagra
Hello!
viagra ,
viagra
Hello!
viagra ,
viagra
Hello!
viagra ,
cialis
Hello!
cialis , cheap cialis , cialis , cheap cialis , viagra ,
cialis
Hello!
cialis , viagra , cialis , cheap cialis , cheap viagra ,
viagra
Hello!
viagra ,
cheap cialis
Hello!
cheap cialis ,
viagra
Hello!
viagra ,
cialis
Hello!
cialis ,
cialis
Hello!
cialis ,
cialis
Hello!
cialis ,
cialis
Hello!
cialis ,
cialis
Hello!
cialis ,
cialis
Hello!
cialis ,
cheap cialis
Hello!
cheap cialis ,
cialis
Hello!
cialis , cialis , viagra , viagra , cheap cialis ,
cialis
Hello!
cialis ,
cialis
Hello!
cialis ,
cialis
Hello!
cialis ,
viagra
Hello!
viagra ,
viagra
Hello!
viagra ,
cialis
Hello!
cialis ,
cheap cialis
Hello!
cheap cialis ,
viagra
Hello!
viagra ,
viagra
Hello!
viagra ,
cheap cialis
Hello!
cheap cialis ,
cialis
Hello!
cialis , cheap cialis , viagra , cheap viagra , cialis ,
cialis
Hello!
cialis , viagra , cheap viagra , cheap cialis , cialis ,