comparison QuestionnaireViewController.mm @ 22:8c0783739337

Logs uploading. Questionnaire also.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Thu, 24 Jan 2013 18:14:40 +0000
parents 650589cac373
children dae6d77657a0
comparison
equal deleted inserted replaced
21:650589cac373 22:8c0783739337
12 12
13 #pragma mark - 13 #pragma mark -
14 #pragma mark QuestionnaireViewController 14 #pragma mark QuestionnaireViewController
15 15
16 @interface QuestionnaireViewController () 16 @interface QuestionnaireViewController ()
17 // the "model" is an array of questions and a bunch of answers 17 // the "model" is an array of questions
18 @property (strong, nonatomic) NSArray * questionArray; 18 @property (strong, nonatomic) NSArray * questionArray;
19 @property (strong, nonatomic) NSArray * answerTypeArray;
20 @property (strong, nonatomic) NSMutableArray * answerArray;
21 @property (nonatomic) NSInteger currentQuestionIndex; 19 @property (nonatomic) NSInteger currentQuestionIndex;
22 @property (nonatomic, assign) id theOFAppRef; 20 @property (nonatomic, assign) id theOFAppRef;
23 21
24 /* 22 /*
25 23
29 @end 27 @end
30 28
31 @implementation QuestionnaireViewController 29 @implementation QuestionnaireViewController
32 30
33 @synthesize picker; 31 @synthesize picker;
34 @synthesize agreeAnswer;
35 @synthesize agreeType;
36 @synthesize answerTypeArray;
37 @synthesize nextButton = _nextButton; 32 @synthesize nextButton = _nextButton;
38 @synthesize segControl = _segControl; 33 @synthesize questionArray;
34
39 35
40 //---------------------------------------------------------------- 36 //----------------------------------------------------------------
41 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 37 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
42 { 38 {
43 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 39 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
44 if (self) { 40 if (self) {
45 // Custom initialization 41 // Custom initialization
46 42
47 [self populateQuestionArray ]; 43 [self populateQuestionArray ];
48 [self populateAnswerArray];
49 44
50 } 45 }
51 return self; 46 return self;
52 } 47 }
53 - (void)setAppRef:(id)theOFApp{ 48 - (void)setAppRef:(id)theOFApp{
58 - (void)viewDidLoad 53 - (void)viewDidLoad
59 { 54 {
60 [super viewDidLoad]; 55 [super viewDidLoad];
61 // Do any additional setup after loading the view from its nib. 56 // Do any additional setup after loading the view from its nib.
62 self.currentQuestionIndex = 0; 57 self.currentQuestionIndex = 0;
63 // load question 1 58
64 59 // load question 1
65 self.agreeAnswer = [[NSArray alloc] initWithObjects:
66 @"Strongly disagree", @"Disagree", @"Neither",
67 @"Agree", @"Strongly agree", nil];
68
69 self.interfaceAnswer = [[NSArray alloc] initWithObjects:
70 @"Definitely Sliders", @"Maybe Sliders", @"Neither",
71 @"Maybe Zoomer", @"Definitely Zoomer", nil];
72 agreeType = YES;
73
74 [self loadQuestion:self.currentQuestionIndex]; 60 [self loadQuestion:self.currentQuestionIndex];
61
62 self.previousButton.hidden = YES; // dont bother
63
75 } 64 }
76 //---------------------------------------------------------------- 65 //----------------------------------------------------------------
77 - (void)didReceiveMemoryWarning 66 - (void)didReceiveMemoryWarning
78 { 67 {
79 [super didReceiveMemoryWarning]; 68 [super didReceiveMemoryWarning];
84 73
85 [_questionText release]; 74 [_questionText release];
86 [_titleText release]; 75 [_titleText release];
87 [_finishButton release]; 76 [_finishButton release];
88 [_nextButton release]; 77 [_nextButton release];
89 [_segControl release]; 78 [_previousButton release];
90 [super dealloc]; 79 [super dealloc];
91 } 80 }
92 //---------------------------------------------------------------- 81 //----------------------------------------------------------------
93 - (void)viewDidUnload { 82 - (void)viewDidUnload {
94 [self setQuestionText:nil]; 83 [self setQuestionText:nil];
95 [self setTitleText:nil]; 84 [self setTitleText:nil];
96 [self setFinishButton:nil]; 85 [self setFinishButton:nil];
97 [self setNextButton:nil]; 86 [self setNextButton:nil];
98 [self setSegControl:nil]; 87 [self setPreviousButton:nil];
99 [super viewDidUnload]; 88 [super viewDidUnload];
100 } 89 }
101 //---------------------------------------------------------------- 90 //----------------------------------------------------------------
102 - (IBAction)answerWasSelected:(id)sender {
103 // look at property?
104
105 }
106
107 //----------------------------------------------------------------
108 -(IBAction)hide:(id)sender{ 91 -(IBAction)hide:(id)sender{
92 // called when finish button hit
109 // c++ call with NSArray argument?? 93 // c++ call with NSArray argument??
110 ((testApp *)self.theOFAppRef)->questionnaireHidden(self.answerArray); 94 // load answers into a c++ vector;
95 vector<int> answersArray;
96
97 Question *q;
98
99 for(int i=0;i<[questionArray count];i++){
100 q = [questionArray objectAtIndex:i];
101 answersArray.push_back(q.answer);
102
103 }
104
105 ((testApp *)self.theOFAppRef)->questionnaireHidden(answersArray);
111 self.view.hidden = YES; 106 self.view.hidden = YES;
112 } 107 }
113 //---------------------------------------------------------------- 108 //----------------------------------------------------------------
114 -(IBAction)show:(id)sender{ 109 -(IBAction)show:(id)sender{
115 self.view.hidden = NO; 110 self.view.hidden = NO;
137 self.currentQuestionIndex = 0; 132 self.currentQuestionIndex = 0;
138 }else{ 133 }else{
139 [self loadQuestion:self.currentQuestionIndex]; 134 [self loadQuestion:self.currentQuestionIndex];
140 } 135 }
141 } 136 }
142 //---------------------------------------------------------------- 137
143
144 // NAH
145 - (IBAction)answerSelected:(id)sender {
146 // nice short lines of code.
147
148 [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:self.segControl.selectedSegmentIndex]];
149
150 // chek wot we just rote
151
152 NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]);
153
154
155 }
156 //---------------------------------------------------------------- 138 //----------------------------------------------------------------
157 139
158 - (void)showThanks{ 140 - (void)showThanks{
159 // hide next question button 141 // hide next question button
160 self.nextButton.hidden = YES; 142 self.nextButton.hidden = YES;
161 // hide selector 143 // hide selector
162 self.segControl.hidden = YES; 144 self.picker.hidden = YES;
163 145 self.previousButton.hidden = YES;
164 146
165 self.titleText.text = @"Thank you!"; 147 self.titleText.text = @"Thank you!";
166 148
167 self.questionText.text = @"Thanks for helping science help you. Visit the study website to keep abreast of exciting events."; 149 self.questionText.text = @"Thanks for helping science help you. Visit the study website to keep abreast of exciting events.";
168 } 150 }
172 // populate text fields with question 154 // populate text fields with question
173 NSString *qtitle; 155 NSString *qtitle;
174 qtitle = [@"Question " stringByAppendingFormat:@"%d / 16",questionIndex+1]; 156 qtitle = [@"Question " stringByAppendingFormat:@"%d / 16",questionIndex+1];
175 self.titleText.text = qtitle; 157 self.titleText.text = qtitle;
176 158
177 self.questionText.text = [self.questionArray objectAtIndex:questionIndex]; 159 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
178 160
179 // if question already answered show that 161 self.questionText.text = curQ.questionText;
180 NSInteger answerInt = [[self.answerArray objectAtIndex:questionIndex] integerValue]; 162
181 163
182 // set different answer type 164 // refresh picker view content
183 agreeType = [answerTypeArray objectAtIndex:questionIndex];
184 // then refresh picker view content
185 [picker reloadComponent:0]; 165 [picker reloadComponent:0];
186 166
187 167
188 // DUZZNT WERK 168 NSLog(@"Prev answer answerInt %d", curQ.answer);
189 if(answerInt==-1){ 169 [picker selectRow:curQ.answer inComponent:0 animated:YES];
190 // select "neither" (2) 170
191 NSLog(@"No answer answerInt %d", answerInt);
192 [picker selectRow:2 inComponent:0 animated:YES];
193
194 }else{
195 // select previous answer
196 NSLog(@"Prev answer answerInt %d", answerInt);
197 [picker selectRow:answerInt inComponent:0 animated:YES];
198 }
199 } 171 }
200 //---------------------------------------------------------------- 172 //----------------------------------------------------------------
201 - (void)populateQuestionArray{ 173 - (void)populateQuestionArray{
202 self.questionArray = [[NSArray alloc] initWithObjects: 174
203 @"I am familiar with music software and synthesisers.", 175 self.questionArray = [NSArray arrayWithObjects:
204 @"The best way to get a feel for the possibilities of the synth was with:", 176 [[Question alloc] initWithTextAndType:@"I am familiar with music software and sound synthesis.":AGREE_DISAGREE],
205 @"Interesting sounds could be discovered more quickly as a result of using:", 177 [[Question alloc] initWithTextAndType:@"The best way to get a feel for the possibilities of the synth was with:":SLIDERS_ZOOMER],
206 @"A sound could be fine tuned more easily using:", 178 [[Question alloc] initWithTextAndType:@"Interesting sounds could be discovered more quickly as a result of using:":SLIDERS_ZOOMER],
207 @"The correspondence between the sliders and the grid was understandable.", 179 [[Question alloc] initWithTextAndType:@"A sound could be fine tuned more easily using:":SLIDERS_ZOOMER],
208 @"The interface that felt more familiar was:", 180 [[Question alloc] initWithTextAndType:@"The correspondence between the sliders and the grid was understandable.":AGREE_DISAGREE],
209 @"Scrolling a greater distance the zoom grid seemed to correspond to larger difference in the sound.", 181 [[Question alloc] initWithTextAndType:@"The interface that felt more familiar was:":SLIDERS_ZOOMER],
210 @"The ability to see other presets on the grid was useful.", 182 [[Question alloc] initWithTextAndType:@"Scrolling a greater distance the zoom grid seemed to correspond to larger difference in the sound.":AGREE_DISAGREE],
211 @"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.", 183 [[Question alloc] initWithTextAndType:@"The ability to see other presets on the grid was useful.":AGREE_DISAGREE],
212 @"The interface better for generating new ideas was", 184 [[Question alloc] initWithTextAndType:@"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.":AGREE_DISAGREE],
213 @"The interface better for live performance would be:", 185 [[Question alloc] initWithTextAndType:@"The interface better for generating new ideas was":SLIDERS_ZOOMER],
214 @"A specific type of sound could be found more quickly using:", 186 [[Question alloc] initWithTextAndType:@"The interface better for live performance would be:":SLIDERS_ZOOMER],
215 @"I felt more in control when using:", 187 [[Question alloc] initWithTextAndType:@"A specific type of sound could be found more quickly using:":SLIDERS_ZOOMER],
216 @"The Zoomer was an improvement on just using a randomiser.", 188 [[Question alloc] initWithTextAndType:@"I felt more in control when using:":SLIDERS_ZOOMER],
217 @"The combination of Zoomer and Sliders was more useful than either individually.", 189 [[Question alloc] initWithTextAndType:@"The Zoomer was an improvement on just using a randomiser.":AGREE_DISAGREE],
218 @"Overall, I preferred using:", 190 [[Question alloc] initWithTextAndType:@"The combination of Zoomer and Sliders was better than either individually.":AGREE_DISAGREE],
191 [[Question alloc] initWithTextAndType:@"Overall, I preferred using:":SLIDERS_ZOOMER],
219 nil]; 192 nil];
220 self.answerTypeArray = [[NSArray alloc] initWithObjects: 193
221 YES, 194 }
222 NO, 195
223 NO,
224 NO,
225 YES,
226 NO,
227 YES,
228 YES,
229 YES,
230 NO,
231 NO,
232 NO,
233 NO,
234 YES,
235 YES,
236 NO,
237 nil]
238 }
239 //----------------------------------------------------------------
240 - (void)populateAnswerArray{
241 int N = [self.questionArray count];
242
243 //[self.answerArray initWithCapacity:N]; // necessary?
244 self.answerArray = [[NSMutableArray alloc] initWithCapacity:N];
245 // set the number to what?
246 for(int i=0;i<N;i++){
247 [self.answerArray addObject:[NSNumber numberWithInt:-1]];
248 }
249
250 }
251 //---------------------------------------------------------------- 196 //----------------------------------------------------------------
252 #pragma mark - 197 #pragma mark -
253 #pragma mark PickerView DataSource 198 #pragma mark PickerView DataSource
254 199
255 - (NSInteger)numberOfComponentsInPickerView: 200 - (NSInteger)numberOfComponentsInPickerView:
256 (UIPickerView *)pickerView 201 (UIPickerView *)pickerView
257 { 202 {
258 return 1; 203 return 1;
259 } 204 }
205 //----------------------------------------------------------------
260 - (NSInteger)pickerView:(UIPickerView *)pickerView 206 - (NSInteger)pickerView:(UIPickerView *)pickerView
261 numberOfRowsInComponent:(NSInteger)component 207 numberOfRowsInComponent:(NSInteger)component
262 { 208 {
263 return [agreeAnswer count]; // always 5 209 return 6; // always 6
264 } 210 }
211 //----------------------------------------------------------------
265 - (NSString *)pickerView:(UIPickerView *)pickerView 212 - (NSString *)pickerView:(UIPickerView *)pickerView
266 titleForRow:(NSInteger)row 213 titleForRow:(NSInteger)row
267 forComponent:(NSInteger)component 214 forComponent:(NSInteger)component
268 { 215 {
269 if(agreeType){ 216 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
270 return [agreeAnswer objectAtIndex:row]; 217
271 }else{ 218 // get array of answers from Question class
272 return [interfaceAnswer objectAtIndex:row]; 219 NSArray * answers = [Question answersWithType:curQ.questionType];
273 } 220 return [answers objectAtIndex:row];
274 } 221
275 222 }
223 //----------------------------------------------------------------
276 #pragma mark - 224 #pragma mark -
277 #pragma mark PickerView Delegate 225 #pragma mark PickerView Delegate
278 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row 226 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
279 inComponent:(NSInteger)component 227 inComponent:(NSInteger)component
280 { 228 {
281 229 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
282 // set question answerArray 230 // set question answerArray
283 [self.answerArray replaceObjectAtIndex:self.currentQuestionIndex withObject:[NSNumber numberWithInteger:row]]; 231 curQ.answer = row;
284 232
285 // chek wot we just rote 233 // chek wot we just rote
286 234
287 NSLog(@"%@",[self.answerArray objectAtIndex:self.currentQuestionIndex]); 235 NSLog(@"Answer: %d",curQ.answer);
288 /* 236
289 float rate = [[exchangeRates objectAtIndex:row] floatValue];
290 float dollars = [dollarText.text floatValue];
291 float result = dollars * rate;
292
293 NSString *resultString = [[NSString alloc] initWithFormat:
294 @"%.2f USD = %.2f %@", dollars, result,
295 [countryNames objectAtIndex:row]];
296 resultLabel.text = resultString;
297 */
298 } 237 }
299 238
300 @end // end implementation 239 @end // end implementation
301 //---------------------------------------------------------------- 240 //----------------------------------------------------------------
302 //---------------------------------------------------------------- 241 //----------------------------------------------------------------