From 8533420631fff78c1e0045b6a9762e108277194f Mon Sep 17 00:00:00 2001 From: Tomasz Malisiewicz Date: Fri, 4 Sep 2015 19:22:27 -0400 Subject: [PATCH] google maker is almost done --- apidocs/tests/google_maker.js | 50 +++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/apidocs/tests/google_maker.js b/apidocs/tests/google_maker.js index 254baca..e21f9bb 100755 --- a/apidocs/tests/google_maker.js +++ b/apidocs/tests/google_maker.js @@ -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; @@ -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) { +}); }); - }); +}); + +