some cluttered rot and another testApp to test new adjustments in tags to features

This commit is contained in:
raluca-elena 2014-08-06 23:02:25 -07:00
Родитель 480174842b
Коммит 467fc2dde9
2 изменённых файлов: 33 добавлений и 28 удалений

Просмотреть файл

@ -12,10 +12,10 @@
<script src="./superagent.js"></script> <script src="./superagent.js"></script>
<script src="rot.js"> <script src="rot.js">
</script> </script>
<script src="app.js"> <script src="anotherApp.js">
</script> </script>
<div style="display: inline-flex;"> <div style="display: inline-flex;">
<div> <!--<div>
<img id = "myPic" style="float:left;margin: 10px 10px;" src="http://localhost:8989/?action=stream" width="520" height="480" /> <img id = "myPic" style="float:left;margin: 10px 10px;" src="http://localhost:8989/?action=stream" width="520" height="480" />
</div> </div>
<form id="speech" class="navbar-form navbar-left" action="http://localhost:3333" method="post"> <form id="speech" class="navbar-form navbar-left" action="http://localhost:3333" method="post">
@ -23,7 +23,7 @@
<input type="text" class="form-control" placeholder="write something"> <input type="text" class="form-control" placeholder="write something">
</div> </div>
<button type="submit" class="btn btn-danger">ToSpeech</button> <button type="submit" class="btn btn-danger">ToSpeech</button>
</form> </form>-->
</div> </div>
</body> </body>
</html> </html>

Просмотреть файл

