added some psuedocode for combining arrays

This commit is contained in:
2013-01-08 23:45:19 -05:00
parent 78061256b8
commit 4aebfbf83d

48
app.js
View File

@@ -106,23 +106,32 @@ io.sockets.on('connection', function(socket) {
console.log('getactivities'); console.log('getactivities');
testcollection.find().toArray(function(err, result) { testcollection.find().toArray(function(err, result) {
if (err) throw err; if (err) throw err;
async.forEachSeries(result, async.forEachSeries(result,
function(item,callback2) { function(item,callback2) {
async.forEachSeries(item.Activities.Activity.Lap, async.forEachSeries(item.Activities.Activity.Lap,
function(itemx,callback3){ function(itemx,callback3){
exercisecollection.findById(itemx.selection, function(err, exresult) { exercisecollection.findById(itemx.selection, function(err, exresult) {
if (err) throw err; if (err) throw err;
itemx.exercisename = exresult.exercise.name; itemx.exercisename = exresult.exercise.name;
itemx.exercisemuscledata = exresult.exercise.muscledata; itemx.exercisemuscledata = exresult.exercise.muscledata;
itemx.exerciseclass = exresult.exercise.type; itemx.exerciseclass = exresult.exercise.type;
callback3(); callback3();
}); });
}, function(err){ }, function(err){
callback2(); callback2();
}); });
}, function(err){ }, function(err){
socket.emit('populateactivities', result); /////////THIS is psuedo code for adding the activity arrays
}); //combinedarray = [0,0,0,0,0,0]
// for j in result
// do
//for i in (1..6)
// do
// combinedarray[i] = result[j].exercisemuscledata[i] + combinedarray[i]
//
// result.combinedarray = combinedarray
socket.emit('populateactivities', result);
});
}); });
}); });
/////////////////////////////////////// ///////////////////////////////////////
@@ -146,16 +155,12 @@ io.sockets.on('connection', function(socket) {
//////////////////////// ////////////////////////
socket.on('addactivity', function(data, docid) { socket.on('addactivity', function(data, docid) {
var document_id; var document_id;
// console.log('addactivity' + docid);
// console.log('add_activity_data' + JSON.stringify(data));
if (docid === null) { if (docid === null) {
document_id = new BSON.ObjectID(); document_id = new BSON.ObjectID();
} }
else { else {
document_id = new BSON.ObjectID(docid); document_id = new BSON.ObjectID(docid);
} }
//var document_id = new BSON.ObjectID(docid);
// console.log('inserted BSONID' + document_id);
testcollection.update({_id:document_id}, data,{upsert:true} , function(err, result) { testcollection.update({_id:document_id}, data,{upsert:true} , function(err, result) {
if (err) throw err; if (err) throw err;
exercisecollection.find().toArray(function(err, result) { exercisecollection.find().toArray(function(err, result) {
@@ -179,7 +184,6 @@ io.sockets.on('connection', function(socket) {
}); });
/////////////////// ///////////////////
socket.on('getexercises', function(data) { socket.on('getexercises', function(data) {
// console.log('emit exercises');
exercisecollection.find().toArray(function(err, result) { exercisecollection.find().toArray(function(err, result) {
if (err) throw err; if (err) throw err;
socket.emit('populateexercises', result); socket.emit('populateexercises', result);