Mercurial > hg > soniczoomios
diff eventLogger.mm @ 29:fabb3a5cdfc9
Timed session improvements. Desperate pathetic attempts to send a simple HTTP POST.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 22 Feb 2013 17:41:38 +0000 |
parents | e2c62db1e265 |
children | c0a6f7c66719 |
line wrap: on
line diff
--- a/eventLogger.mm Mon Feb 18 11:45:05 2013 +0000 +++ b/eventLogger.mm Fri Feb 22 17:41:38 2013 +0000 @@ -8,10 +8,9 @@ //--------------------------------------------------------------------------- #include "eventLogger.h" -#include "timer.h" EventLogger eventLogger; -extern Timer timer; + //--------------------------------------------------------------------------- EventLogger::EventLogger(){ //QuestionnaireViewController * questionnaireViewController; @@ -33,6 +32,7 @@ // draw() - show path of last N scroll events - can be scrubbed along? // //--------------------------------------------------------------------------- + void EventLogger::init(){ readJsonToLog(ofxiPhoneGetDocumentsDirectory() + EVENT_LOG_FILENAME); @@ -41,7 +41,19 @@ testConnection(); logEvent(APP_STARTED); + + stringstream r; + r << LOGGING_SERVER_URL << "testConnection?jsontext=" << "{\"test\":\"test\"}&Content-Length=456"; + + NSString *urlstring; + urlstring = @"http://127.0.0.1:8080/testservice/testConnection?jsontext={\"objc post\":\"obj c post\"}"; + serverComms = [[ServerComms alloc] init]; + [serverComms postRequest:urlstring]; + + + urlstring = nil; } + //--------------------------------------------------------------------------- void EventLogger::questionnaireAnswersObtained(vector<int> answers, const char* userComments){ @@ -62,8 +74,10 @@ //--------------------------------------------------------------------------- bool EventLogger::sendToServer(string functionName, Json::Value jsonData, bool async = false){ bool sent; - string request; + stringstream request; + request << LOGGING_SERVER_URL << functionName << "?jsontext="; + /* if(functionName == "testConnection"){ request = "http://127.0.0.1:8080/testservice/testConnection?jsontext="; }else if(functionName == "questionnaire"){ @@ -71,6 +85,7 @@ }else if(functionName == "eventlog"){ request = "http://127.0.0.1:8080/testservice/eventlog?jsontext="; } + */ Json::FastWriter writer; string jsontext = writer.write( jsonData ); @@ -79,12 +94,14 @@ jsontext.erase(jsontext.length()-1); } - request.append(jsontext); + request << jsontext; + + cout << request.str(); if(!async){ ofURLFileLoader fileLoader; ofHttpResponse resp; - resp = fileLoader.get(request); + resp = fileLoader.get(request.str()); cout << "HTTP STATUS " << resp.status << "\n"; cout << "HTTP ERROR " << resp.error << "\n"; @@ -111,7 +128,7 @@ return sent; }else{ // async ofURLFileLoader fileLoader; - currentHTTPRequestID = ofLoadURLAsync(request, functionName); + currentHTTPRequestID = ofLoadURLAsync(request.str(), functionName); ofRegisterURLNotification(this); return true; // ??? @@ -178,7 +195,7 @@ //--------------------------------------------------------------------------- bool EventLogger::testConnection(){ Json::Value root; - root["test"] = "test"; + root["x"] = "y"; sendToServer("testConnection", root, true); @@ -256,8 +273,8 @@ // TODO if the total interaction time is greater than a certain amount && no questions answered - questionnaire time! cout << "Total interaction time: " << savedInteractionTime << '\n'; - timer.setInteractionTime(savedInteractionTime); - timer.setOrderFromPrevious(interfaceOrder); + //timer.setInteractionTime(savedInteractionTime); + //timer.setOrderFromPrevious(interfaceOrder); } @@ -272,7 +289,7 @@ if(!async){ bool success = sendToServer("eventlog", logsToJson(), async); if(!success){ - // try later + // try later : NOPE has maximum size nextUploadQty += UPLOAD_CHUNK_SIZE; }else{ @@ -310,15 +327,16 @@ // only called when doing supervised tests void EventLogger::newUser(){ cout<<"setup new user\n"; + deleteLogs(); nextUploadNumber = 0; deviceID = ofGetSystemTimeMicros(); savedInteractionTime = 0; totalInteractionTime = 0; sessionStartTime = ofGetSystemTime(); questionnaireCompleted = false; - questionnaireUploaded = false; - consentGiven = true; // other wise we wouldn't be doing this - ((testApp *)ofGetAppPtr())->introHidden(true); // hacky + questionnaireUploaded = false; + + ((testApp *)ofGetAppPtr())->showIntro(); } //--------------------------------------------------------------------------- @@ -326,7 +344,9 @@ void EventLogger::setUsername(const char *u){ userName = u; // start interaction clock - timer.startInteractionClock(); + + //timer.startInteractionClock(); + [((testApp *)ofGetAppPtr())->tsc startTimer]; } //--------------------------------------------------------------------------- void EventLogger::thinnedLogEvent(lEvent newEvent){ @@ -361,7 +381,6 @@ previousEvent = newEvent; } //--------------------------------------------------------------------------- -// log zoom event void EventLogger::logEvent(const leventType& evtType,const TwoVector& centre, const double& scale, const int& sliderID, const double& sliderVal){ //cout << "log: " << evtType << "\n"; @@ -386,7 +405,7 @@ case CHANGE_SLIDER: thinnedLogEvent(lEvent(evtType,sliderVal , 0.0 , sliderID)); break; - + // non thinned data case SAVE_PRESET: theEvents.push_back(lEvent(evtType,centre.x,centre.y)); // Code @@ -419,7 +438,16 @@ totalInteractionTime = savedInteractionTime + (ofGetSystemTime() - sessionStartTime); // milliseconds } - +//-------------------------------------------------------------------- +// called from newUser +void EventLogger::deleteLogs(){ + // the + theEvents.clear(); + string fname = ofxiPhoneGetDocumentsDirectory() + EVENT_LOG_FILENAME; + ofFile logFile(fname,ofFile::WriteOnly); + logFile << ""; + logFile.close(); +} //--------------------------------------------------------------------------- void EventLogger::exitAndSave(){ @@ -445,6 +473,7 @@ Json::Value jlogs = logsToJson(); ofFile logFile(fname,ofFile::WriteOnly); logFile << jlogs; + logFile.close(); } //---------------------------------------------------------------------------