Re: Usage statistics.

Dave Aronson
Wed, 18 Jan 2012 17:51:06 -0000

On Wed, Jan 18, 2012 at 09:42, bertly_the_coder
<muchira-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> users do things like vote, give opinions
> etc. Now I want to collect this data and display it, possibly using
> flot, to show the break down of users by age, sex, location, etc etc.
> I was initial going to hit the database for each query I want to have,
> but that seems like too many database hits and too much
> redundancy.....any one know of a smarter way to do this?

How many users do you have, what demographic data do you need, how
many choices are there on each, how many different ways to vote were
there, how are you recording the votes, how often do you expect it to
be queried, and how?  Any way you recorded the votes, you can probably
extract a fairly well rolled-up version, and serve up more specific
rollups from there.  If worst comes to worst you could use memcache or
some similar thing to reduce database traffic.

For instance, suppose you were polling on the favorite season, and you
want to break it down by age, sex, race, educational level, income
bracket, employment status, marital status, shoe size, hair color,
handedness, and location (defined as nearest integer latitude and
longitude), etc. etc. etc.  You could store them in a table with
season, each demographic factor (extracted from the user record or
input at voting time), and a count of how many such people voted for
that season.  (Do NOT store just vote and user ID, to extract the
demographic data later on demand, if the users might ever care about
the votes being secret!  Store who voted, *separately*.)  Then it
should be easy to pull out a breakdown by each demographic sector, or
even a combination.  (Just be aware that with a small enough sample
size, it may thus be possible to extract how certain individuals
voted, or reveal other private data.)

-Dave

--
Dave Aronson, President, Dave Aronson Software Engineering and Training
Ruby on Rails Freelancing (Northern Virginia, Washington DC, or Remote)
DaveAronson.com, Codosaur.us, Dare2XL.com, & RecruitingRants.com (NEW!)
Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (me)

--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at