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@8
|
27
|
rt300@29
|
28 #import "ServerComms.h"
|
rt300@29
|
29
|
rt300@28
|
30 #define EVENT_THIN_FACTOR 10
|
rt300@25
|
31 #define EVENT_LOG_FILENAME "log.json"
|
rt300@29
|
32 //#define LOGGING_SERVER_URL "http://www.isophonics.net/datacollector/"
|
rt300@29
|
33 #define LOGGING_SERVER_URL "http://127.0.0.1:8080/testservice/"
|
rt300@29
|
34 #define UPLOAD_CHUNK_SIZE 100
|
rt300@29
|
35
|
rt300@25
|
36 #define QUESTIONNAIRE_ENABLE_TIME 100000 // milliseconds
|
rt300@29
|
37 #define APP_CREATION_TIME 381429000000 // milliseconds to the time i wrote this wee blighter saves digits
|
rt300@25
|
38
|
rt300@29
|
39 #define PROGRAM_VERSION 0.1 // IMPORTANT TOCHNAGE!
|
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@27
|
61 HELP_PRESSED}; // 19
|
rt300@1
|
62
|
rt300@8
|
63 //---------------------------------------------------------------------------
|
rt300@8
|
64
|
rt300@4
|
65 class lEvent{
|
rt300@5
|
66 public:
|
rt300@1
|
67 // try and make this as compact as possible.
|
rt300@4
|
68 leventType eventType;
|
rt300@1
|
69 double val1; // x coord, scale if zoom
|
rt300@1
|
70 double val2; // y coord, 0 if zoom
|
rt300@25
|
71 int sliderID; // xtra int
|
rt300@9
|
72 long long eventTime;
|
rt300@8
|
73 lEvent(leventType eType, double v1 = 0.0, double v2 = 0.0,int sID = 0){
|
rt300@5
|
74 eventType = eType;
|
rt300@5
|
75 val1 = v1;
|
rt300@5
|
76 val2 = v2;
|
rt300@5
|
77 sliderID = sID;
|
rt300@9
|
78
|
rt300@28
|
79 double timemsd = [NSDate timeIntervalSinceReferenceDate]; // MILLISECONDS
|
rt300@25
|
80 eventTime = (unsigned long long)(timemsd*1000) - APP_CREATION_TIME;
|
rt300@9
|
81
|
rt300@5
|
82 }
|
rt300@25
|
83
|
rt300@8
|
84 lEvent(const Json::Value &jevt){
|
rt300@9
|
85 // constructor takes "jsonToEvent" readfile function role
|
rt300@25
|
86 eventType = (leventType)jevt["eType"].asInt();
|
rt300@25
|
87 val1 = jevt["v1"].asDouble();
|
rt300@25
|
88 val2 = jevt["v2"].asDouble();
|
rt300@25
|
89 sliderID = jevt["sID"].asInt();
|
rt300@25
|
90 eventTime = jevt["eTime"].asLargestInt();
|
rt300@9
|
91
|
rt300@15
|
92 // TODO what happens if we try to read one that isn't there?
|
rt300@15
|
93
|
rt300@8
|
94 }
|
rt300@8
|
95 Json::Value eventToJson(){
|
rt300@8
|
96 Json::Value jevt;
|
rt300@25
|
97 jevt["eType"] = eventType;
|
rt300@25
|
98 // here: should give a certain number of sig figs?
|
rt300@25
|
99 jevt["v1"] = val1;
|
rt300@25
|
100 jevt["v2"] = val2;
|
rt300@25
|
101 jevt["sID"] = sliderID;
|
rt300@25
|
102 jevt["eTime"] = eventTime;
|
rt300@8
|
103 return jevt;
|
rt300@8
|
104 }
|
rt300@5
|
105 };
|
rt300@5
|
106 //---------------------------------------------------------------------------
|
rt300@8
|
107 // streams no longer used
|
rt300@5
|
108 inline istream& operator>>(istream & is, lEvent& e){
|
rt300@5
|
109 is.setf(ios_base::fixed,ios_base::floatfield);
|
rt300@5
|
110 is.precision(1);
|
rt300@4
|
111
|
rt300@5
|
112 char delim;
|
rt300@5
|
113 int eType;
|
rt300@0
|
114
|
rt300@5
|
115 is >> eType >> delim >> e.val1 >> delim >> e.val2 >> delim >> e.sliderID;
|
rt300@5
|
116
|
rt300@5
|
117 e.eventType = (leventType)eType;
|
rt300@5
|
118
|
rt300@5
|
119 return is;
|
rt300@5
|
120 }
|
rt300@4
|
121
|
rt300@5
|
122 //---------------------------------------------------------------------------
|
rt300@5
|
123 inline ostream& operator<<(ostream & os, const lEvent& e){
|
rt300@5
|
124 os.setf(ios_base::fixed,ios_base::floatfield);
|
rt300@5
|
125 os.precision(1);
|
rt300@5
|
126
|
rt300@5
|
127 os << e.eventType << ',' << e.val1 << ',' << e.val2 << ',' << e.sliderID << '\n';
|
rt300@5
|
128
|
rt300@5
|
129 return os;
|
rt300@7
|
130 }
|
rt300@5
|
131 //---------------------------------------------------------------------------
|
rt300@29
|
132
|
rt300@29
|
133 class ThreadedObject: ofThread{
|
rt300@29
|
134 int i;
|
rt300@29
|
135 int threadedFunc(int i){
|
rt300@29
|
136 return i + 10;
|
rt300@29
|
137 };
|
rt300@29
|
138 };
|
rt300@29
|
139
|
rt300@29
|
140
|
rt300@0
|
141 class EventLogger{
|
rt300@0
|
142 public:
|
rt300@25
|
143 int nextUploadNumber;
|
rt300@14
|
144 bool loggingEnabled;
|
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@29
|
150 unsigned int deviceID;
|
rt300@25
|
151 unsigned int totalInteractionTime, savedInteractionTime, sessionTime, sessionStartTime;
|
rt300@14
|
152 string userName; // not unique
|
rt300@27
|
153
|
rt300@14
|
154 EventLogger();
|
rt300@14
|
155 void init();
|
rt300@14
|
156 void exitAndSave();
|
rt300@14
|
157 void setUsername(const char *u);
|
rt300@27
|
158 void newUser();
|
rt300@14
|
159 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
|
160 void questionnaireAnswersObtained(vector<int> answers, const char* userComments);
|
rt300@27
|
161 void urlResponse(ofHttpResponse & response);
|
rt300@14
|
162 private:
|
rt300@14
|
163
|
rt300@27
|
164 int currentHTTPRequestID;
|
rt300@29
|
165
|
rt300@29
|
166
|
rt300@4
|
167 vector<lEvent> theEvents;
|
rt300@29
|
168
|
rt300@28
|
169 void thinnedLogEvent(lEvent nextEvent);
|
rt300@14
|
170 unsigned int nextUploadQty;
|
rt300@14
|
171
|
rt300@28
|
172 string questionnaireComments;
|
rt300@8
|
173
|
rt300@22
|
174 ofxiPhoneDeviceType iOSdeviceType;
|
rt300@14
|
175
|
rt300@9
|
176 bool testConnection();
|
rt300@22
|
177 vector<int> questionnaireAnswers;
|
rt300@28
|
178 int interfaceOrder;
|
rt300@9
|
179
|
rt300@27
|
180
|
rt300@7
|
181 void checkLogFile();
|
rt300@29
|
182 void deleteLogs(); // new user
|
rt300@27
|
183 bool uploadEventLog(bool async);
|
rt300@7
|
184 void firstEverAppOpen();
|
rt300@8
|
185 void readJsonToLog(const string &jsonFile);
|
rt300@27
|
186 void uploadQuestionnaire();
|
rt300@27
|
187 bool sendToServer(string functionName, Json::Value jsonData, bool async);
|
rt300@8
|
188 Json::Value logsToJson();
|
rt300@22
|
189 Json::Value questionnaireToJson();
|
rt300@5
|
190 void printAll(){
|
rt300@5
|
191 cout << "ALL LOGGED EVENTS!: \n";
|
rt300@5
|
192 vector<lEvent>::iterator evIter;
|
rt300@5
|
193 for(evIter = theEvents.begin(); evIter < theEvents.end(); evIter++){
|
rt300@5
|
194 cout << *evIter;
|
rt300@5
|
195
|
rt300@5
|
196 }
|
rt300@5
|
197 };
|
rt300@29
|
198
|
rt300@29
|
199 //
|
rt300@29
|
200 ServerComms *serverComms;
|
rt300@29
|
201
|
rt300@0
|
202 };
|
rt300@0
|
203
|
rt300@0
|
204
|
rt300@8
|
205 //---------------------------------------------------------------------------
|
rt300@8
|
206
|
rt300@5
|
207
|
rt300@0
|
208 #endif /* defined(__oscSenderExample__eventLogger__) */
|