Skip to content

Instantly share code, notes, and snippets.

@danielberlinger
Last active June 2, 2016 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielberlinger/536a06db63e2bf461188 to your computer and use it in GitHub Desktop.
Save danielberlinger/536a06db63e2bf461188 to your computer and use it in GitHub Desktop.
Rolled together a startup of rethinkdb on OS X and a couple of fixes from a tutorial
This tutorial had a few bugs in it:
http://www.rethinkdb.com/docs/tutorials/elections/
---
getting started on Mac OS X...
The first few items are run in the terminal, and while I'm sure there are other ways to load the data,
I just went with what was in the tutorial, which included using the Python driver for Rethinkdb via pip.
After the last command in here, things seemed to just work... so I pass you back to the tutorial page.
brew update
brew install rethinkdb
(start it up!)
# To get the data for the tutorial
sudo easy_install pip
wget https://raw.github.com/rethinkdb/rethinkdb/next/demos/election/input_polls.json
wget https://raw.github.com/rethinkdb/rethinkdb/next/demos/election/county_stats.json
sudo pip install rethinkdb
rethinkdb import -c localhost:28015 --table test.input_polls --pkey uuid -f input_polls.json --format json
rethinkdb import -c localhost:28015 --table test.county_stats --pkey uuid -f county_stats.json --format json
#in javascript using the data explorer (http://localhost:8080/#dataexplorer)
r.table('input_polls').limit(1)
r.db('test').tableCreate('polls')
r.table("polls").insert(
r.table("input_polls")
.group("id") // We group the table by `id`, which is the state name.
.pluck('Dem', 'GOP') // We pluck out the poll results we care about.
.merge({polls: 1}) // And finally, we add an extra field `polls: 1` to each row.
.reduce(function(left, right){
// We reduce over the polls, adding up the results and keeping
// track of the total number of polls.
return {
Dem: left("Dem").add(right("Dem")),
GOP: left("GOP").add(right("GOP")),
polls: left("polls").add(right("polls"))
};
}).ungroup().map(function(state){
// We ungroup and divide the fields `Dem` and `GOP` for each state
// by the number of polls to get the average result per state.
return {
Dem: state("reduction")("Dem").div(state("reduction")("polls")),
GOP: state("reduction")("GOP").div(state("reduction")("polls")),
polls: state("reduction")("polls"),
id: state("group")
};
})
)
#etc as in the tutorial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment