Mercurial > hg > soniczoomios
view eventLogger.h @ 27:ae4d2c3ce5e0
Details. Zoom trailing finger move sorted. Qs rephrased.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Wed, 13 Feb 2013 17:03:56 +0000 |
parents | f42a00e3f22d |
children | e2c62db1e265 |
line wrap: on
line source
// // eventLogger.h // oscSenderExample // // Created by Robert Tubb on 05/11/2012. // // // This class handle everything to do with loggin user actions, // uploading logs to server, and storing locally if not uploaded #ifndef __oscSenderExample__eventLogger__ #define __oscSenderExample__eventLogger__ #include "ofMain.h" #include "ofxiPhone.h" #include "2dvector.h" #include "ofxiPhoneExtras.h" #include <sys/time.h> #include <iostream> #include <string> #include <cstring> #include <map> #include "2dvector.h" #include "json.h" #include "testApp.h" #define EVENT_LOG_FILENAME "log.json" #define SERVER_URL "http://127.0.0.1:8080/testservice/" #define UPLOAD_CHUNK_SIZE 500 #define QUESTIONNAIRE_ENABLE_TIME 100000 // milliseconds #define APP_CREATION_TIME 381429000000 // milliseconds to the time i wrote this wee blighter #define PROGRAM_VERSION 1.0 // IMPORTANT TOCHNAGE! // can add but don't change ordering - this will invalidate logs enum leventType {SAVE_PRESET, // 0 SAVE_DESET, // 1 SCROLL, // 2 ZOOM, // 3 SCROLL_STOPPED, // 4 ZOOM_STOPPED, // 5 SNAPPED_TO_PRESET, // 6 CHANGE_SLIDER, // 7 SWAP_VIEW, // 8 SET_MIN_ZOOM, // 9 SET_MAX_ZOOM, // 10 RANDOMISE, // 11 APP_STARTED, // 12 APP_EXITED, // 13 CONSENT_DENIED, // 14 SEQ_LOCKED, // 15 SYNTH_LOCKED, // 16 PLAY_PRESSED, // 17 PAUSE_PRESSED, // 18 HELP_PRESSED}; // 19 //--------------------------------------------------------------------------- class lEvent{ public: // try and make this as compact as possible. leventType eventType; double val1; // x coord, scale if zoom double val2; // y coord, 0 if zoom int sliderID; // xtra int long long eventTime; lEvent(leventType eType, double v1 = 0.0, double v2 = 0.0,int sID = 0){ eventType = eType; val1 = v1; val2 = v2; sliderID = sID; double timemsd = [NSDate timeIntervalSinceReferenceDate]; eventTime = (unsigned long long)(timemsd*1000) - APP_CREATION_TIME; } lEvent(const Json::Value &jevt){ // constructor takes "jsonToEvent" readfile function role eventType = (leventType)jevt["eType"].asInt(); val1 = jevt["v1"].asDouble(); val2 = jevt["v2"].asDouble(); sliderID = jevt["sID"].asInt(); eventTime = jevt["eTime"].asLargestInt(); // TODO what happens if we try to read one that isn't there? } Json::Value eventToJson(){ Json::Value jevt; jevt["eType"] = eventType; // here: should give a certain number of sig figs? jevt["v1"] = val1; jevt["v2"] = val2; jevt["sID"] = sliderID; jevt["eTime"] = eventTime; return jevt; } }; //--------------------------------------------------------------------------- // streams no longer used inline istream& operator>>(istream & is, lEvent& e){ is.setf(ios_base::fixed,ios_base::floatfield); is.precision(1); char delim; int eType; is >> eType >> delim >> e.val1 >> delim >> e.val2 >> delim >> e.sliderID; e.eventType = (leventType)eType; return is; } //--------------------------------------------------------------------------- inline ostream& operator<<(ostream & os, const lEvent& e){ os.setf(ios_base::fixed,ios_base::floatfield); os.precision(1); os << e.eventType << ',' << e.val1 << ',' << e.val2 << ',' << e.sliderID << '\n'; return os; } //--------------------------------------------------------------------------- class EventLogger{ public: int nextUploadNumber; bool loggingEnabled; bool logUploadInProgress; bool serverConnectionOK; bool consentGiven; unsigned int deviceID; // unique get something from hardware?? unsigned int totalInteractionTime, savedInteractionTime, sessionTime, sessionStartTime; string userName; // not unique EventLogger(); void init(); void exitAndSave(); void setUsername(const char *u); void newUser(); void logEvent(const leventType& evtType,const TwoVector& centre = TwoVector(), const double& scale = 1.0, const int& sliderID = -1, const double& sliderVal = 0.0); void questionnaireAnswersObtained(vector<int> answers); void urlResponse(ofHttpResponse & response); private: // what we need... /* time, type, value */ int currentHTTPRequestID; vector<lEvent> theEvents; // values applicable to all events unsigned int nextUploadQty; ofxiPhoneDeviceType iOSdeviceType; bool testConnection(); vector<int> questionnaireAnswers; bool questionnaireCompleted; bool questionnaireUploaded; void checkLogFile(); bool uploadEventLog(bool async); void firstEverAppOpen(); void readJsonToLog(const string &jsonFile); void uploadQuestionnaire(); bool sendToServer(string functionName, Json::Value jsonData, bool async); Json::Value logsToJson(); Json::Value questionnaireToJson(); void printAll(){ cout << "ALL LOGGED EVENTS!: \n"; vector<lEvent>::iterator evIter; for(evIter = theEvents.begin(); evIter < theEvents.end(); evIter++){ cout << *evIter; } }; }; //--------------------------------------------------------------------------- #endif /* defined(__oscSenderExample__eventLogger__) */