diff eventLogger.mm @ 42:3d627dce8bf0

Tidied up startup logic.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 17 Apr 2013 13:44:05 +0100
parents 79c129e500e1
children a1e75b94c505
line wrap: on
line diff
--- a/eventLogger.mm	Fri Apr 12 17:50:25 2013 +0100
+++ b/eventLogger.mm	Wed Apr 17 13:44:05 2013 +0100
@@ -46,19 +46,38 @@
     cout << "Device: " << iOSdeviceType << '\n';
     
     nextUploadQty = UPLOAD_CHUNK_SIZE; // amount of data uploaded is always more than UPLOAD_CHUNK_SIZE events
+    serverComms = [[ServerComms alloc] init];
     
 }
-
-void EventLogger::init(){
+//---------------------------------------------------------------------------
+void EventLogger::startLoadAll(){
     
-    checkExistingLogFile(ofxiPhoneGetDocumentsDirectory() + EVENT_LOG_FILENAME);
+    loadExistingLogFile(ofxiPhoneGetDocumentsDirectory() + EVENT_LOG_FILENAME);
+    
+    
     sessionStartTime = ofGetSystemTime();
-
-    logEvent(APP_STARTED);
-
-    serverComms = [[ServerComms alloc] init];
+    testConnection();
     
-    testConnection();
+    // if we have a back log of events upload them
+    if(theEvents.size() > nextUploadQty && ! logUploadInProgress){
+        //try to upload
+        uploadEventLog(true);
+    }
+    
+    if(questionnaireCompleted && !questionnaireUploaded){
+        uploadQuestionnaire();
+    }
+    
+    //TODO if questionnaire wasn't reached but still opened then set the timer to something sensible
+    
+    //timer.setInteractionTime(savedInteractionTime);
+    //timer.setOrderFromPrevious(interfaceOrder);
+    
+   // for now sod it, start from scratch
+    if(!questionnaireCompleted){
+        cout<<"Questionnaire NOT completed - first APP open called\n";
+        firstEverAppOpen();
+    }
 
 }
 //---------------------------------------------------------------------------
@@ -73,8 +92,9 @@
 // this reads the persistent log file , checks if we've used the app before and
 // if we've answered questionnaire or not
 
-// this function is horrible
-void EventLogger::checkExistingLogFile(const string &jsonFile){
+// should just store stuff. the start up state should be handled by testAPp
+
+void EventLogger::loadExistingLogFile(const string &jsonFile){
     Json::Value root;
     Json::Reader reader;
     
@@ -85,7 +105,7 @@
     stringstream fileText;
     string line;
     if(!theFile){
-        
+        cout<<"No event log file found - first APP open called\n";
         firstEverAppOpen();
         return;
     }else{
@@ -96,11 +116,7 @@
         }
         theFile.close();
     }
-    
-    // otherwise, we've been in here before
-    
-    /////////////
-    // Parse json
+
     cout << "size of log JSON string:" << fileText.str().length() << "BYTES \n";
     
     bool parsingSuccessful = reader.parse( fileText.str(), root );
@@ -129,13 +145,9 @@
     const Json::Value jlogs = root["events"];
     
     for ( int index = 0; index < jlogs.size(); ++index ) theEvents.push_back(lEvent(jlogs[index]));
-    if(theEvents.size() > nextUploadQty && ! logUploadInProgress){
-        //try to upload
-        uploadEventLog(true);
-    }
+
     
     //////////////
-    // what stage is the experiment at??
     
     if(questionnaireCompleted && !questionnaireUploaded){
         // then read it in and upload it
@@ -149,40 +161,23 @@
             questionnaireAnswers.push_back(JArray[i].asInt());
         }
         questionnaireComments = JQ["comments"].toStyledString();
-        uploadQuestionnaire();
+        //uploadQuestionnaire();
     }
-    //TODO if questionnaire wasn't reached but still opened then set the timer to something sensible
-    
-    if(!questionnaireCompleted){
-        // for now sod it, start from scratch
-        firstEverAppOpen();
-        return;
-    }
+
     cout << "Total interaction time: " << savedInteractionTime << '\n';
-    
-    //timer.setInteractionTime(savedInteractionTime);
-    //timer.setOrderFromPrevious(interfaceOrder);
-    
-    // otherwise just start
-    ((testApp *)ofGetAppPtr())->justStart();
-    
+   
 }
 
 //---------------------------------------------------------------------------
 
 void EventLogger::firstEverAppOpen(){
-    cout<<"no event log file - first APP open\n";
+    
     nextUploadNumber = 0;
     deviceID = ofGetSystemTimeMicros();
     savedInteractionTime = 0;
     questionnaireCompleted = false;
     questionnaireUploaded = false;
     
-    //((testApp *)ofGetAppPtr())->showIntro();
-    //consentGiven = false;
-    //((testApp *)ofGetAppPtr())->justStart();
-    
-    
 }
 
 
@@ -379,12 +374,7 @@
 // called from alertView OK in iViewController
 void EventLogger::setUsername(const char *u){
     userName = u;
-    // start interaction clock
     
-    //timer.startInteractionClock();
-    [((testApp *)ofGetAppPtr())->tsc startTimer];
-    
-    // press play??
 }
 //---------------------------------------------------------------------------
 void EventLogger::thinnedScrollEvent(lEvent newEvent){