Skip to content

Commit

Permalink
Now using the official bodytrack-datastore node module. Updated code …
Browse files Browse the repository at this point in the history
…to match its the new bodytrack-datastore API.
  • Loading branch information
chrisbartley committed May 5, 2014
1 parent 7839d09 commit 79bcf95
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 471 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
*.iws
*.iws
node_modules
3 changes: 1 addition & 2 deletions Node Datastore Server.iml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
<excludeFolder url="file://$MODULE_DIR$/datastore/db" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jQuery UI 1.10.3" level="application" />
<orderEntry type="library" name="Node.js Dependencies for Node Datastore Server" level="project" />
<orderEntry type="library" name="Node.js v0.10.26 Core Modules" level="application" />
<orderEntry type="library" name="Node.js Dependencies for Node Datastore Server" level="project" />
</component>
</module>

16 changes: 6 additions & 10 deletions Node Datastore Server.ipr
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
</profile>
</annotationProcessing>
</component>
<component name="CopyrightManager" default="">
<module2copyright />
</component>
<component name="CopyrightManager" default="" />
<component name="DependencyValidationManager">
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</component>
Expand Down Expand Up @@ -62,7 +60,6 @@
<version value="1.0" />
</component>
<component name="JavaScriptLibraryMappings">
<file url="file://$PROJECT_DIR$" libraries="{Node.js Dependencies for Node Datastore Server}" />
<file url="PROJECT" libraries="{Node.js Dependencies for Node Datastore Server, Node.js v0.10.26 Core Modules}" />
<includedPredefinedLibrary name="Node.js Globals" />
</component>
Expand Down Expand Up @@ -298,6 +295,11 @@
<option name="TAB_SIZE" value="3" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="Python">
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="PARENT_SETTINGS_INSTALLED" value="true" />
</codeStyleSettings>
<codeStyleSettings language="SCSS">
<indentOptions>
<option name="INDENT_SIZE" value="3" />
Expand Down Expand Up @@ -380,7 +382,6 @@
</component>
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="app.js" type="NodeJSConfigurationType" factoryName="Node.js" path-to-node="/usr/local/bin/node" path-to-js-file="app.js" working-dir="$PROJECT_DIR$">
<browser start="false" url="" with-js-debugger="false" />
<method />
</configuration>
</component>
Expand Down Expand Up @@ -418,11 +419,6 @@
</component>
<component name="libraryTable">
<library name="Node.js Dependencies for Node Datastore Server" type="javaScript">
<properties>
<sourceFilesUrls>
<item url="file://$PROJECT_DIR$/node_modules" />
</sourceFilesUrls>
</properties>
<CLASSES>
<root url="file://$PROJECT_DIR$/node_modules" />
</CLASSES>
Expand Down
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Node Datastore Server
=====================

This is a simple, minimal Node.js server demonstrating communication between the BodyTrack Grapher and the BodyTrack Datastore. Not intended for use in production.

The BodyTrack Datastore repository is at:

https://github.com/BodyTrack/datastore

The BodyTrack Grapher repository is at:

https://github.com/BodyTrack/Grapher

This project includes binaries for the Grapher, but you'll need to
fetch and build the Datastore--see instructions below.

Installation And Setup
======================

Here's what to do to get the server running:

1. Fetch the BodyTrack Datastore:

git clone https://github.com/BodyTrack/datastore.git

2. Follow the build and install instructions for the BodyTrack Datastore, but install it into this project's "datastore" directory. This project's "datastore" directory should be the parent to the "datastore" and "db" subdirectories.

3. Install Node.js (http://nodejs.org/)

4. Open a terminal window and cd to this project's root directory

5. Install the dependences:

npm install

6. Optionally install nodemon (https://github.com/remy/nodemon)

npm install -g nodemon

7. Start the server:

node app.js

Or, if you installed nodemon, start it with:

nodemon app.js

8. Open a brower and go to:

http://localhost:3000/

You should see the server's home page with a message that the
datastore is empty. See the "Uplaoding Data" section below for a
few different ways to get data in to the datastore.

Uploading Data
==============

This server supports uploading of new data. Here are a few ways
to get data in:

1. For a quick test with some sample Speck data, find the db.tgz tarball in this project's etc directory and untar it into the datastore directory. OK, fine...so this isn't *uploading*, but it gets data in there so stop complaining. :-)

2. To upload using curl, make sure the server is running, open a terminal with the current directory set to this project's root, and run the following:

curl -H "Content-Type:application/json" http://localhost:3000/upload?dev_nickname=Speck -d @etc/speck_data.json

Doing that will get you the exact same data as what's in the db.tgz mentioned above.

3) If you're using the Speck Gateway (http://specksensor.org/), simply point the uploader at localhost:3000. This server doesn't support multiple users (all data is stored under user ID 1), so the username and password required by uploader are ignored--set them to whatever you want.

Disclaimer
==========

This is my first time writing code for Node.js. I probably did a lot
of things wrong and/or in a stupid way. Feedback welcome. Thanks.
97 changes: 0 additions & 97 deletions README.txt

This file was deleted.

12 changes: 6 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var express = require('express');
var routes = require('./routes');
var datastore = require('./routes/datastore');
var routes = require('./routes/index');
var http = require('http');
var path = require('path');

Expand All @@ -17,7 +16,7 @@ app.use(express.compress()); // enables gzip compression
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.set("jsonp callback", true);
app.set('json spaces',0); // setting this to 0 removes whitespace from json
app.set('json spaces', 0); // setting this to 0 removes whitespace from json

// development only
if ('development' == app.get('env')) {
Expand All @@ -27,9 +26,10 @@ if ('development' == app.get('env')) {
app.get('/', routes.index);
app.get('/grapher/:uid', routes.index);
app.get('/grapher/:uid/:deviceNickname/:channelName', routes.index);
app.get('/users/:uid/sources/list', datastore.listSources);
app.get('/tiles/:uid/:deviceNickname.:channelName/:level.:offset.json', datastore.getTile);
app.post('/api/bodytrack/jupload', datastore.uploadJson);
app.get('/users/:uid/sources/list', routes.listSources);
app.get('/tiles/:uid/:deviceNickname.:channelName/:level.:offset.json', routes.getTile);
app.post('/api/bodytrack/jupload', routes.uploadJson);
app.post('/upload', routes.uploadJson);

http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
Expand Down
5 changes: 0 additions & 5 deletions node_modules/.gitignore

This file was deleted.

Loading

0 comments on commit 79bcf95

Please sign in to comment.