Mercurial > hg > soniczoomios
changeset 7:845ea04f8e33
more logging, user id, preset info
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Thu, 06 Dec 2012 18:26:51 +0000 |
parents | 34eba1046890 |
children | e2c6cfe8c6b7 |
files | eventLogger.h eventLogger.mm grid.h grid.mm presetManager.h presetManager.mm testApp.mm |
diffstat | 7 files changed, 162 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/eventLogger.h Thu Dec 06 13:55:58 2012 +0000 +++ b/eventLogger.h Thu Dec 06 18:26:51 2012 +0000 @@ -60,7 +60,7 @@ os << e.eventType << ',' << e.val1 << ',' << e.val2 << ',' << e.sliderID << '\n'; return os; - } +} //--------------------------------------------------------------------------- class EventLogger{ @@ -73,13 +73,20 @@ vector<lEvent> theEvents; - string userID; // get something from hardware?? + unsigned int deviceID; // get something from hardware?? + unsigned int totalInteractionTime, sessionTime, sessionStartTime; + string userName; EventLogger(); + void init(); + void logEvent(const leventType& evtType,const TwoVector& centre = TwoVector(), const double& scale = 1.0, const int& sliderID = -1, const double& sliderVal = 0.0); void logEvent(const leventType& evtType,const int& sliderID, const double& sliderVal); void sendHttp(); - + void checkLogFile(); + void attemptUpload(); + void firstEverAppOpen(); + void exitAndSave(); void printAll(){ cout << "ALL LOGGED EVENTS!: \n"; vector<lEvent>::iterator evIter;
--- a/eventLogger.mm Thu Dec 06 13:55:58 2012 +0000 +++ b/eventLogger.mm Thu Dec 06 18:26:51 2012 +0000 @@ -9,28 +9,22 @@ #include "eventLogger.h" - EventLogger eventLogger; EventLogger::EventLogger(){ // if first time opened request a user ID from the server... use time? loggingEnabled = true; - - double timemsd = [NSDate timeIntervalSinceReferenceDate]; - long long timems = (long long)(timemsd*1000); - cout << "Time (ms) = " << timems << "\n"; - - - CFUUIDRef theUUID = CFUUIDCreate(NULL); - CFStringRef tstring = CFUUIDCreateString(NULL, theUUID); - CFRelease(theUUID); - - + } +void EventLogger::init(){ + checkLogFile(); + sessionStartTime = ofGetSystemTime(); + +} void EventLogger::logEvent(const leventType& evtType,const TwoVector& centre, const double& scale, const int& sliderID, const double& sliderVal){ //cout << "log: " << evtType << "\n"; @@ -68,7 +62,12 @@ // Code break; } - + if(theEvents.size() > 5000){ + //try to upload + attemptUpload(); + } + sessionTime = (ofGetSystemTime() - sessionStartTime); + } void EventLogger::logEvent(const leventType& evtType,const int& sliderID, const double& sliderVal){ @@ -82,6 +81,18 @@ // Code break; } + if(theEvents.size() > 5000){ + //try to upload + attemptUpload(); + } +} +void EventLogger::attemptUpload(){ + + //if(fail){ + // try later + //} + + // if success - clear memory } void EventLogger::sendHttp(){ @@ -92,4 +103,70 @@ cout << "HTTP STATUS " << resp.status << "\n"; cout << "HTTP ERROR " << resp.error << "\n"; cout << "HTTP DATA " << resp.data << "\n"; +} + +void EventLogger::checkLogFile(){ + + string fname = ofxiPhoneGetDocumentsDirectory() + "eventlog.dat"; + ifstream eventLogFile(fname.c_str()); + // have we opened the app before? if so get device ID and userName + //string firstLine, nextLine; + if(!eventLogFile){ + cout<<"no event log file - first APP open\n"; + + firstEverAppOpen(); + + return; + } + eventLogFile >> deviceID; + eventLogFile >> userName; + eventLogFile >> totalInteractionTime; + + cout << "DeviceID" << deviceID << '\n'; + cout << "userName" << userName << '\n'; + cout << "totalInteractionTime" << totalInteractionTime << '\n'; + + + // is there logged stuff that hasn't been uploaded yet? + + // don't actually need to load old ones unless uploading? or saving... + //while(eventLogFile >> nextLine){ + + //} + + eventLogFile.close(); + +} + +void EventLogger::firstEverAppOpen(){ + deviceID = ofGetSystemTimeMicros(); + + // somehow prompt for username + userName = "Dennis"; + totalInteractionTime = 0; +} + +void EventLogger::exitAndSave(){ + // save user details + string fname = ofxiPhoneGetDocumentsDirectory() + "eventlog.dat"; + ofstream logFile(fname.c_str()); + logFile << deviceID << '\n'; + logFile << userName << '\n'; + totalInteractionTime = totalInteractionTime + sessionTime; + logFile << totalInteractionTime << '\n'; + + if(theEvents.size() > 0){ + attemptUpload(); + + // if (failed upload) save logged evts to file + cout << "Saving un-uploaded logs\n"; + vector<lEvent>::iterator evtIter; + + for(evtIter = theEvents.begin(); evtIter < theEvents.end(); evtIter++){ + + logFile << *evtIter << "\n"; + } + } + logFile.close(); + } \ No newline at end of file
--- a/grid.h Thu Dec 06 13:55:58 2012 +0000 +++ b/grid.h Thu Dec 06 18:26:51 2012 +0000 @@ -15,6 +15,7 @@ #include "eventLogger.h" #include "presetManager.h" using namespace std; +class Preset; class Grid { private: @@ -37,6 +38,7 @@ TwoVector snapCentre; TwoVector snapDist; // number of pixels to snap to + Preset * closestPreset; // pointer to the currently selected (snapped to ) preset.. NULL if none. bool maxZoom, minZoom; int cubeWidth; // side of hypercube. 2 for binary coding.
--- a/grid.mm Thu Dec 06 13:55:58 2012 +0000 +++ b/grid.mm Thu Dec 06 18:26:51 2012 +0000 @@ -103,7 +103,7 @@ vcode[i].push_back(code[i][j]); } } - + /* // now try with iterators to print... vector< vector<bool> >::iterator cit; //vector<bool>::iterator bit; @@ -120,7 +120,7 @@ cout << "\n"; } - /* + // codeToInt unit test vector<bool> aCode = vcode[12]; int result = grayToInt(aCode); @@ -369,6 +369,13 @@ //----------------------------------------------------------------------- void Grid::drawPresets(){ presetManager.drawPresetsInRange(topLeft, topLeft + size); + // draw snapped preset info + if(snapped && closestPreset != NULL){ + ostringstream temp; + temp << "Name: \t" << closestPreset->name << "\nCreation time: \t" << closestPreset->savetime << '\n'; + string s = temp.str(); + ofDrawBitmapString( s, pixSize.x/2+10, pixSize.y/2+10 ); + } } //----------------------------------------------------------------------- @@ -468,7 +475,7 @@ //-------------------------------------------------------------- void Grid::snapCheck(){ // check environs for presets. - Preset * closestPreset; + vector<Preset *> closePresets = presetManager.getPresetsInRange(centre - snapDist*scale, centre + snapDist*scale); if(closePresets.size() > 0){ snapped = true; @@ -488,6 +495,7 @@ }else{ snapped = false; + closestPreset = NULL; snapCentre = centre; } @@ -499,6 +507,8 @@ size.x = maxValue*2.0; scale = size.x/pixSize.x; size.y = scale * pixSize.y; + maxZoom = true; + minZoom = false; viewWasChanged(); } //-------------------------------------------------------------- @@ -507,6 +517,8 @@ size.x = minValue*2.0; scale = size.x/pixSize.x; size.y = scale * pixSize.y; + minZoom = true; + maxZoom = false; viewWasChanged(); } //--------------------------------------------------------------
--- a/presetManager.h Thu Dec 06 13:55:58 2012 +0000 +++ b/presetManager.h Thu Dec 06 18:26:51 2012 +0000 @@ -20,7 +20,7 @@ //--------------------------------------------------------------------------- class Preset{ public: - + string userName; int presetID; string name; long long savetime; @@ -118,11 +118,10 @@ is >> stime >> delim >> px >> delim >> py; if(!is){ - cout << "problem reading preset file"; return(is); } TwoVector pcoord(px,py); - int n = p.loadPreset(pcoord, pname, stime); + p.loadPreset(pcoord, pname, stime); return(is); }
--- a/presetManager.mm Thu Dec 06 13:55:58 2012 +0000 +++ b/presetManager.mm Thu Dec 06 18:26:51 2012 +0000 @@ -59,6 +59,8 @@ timesOpened = 0; nextID = 0; + string ts = ofGetTimestampString(); + cout << "ofGetTimestampString: " << ts << '\n'; } //--------------------------------------------------------------------------- @@ -168,6 +170,8 @@ } while(presetFile >> *this); + //TODO get presets from online database... + presetFile.close(); timesOpened++;
--- a/testApp.mm Thu Dec 06 13:55:58 2012 +0000 +++ b/testApp.mm Thu Dec 06 18:26:51 2012 +0000 @@ -5,7 +5,7 @@ extern PresetManager presetManager; extern EventLogger eventLogger; extern Frequencer frequencer; - +//DeviceID3523537000 //-------------------------------------------------------------- void testApp::setup(){ ofSetOrientation(OF_ORIENTATION_90_LEFT); @@ -28,14 +28,6 @@ touch0.setCoord(17./7., 2./3.); touch1.setCoord(10,20); - TwoVector ttest; - string str = "(4.5,7.8)"; - stringstream sstr; - sstr << str; - sstr >> ttest; - cout << "ttest: " << ttest << "\n"; - - prevTouch0.setCoord(1,2); prevTouch1.setCoord(10,20); prevDist = 10; @@ -84,6 +76,7 @@ ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3); presetManager.startupLoadAll(); + eventLogger.init(); } #pragma mark GUI @@ -95,9 +88,7 @@ zoomGUI->addLabelToggle("SWITCH VIEW", false); zoomGUI->addLabelButton("SAVE PRESET", false); - - zoomGUI->addLabelToggle("LOCK SEQUENCE (X)", false); - zoomGUI->addLabelToggle("LOCK SYNTH (Y)", false); + zoomGUI->addLabelButton("ZOOM MIN", false); zoomGUI->addLabelButton("ZOOM MAX", false); @@ -145,25 +136,7 @@ // this wont work // HACK just name it after time - }else if(e.widget->getName() == "LOCK SEQUENCE (X)") - { - - cout << "LOCK SEQUENCE (X)\n"; - // lock - xLocked = !xLocked; - presetManager.clearAll(); - }else if(e.widget->getName() == "LOCK SYNTH (Y)") - { - - cout << "LOCK SYNTH (Y)\n"; - // lock - if(((ofxUIButton *)e.widget)->getValue()){ - yLocked = true; - }else{ - yLocked = false; - - } }else if(e.widget->getName() == "ZOOM MIN") { if(((ofxUIButton *)e.widget)->getValue()){ @@ -193,9 +166,12 @@ float dim = 42; // LEFT GUI - standardGUI = new ofxUICanvas(0,0,length+90,ofGetHeight()-90); + standardGUI = new ofxUICanvas(0,0,length+90,ofGetHeight()); + ofxUILabelToggle * butt = standardGUI->addLabelToggle("LOCK SEQUENCE (X)", false); + butt->setColorFill(ofColor(0,0,255)); + butt->setColorFillHighlight(ofColor(0,0,255)); // Uh.. loop this for(int i = 1; i<=10;i++){ @@ -215,6 +191,10 @@ sliders.push_back(slider); } + ofxUILabelToggle * butt2 = standardGUI->addLabelToggle("LOCK SYNTH (Y)", false); + butt2->setColorFill(ofColor(255,0,0)); + butt2->setColorFillHighlight(ofColor(255,0,0)); + ofAddListener(standardGUI->newGUIEvent, this, &testApp::standardGUIEvent); standardGUI->loadSettings(ofxiPhoneGetDocumentsDirectory() + "guiSettings.xml"); @@ -225,6 +205,28 @@ cout << "GUI ERROR"; return; } + + if(e.widget->getName() == "LOCK SEQUENCE (X)") + { + + cout << "LOCK SEQUENCE (X)\n"; + // lock + xLocked = !xLocked; + //presetManager.clearAll(); + + }else if(e.widget->getName() == "LOCK SYNTH (Y)") + { + + cout << "LOCK SYNTH (Y)\n"; + // lock + if(((ofxUIButton *)e.widget)->getValue()){ + yLocked = true; + }else{ + yLocked = false; + + } + } + // "normal" parameter changes for(int i = 1; i<=10;i++){ stringstream ss; @@ -375,6 +377,7 @@ void testApp::exit(){ presetManager.exitAndSaveAll(); + eventLogger.exitAndSave(); core.exit(); delete standardGUI; @@ -426,6 +429,10 @@ // TODO check if in GUI area if(touch.x < 256) return; } + // check if in other gui area + if(touch.x > ofGetWidth()-200 && touch.y < 300){ + return; + } // which one? keep track of each touch point if(touch.id == 0){ @@ -511,6 +518,7 @@ return; } + // check if in // which one? if(touch.id == 0){