Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tweak the response data format

One response now corresponds to one parcel, not one form. A form can
cover multiple parcels. But each parcel has its own set of questions, so
it gets its own response.

Fixed a typo bug in testclient.js.

Modify the sample form data so that it corresponds to an existing
skeleton form.
  • Loading branch information...
commit c838f6095e5e59792352da86d4360dd4a1befc32 1 parent e9454a8
@prashtx prashtx authored
Showing with 23 additions and 20 deletions.
  1. +13 −10 form_constructor.json
  2. +6 −3 responses.js
  3. +4 −7 testclient.js
View
23 form_constructor.json
@@ -2,20 +2,23 @@
"forms": [
{ "parcels": [ {"parcel_id": "10", "bubblesets": [
{ "bubbles" :
- [ {"center" : [150, 425], "radius" : 15},
- {"center" : [210, 425], "radius" : 15},
- {"center" : [270, 425], "radius" : 15},
- {"center" : [330, 425], "radius" : 15},
- {"center" : [390, 425], "radius" : 15}
+ [ {"center" : [600, 356], "radius" : 15},
+ {"center" : [600, 394], "radius" : 15},
+ {"center" : [600, 432], "radius" : 15}
],
"name" : "Q0"
},
{ "bubbles" :
- [ {"center" : [150, 460], "radius" : 15},
- {"center" : [210, 460], "radius" : 15},
- {"center" : [270, 460], "radius" : 15},
- {"center" : [330, 460], "radius" : 15},
- {"center" : [390, 460], "radius" : 15}
+ [ {"center" : [347, 694], "radius" : 15},
+ {"center" : [384, 694], "radius" : 15},
+ {"center" : [422, 694], "radius" : 15},
+ {"center" : [459, 694], "radius" : 15},
+ {"center" : [497, 694], "radius" : 15},
+ {"center" : [534, 694], "radius" : 15},
+ {"center" : [572, 694], "radius" : 15},
+ {"center" : [609, 694], "radius" : 15},
+ {"center" : [647, 694], "radius" : 15},
+ {"center" : [684, 694], "radius" : 15}
],
"name" : "Q1"
}
View
9 responses.js
@@ -7,8 +7,9 @@
*
* Data structure:
* responses: [
- * { parcels: [ {parcel_id: 10, responses: {'Q0': 0, 'Q1': 3}}, ]
- * }, ]
+ * { parcel_id: '10', responses: {'Q0': 0, 'Q1': 3}},
+ * { parcel_id: '11', responses: {'Q0': 1, 'Q1': 2}}
+ * ]
*
*/
@@ -60,7 +61,7 @@ function setup(app, db, idgen, collectionName) {
var surveyid = req.params.sid;
var parcel_id = req.params.parcel_id;
getCollection(function(err, collection) {
- collection.find({'survey': surveyid, 'parcels.parcel_id': parcel_id}, function(err, cursor) {
+ collection.find({'survey': surveyid, 'parcel_id': parcel_id}, function(err, cursor) {
if (err != null) {
console.log('Error retrieving responses for survey ' + surveyid + ': ' + err.message);
response.send();
@@ -103,6 +104,8 @@ function setup(app, db, idgen, collectionName) {
// POST http://localhost:3000/surveys/{SURVEY ID}/reponses
// POST http://localhost:3000/surveys/1/reponses
app.post('/surveys/:sid/responses', function(req, response) {
+ console.log(req.body);
+ console.log(JSON.stringify(req.body, null, ' '));
var resps = req.body.responses;
var total = resps.length;
console.log('Adding ' + total + ' responses to the database.');
View
11 testclient.js
@@ -158,7 +158,7 @@ function getparcelresponses(parcel_id) {
console.log('Received an error getting response for parcel ' + parcel_id + ': ' + error.message);
} else {
body = JSON.parse(body);
- console.log(JSONpretty(body.response));
+ console.log(JSONpretty(body.responses));
}
});
}
@@ -168,10 +168,8 @@ function seedresponses() {
var url = BASEURL + '/surveys/' + SURVEYID + '/responses';
var data = {
responses: [
- { parcels: [ {parcel_id: '10', responses: {'Q0': 0, 'Q1': 3}} ]
- }
- , { parcels: [ {parcel_id: '11', responses: {'Q0': 1, 'Q1': 4}} ]
- }
+ { parcel_id: '10', responses: {'Q0': 0, 'Q1': 3}}
+ , { parcel_id: '11', responses: {'Q0': 1, 'Q1': 4}}
]
};
console.log('Posting to url: ' + url);
@@ -195,8 +193,7 @@ function addresponse() {
var url = BASEURL + '/surveys/' + SURVEYID + '/responses';
var data = {
responses: [
- { parcels: [ {parcel_id: '10', responses: {'Q0': 0, 'Q1': 3}} ]
- }
+ { parcel_id: '10', responses: {'Q0': 0, 'Q1': 3}}
]
};
console.log('Posting to url: ' + url);
Please sign in to comment.
Something went wrong with that request. Please try again.