howaboutwe / experimental

MIT License
20 stars 2 forks source link

add postgres support #16

Open zilkey opened 11 years ago

zilkey commented 11 years ago

I'd like to use experimental, but I'm on postgres. It does not seem to be trivial to convert the existing mysql functions to postgres, but I have a version that seems to be equivalent.

The ruby version is:

top_8 = Digest::MD5.hexdigest("#{experiment_name}#{user.id}")[0...16]
top_8.to_i(16) % num_buckets

The SQL version is:

select abs(('x'|| substr(md5('experiment-name' || id),1,16))::bit(64)::bigint) % 2 from users;

Are there any plans to include different database adapters in this gem?

zilkey commented 11 years ago

Please disregard the code above. The sql does not match the ruby.

To support ruby, could we change the algorithm to something simpler? Like, having a random seed number in the config file, then just adding that random number to the user's id? (an idea from @dlikhten)

That way, the math would be super simple in the database, and would be database agnostic.

dlikhten commented 11 years ago

Less math = always my favorite approach. :+1: