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="rot.js">
</script>
<script src="app.js">
<script src="anotherApp.js">
</script>
<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" />
</div>
<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">
</div>
<button type="submit" class="btn btn-danger">ToSpeech</button>
</form>
</form>-->
</div>
</body>
</html>

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

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