annotate eventLogger.h @ 43:b91a1859829a

used UIkit sliders
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 19 Apr 2013 18:50:04 +0100
parents 3d627dce8bf0
children a1e75b94c505
rev   line source
rt300@0 1 //
rt300@0 2 // eventLogger.h
rt300@0 3 // oscSenderExample
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 05/11/2012.
rt300@0 6 //
rt300@0 7 //
rt300@0 8 // This class handle everything to do with loggin user actions,
rt300@0 9 // uploading logs to server, and storing locally if not uploaded
rt300@0 10
rt300@0 11 #ifndef __oscSenderExample__eventLogger__
rt300@0 12 #define __oscSenderExample__eventLogger__
rt300@0 13
rt300@1 14
rt300@4 15 #include "ofMain.h"
rt300@4 16 #include "ofxiPhone.h"
rt300@4 17 #include "2dvector.h"
rt300@4 18 #include "ofxiPhoneExtras.h"
rt300@4 19 #include <sys/time.h>
rt300@4 20 #include <iostream>
rt300@4 21 #include <string>
rt300@22 22 #include <cstring>
rt300@4 23 #include <map>
rt300@4 24 #include "2dvector.h"
rt300@8 25 #include "json.h"
rt300@24 26 #include "testApp.h"
rt300@32 27 #include "presetManager.h"
rt300@29 28 #import "ServerComms.h"
rt300@33 29 #include "grid.h"
rt300@33 30
rt300@38 31 #define EVENT_THIN_FACTOR 12
rt300@25 32 #define EVENT_LOG_FILENAME "log.json"
rt300@42 33 #define UPLOAD_CHUNK_SIZE 1000
rt300@33 34 #define APP_CREATION_TIME 381429000000 // milliseconds to the time i wrote this wee blighter. saves digits
rt300@33 35 #define SCROLL_TRAIL_LENGTH 200
rt300@35 36 #define PROGRAM_VERSION 0.5 // NOW USES NEW HILBERT CURVE. ALL OLD PRESETS WILL BE INVALID :(
rt300@29 37
rt300@33 38 #define SUPERVISED // this def will save files
rt300@25 39
rt300@25 40
rt300@9 41 // can add but don't change ordering - this will invalidate logs
rt300@25 42 enum leventType {SAVE_PRESET, // 0
rt300@25 43 SAVE_DESET, // 1
rt300@25 44 SCROLL, // 2
rt300@25 45 ZOOM, // 3
rt300@25 46 SCROLL_STOPPED, // 4
rt300@25 47 ZOOM_STOPPED, // 5
rt300@25 48 SNAPPED_TO_PRESET, // 6
rt300@25 49 CHANGE_SLIDER, // 7
rt300@25 50 SWAP_VIEW, // 8
rt300@25 51 SET_MIN_ZOOM, // 9
rt300@25 52 SET_MAX_ZOOM, // 10
rt300@25 53 RANDOMISE, // 11
rt300@25 54 APP_STARTED, // 12
rt300@25 55 APP_EXITED, // 13
rt300@25 56 CONSENT_DENIED, // 14
rt300@25 57 SEQ_LOCKED, // 15
rt300@25 58 SYNTH_LOCKED, // 16
rt300@25 59 PLAY_PRESSED, // 17
rt300@27 60 PAUSE_PRESSED, // 18
rt300@31 61 HELP_PRESSED, // 19
rt300@33 62 QUESTIONNAIRE_COMPLETED, // 20
rt300@33 63 EVALUATION_POINT, // 21
rt300@39 64 EMPTY_EVENT, // 22
rt300@39 65 SMOOTHING_ON, // 23
rt300@39 66 SMOOTHING_OFF}; // 24
rt300@1 67
rt300@8 68 //---------------------------------------------------------------------------
rt300@8 69
rt300@4 70 class lEvent{
rt300@5 71 public:
rt300@1 72 // try and make this as compact as possible.
rt300@4 73 leventType eventType;
rt300@1 74 double val1; // x coord, scale if zoom
rt300@1 75 double val2; // y coord, 0 if zoom
rt300@25 76 int sliderID; // xtra int
rt300@32 77 long long eventTime; // MILLISECONDS since app creation
rt300@8 78 lEvent(leventType eType, double v1 = 0.0, double v2 = 0.0,int sID = 0){
rt300@5 79 eventType = eType;
rt300@5 80 val1 = v1;
rt300@5 81 val2 = v2;
rt300@5 82 sliderID = sID;
rt300@9 83
rt300@28 84 double timemsd = [NSDate timeIntervalSinceReferenceDate]; // MILLISECONDS
rt300@25 85 eventTime = (unsigned long long)(timemsd*1000) - APP_CREATION_TIME;
rt300@9 86
rt300@5 87 }
rt300@25 88
rt300@8 89 lEvent(const Json::Value &jevt){
rt300@9 90 // constructor takes "jsonToEvent" readfile function role
rt300@25 91 eventType = (leventType)jevt["eType"].asInt();
rt300@25 92 val1 = jevt["v1"].asDouble();
rt300@25 93 val2 = jevt["v2"].asDouble();
rt300@25 94 sliderID = jevt["sID"].asInt();
rt300@25 95 eventTime = jevt["eTime"].asLargestInt();
rt300@9 96
rt300@15 97 // TODO what happens if we try to read one that isn't there?
rt300@15 98
rt300@8 99 }
rt300@8 100 Json::Value eventToJson(){
rt300@8 101 Json::Value jevt;
rt300@25 102 jevt["eType"] = eventType;
rt300@25 103 // here: should give a certain number of sig figs?
rt300@25 104 jevt["v1"] = val1;
rt300@25 105 jevt["v2"] = val2;
rt300@25 106 jevt["sID"] = sliderID;
rt300@25 107 jevt["eTime"] = eventTime;
rt300@8 108 return jevt;
rt300@8 109 }
rt300@33 110 void draw();
rt300@5 111 };
rt300@5 112 //---------------------------------------------------------------------------
rt300@8 113 // streams no longer used
rt300@5 114 inline istream& operator>>(istream & is, lEvent& e){
rt300@5 115 is.setf(ios_base::fixed,ios_base::floatfield);
rt300@5 116 is.precision(1);
rt300@4 117
rt300@5 118 char delim;
rt300@5 119 int eType;
rt300@0 120
rt300@5 121 is >> eType >> delim >> e.val1 >> delim >> e.val2 >> delim >> e.sliderID;
rt300@5 122
rt300@5 123 e.eventType = (leventType)eType;
rt300@5 124
rt300@5 125 return is;
rt300@5 126 }
rt300@4 127
rt300@5 128 //---------------------------------------------------------------------------
rt300@5 129 inline ostream& operator<<(ostream & os, const lEvent& e){
rt300@5 130 os.setf(ios_base::fixed,ios_base::floatfield);
rt300@5 131 os.precision(1);
rt300@5 132
rt300@5 133 os << e.eventType << ',' << e.val1 << ',' << e.val2 << ',' << e.sliderID << '\n';
rt300@5 134
rt300@5 135 return os;
rt300@7 136 }
rt300@5 137 //---------------------------------------------------------------------------
rt300@32 138
rt300@29 139
rt300@0 140 class EventLogger{
rt300@0 141 public:
rt300@25 142 int nextUploadNumber;
rt300@14 143 bool loggingEnabled;
rt300@31 144
rt300@27 145 bool logUploadInProgress;
rt300@22 146 bool serverConnectionOK;
rt300@25 147 bool consentGiven;
rt300@29 148 bool questionnaireCompleted;
rt300@29 149 bool questionnaireUploaded;
rt300@31 150
rt300@29 151 unsigned int deviceID;
rt300@25 152 unsigned int totalInteractionTime, savedInteractionTime, sessionTime, sessionStartTime;
rt300@14 153 string userName; // not unique
rt300@27 154
rt300@31 155 // constr
rt300@14 156 EventLogger();
rt300@31 157
rt300@31 158 // public methods:
rt300@42 159 void startLoadAll();
rt300@14 160 void exitAndSave();
rt300@14 161 void setUsername(const char *u);
rt300@27 162 void newUser();
rt300@14 163 void logEvent(const leventType& evtType,const TwoVector& centre = TwoVector(), const double& scale = 1.0, const int& sliderID = -1, const double& sliderVal = 0.0);
rt300@28 164 void questionnaireAnswersObtained(vector<int> answers, const char* userComments);
rt300@27 165 void urlResponse(ofHttpResponse & response);
rt300@30 166
rt300@30 167 void questionnaireOK();
rt300@30 168 void eventlogOK();
rt300@30 169 void testConnectionOK();
rt300@30 170 void questionnaireNotOK();
rt300@30 171 void eventlogNotOK();
rt300@30 172 void testConnectionNotOK();
rt300@30 173
rt300@30 174 void printAll();
rt300@32 175 void saveSessionToFile();
rt300@33 176 void drawTrail(const TwoVector min, const TwoVector max);
rt300@33 177 vector<lEvent> getDrawableEventsInRange(const TwoVector min, const TwoVector max);
rt300@33 178 vector<TwoVector> getRecentPath(int numEvents);
rt300@38 179
rt300@38 180 void clearTrail();
rt300@14 181 private:
rt300@31 182
rt300@38 183 vector<lEvent> theEvents; // all logged but not uploaded events
rt300@38 184 deque<lEvent> eventsToDraw; // 200 or so drawable events, maybe uploaded maybe not
rt300@29 185
rt300@39 186 void thinnedSliderEvent(lEvent nextEvent);
rt300@39 187 void thinnedZoomEvent(lEvent nextEvent);
rt300@39 188 void thinnedSnapEvent(lEvent nextEvent);
rt300@33 189 void thinnedScrollEvent(lEvent nextEvent);
rt300@14 190 unsigned int nextUploadQty;
rt300@14 191
rt300@28 192 string questionnaireComments;
rt300@8 193
rt300@22 194 ofxiPhoneDeviceType iOSdeviceType;
rt300@14 195
rt300@42 196
rt300@22 197 vector<int> questionnaireAnswers;
rt300@28 198 int interfaceOrder;
rt300@9 199
rt300@31 200 // private methods
rt300@42 201 void testConnection();
rt300@7 202 void checkLogFile();
rt300@29 203 void deleteLogs(); // new user
rt300@27 204 bool uploadEventLog(bool async);
rt300@7 205 void firstEverAppOpen();
rt300@42 206 void loadExistingLogFile(const string &jsonFile);
rt300@27 207 void uploadQuestionnaire();
rt300@27 208 bool sendToServer(string functionName, Json::Value jsonData, bool async);
rt300@30 209
rt300@43 210
rt300@8 211 Json::Value logsToJson();
rt300@22 212 Json::Value questionnaireToJson();
rt300@30 213
rt300@29 214
rt300@29 215 //
rt300@29 216 ServerComms *serverComms;
rt300@29 217
rt300@0 218 };
rt300@0 219
rt300@0 220
rt300@8 221 //---------------------------------------------------------------------------
rt300@8 222
rt300@5 223
rt300@0 224 #endif /* defined(__oscSenderExample__eventLogger__) */