@ -19,20 +19,19 @@ function init(cb) {
return; return;
} }
var uuids = JSON.parse(res.text); var uuids = Object.keys(JSON.parse(res.text));
console.log("got uuids: ", uuids); console.log("ROT got uuids: ", uuids);
allUuids = uuids; allUuids = uuids;
getAllThings(uuids, function(err, things) { getAllThings(uuids, function(err, things) {
allThings = things; allThings = things;
console.log("allThings: ", allThings); console.log("ROT allThings: ", allThings);
getAllFeatures(things, function(err, features) { getAllFeatures(things, function(err, features) {
allFeatures = features; allFeatures = features;
console.log("allFeatures: ", allFeatures); console.log("ROT allFeatures: ", allFeatures);
getAllTags(things, function(err, tags) { getAllTags(things, function(err, tags) {
allTags = tags; allTags = tags;
console.log("allTags: ", allTags); console.log("ROT allTags: ", allTags);
cb(); cb();
}); });
}); });
@ -58,11 +57,13 @@ function queryTags(tags, cb) {
} }
function readTag(tag, cb) { function readTag(tag, cb) {
var tagData = allTags[tag]; var tagData = JSON.parse(allTags[tag]);
console.log("tagData is ----------------------------", tagData);
if (tagData === undefined) { if (tagData === undefined) {
cb(undefined, "No such tag: " + tag + " :("); cb(undefined, "ROT No such tag: " + tag + " :(");
} else if (tagData['url'] === undefined) { } else if (tagData['url'] === undefined) {
cb(undefined, "No url for tag: " + tag + " :("); cb(undefined, "ROT No url for tag: " + tag + " :(");
} else { } else {
superagent superagent
.get("http://" + tagData['url'], function (err, req) { cb(req.text, err);}) ; .get("http://" + tagData['url'], function (err, req) { cb(req.text, err);}) ;
@ -86,10 +87,12 @@ function writeTag(tag, data, cb) {
} }
function getAllThings(uuids, cb) { function getAllThings(uuids, cb) {
console.log("GET ALL THINGS");
var things = {}; var things = {};
var errors = undefined; var errors = undefined;
var done = 0; var done = 0;
for (var i = 0; i < uuids.length; i++) { for (var i = 0; i < uuids.length; i++) {
console.log("ROT uuids are ", uuids);
(function() { (function() {
var uuid = uuids[i]; var uuid = uuids[i];
superagent.get(baseurl + "/thing/" + uuid, function(err, res) { superagent.get(baseurl + "/thing/" + uuid, function(err, res) {
@ -103,21 +106,24 @@ function getAllThings(uuids, cb) {
things[uuid] = thing; things[uuid] = thing;
} }
done ++; done ++;
if (done === uuids.length) if (done === uuids.length) {
cb(errors, things); cb(errors, things);
console.log("THINGS are : ", things);
}
}); });
})(); })();
} }
} }
function getAllTags(things, cb) { function getAllTags(things, cb) {
console.log("ROT I am in getAllTags having things :--------", things);
var tags = {}; var tags = {};
var errors = undefined; var errors = undefined;
var done = 0; var done = 0;
for (var uuid in things) { for (var uuid in things) {
(function(uuid) { (function(uuid) {
var thing = things[uuid]; var thing = things[uuid];
console.log("thing:", thing); console.log("ROT IN GETALLTAGS A thing:------------------", thing);
superagent.get(thing['localURL'] + "/tags/", function(err, res) { superagent.get(thing['localURL'] + "/tags/", function(err, res) {
console.log("--> getAllTags: err: ", err); console.log("--> getAllTags: err: ", err);
if (err) { if (err) {
@ -126,20 +132,17 @@ function getAllTags(things, cb) {
errors.push(err); errors.push(err);
} else { } else {
var tagsResp = JSON.parse(res.text); var tagsResp = JSON.parse(res.text);
// returns a mapping from tag name to feature name:
// { led1: "factory-name-for-led1-C00FF33"}
console.log("Got tagsResp: ", tagsResp, " for thing: ", thing); console.log("Got tagsResp: ", tagsResp, " for thing: ", thing);
// merge tag lists // merge tag lists
for (var tagName in tagsResp) { for (var tagName in tagsResp) {
var feature = tagsResp[tagName]; //var feature = tagsResp[tagName];
tags[tagName] = allFeatures[uuid][feature]; if (JSON.parse(tagsResp[tagName]).url !== undefined)
console.log("getAllTags: tagName: ", tagName, "uuid:", uuid, "feature:", feature, tags[tagName] = tagsResp[tagName];
"xxx: ", allFeatures[uuid][feature], if (JSON.parse(tagsResp[tagName]).val !== undefined)
"uuid info: ", allFeatures[uuid], tags[tagName] = tagsResp[tagName];
"allFeatures: ", allFeatures); }
}
} }
done ++; done ++;
if (done === Object.keys(things).length) if (done === Object.keys(things).length)
@ -156,7 +159,8 @@ function getAllFeatures(things, cb) {
for (var uuid in things) { for (var uuid in things) {
(function(uuid) { (function(uuid) {
var thing = things[uuid]; var thing = things[uuid];
console.log("thing:", thing); console.log("ROT A THING LOOKS LIKE :", thing);
console.log("thing[localURL]"+ thing['localURL'] +"/features/");
superagent.get(thing['localURL'] + "/features/", function(err, res) { superagent.get(thing['localURL'] + "/features/", function(err, res) {
console.log("--> getAllFeatures: err: ", err, " res.text: ", res.text); console.log("--> getAllFeatures: err: ", err, " res.text: ", res.text);
if (err) { if (err) {
@ -165,8 +169,8 @@ function getAllFeatures(things, cb) {
errors.push(err); errors.push(err);
} else { } else {
var featuresResp = JSON.parse(res.text); var featuresResp = JSON.parse(res.text);
console.log("Got featuresResp: ", featuresResp, " for thing: ", thing, "uuid:", uuid); console.log("************************ Got featuresResp: ", featuresResp, " for thing: ", thing, "uuid:", uuid);
features[uuid] = featuresResp; features[uuid] = JSON.stringify(featuresResp);
} }
done ++; done ++;
if (done === Object.keys(things).length) if (done === Object.keys(things).length)
@ -196,6 +200,7 @@ function setTag(uuid, feature, tag, cb) {
.send(feature) .send(feature)
.end(function(res){ .end(function(res){
console.log("setTag: callback is ", cb); console.log("setTag: callback is ", cb);
console.log("XXXXXXXXXX allFeatures[uuid][feature]", allFeatures[uuid][feature]);
allTags[tag] = allFeatures[uuid][feature]; allTags[tag] = allFeatures[uuid][feature];
if (res.ok) { if (res.ok) {