Skip to content

Commit

Permalink
google maker is almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
quantombone committed Sep 4, 2015
1 parent dbac13b commit 8533420
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions apidocs/tests/google_maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

// A test suite for the load handler
// NOTE: it requires running from a fresh start (instance with no model loaded)
var sleep = require('sleep');
var http = require('http');
var request = require('request');
var https = require('https');
var fs = require('fs');

var assert = require('assert');
var myrequest = require('./vmxtester').myrequest;
Expand All @@ -18,29 +23,52 @@ console.log('Testing simple creation from a blank slate');

require('./vmxtester').myexec("rm -rf "+vmx_dir+"/models/*");

var target = process.argv[2];
//target="cat";
//target = "batman";

myrequest({method:'GET',url:"https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=cat&rsz=8&start=0"},function(error,response,body){
myrequest({method:'GET',url:"https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q="+target+"&rsz=8&start=0"},function(error,response,body){
//console.log('body is', JSON.stringify(body,4,null));

var images = [];
for (var i = 0; i < body.responseData.results.length; ++i) {
var url2 = body.responseData.results[i].url;
var width = body.responseData.results[i].width;
var height = body.responseData.results[i].height;
var width = parseFloat(body.responseData.results[i].width);
var height = parseFloat(body.responseData.results[i].height);
console.log('url2 is', url2);
var objects = [{name:"cat",bb:[1,1,height,width]}];
images[i] = {image:url2,objects:objects};
var objects = [{name:target,bb:[1,1,height,width]}];




var filer = "out/file"+i+".jpg";
console.log('writing '+filer);
request(url2).pipe(fs.createWriteStream(filer));
//sleep.sleep(1);
var url3 = __dirname+'/'+filer;
images[i] = {image:url3,objects:objects};

//var file = fs.createWriteStream(filer);
//var request = http.get(url2, function(response) {
// response.pipe(file);
//});

}

myrequest({method: 'POST', url:url+'/sessions',json:{}},function(error, response, body) {
assert.equal(response.statusCode, 200, 'Problem with status code');
var id = body.data.id;
myrequest({method: 'POST', url:url+'/sessions',json:{id:"tester"}},function(error, response, body) {
//assert.equal(response.statusCode, 200, 'Problem with status code');
//var id = body.data.id;
var id = "tester";

myrequest({method: 'POST', url:url+'/'+id+'/create', json:{name:"face2",images:images,pretrained:'109e8c80074201cda9cfe4d167868337'}}, function(error, response, body) {

myrequest({method: 'POST', url:url+'/sessions/'+id+'/create', json:{name:target,images:images,pretrained:'109e8c80074201cda9cfe4d167868337'}}, function(error, response, body) {
assert.equal(response.statusCode, 200, 'Problem with status code');
//assert.equal(body.error,0,'Error is not 0');
assert.equal(body.data.model.num_pos,1,'num_pos is not one');

myrequest({method: 'POST', url:url+'/sessions/'+id+'/save', json:{}}, function(error, response, body) {
});
});

});
});


0 comments on commit 8533420

Please sign in to comment.