comparison src/requests.tp @ 46:e9e01cd64993

Fix decoding of JSON problem array
author Mike Pavone <pavone@retrodev.com>
date Sun, 11 Aug 2013 02:32:06 -0700
parents 4750da71cae6
children 855c05c9cae1
comparison
equal deleted inserted replaced
45:b90ccee0bace 46:e9e01cd64993
118 } 118 }
119 } 119 }
120 } 120 }
121 } else: { 121 } else: {
122 #{print <- print: "HTTP response gave error! code was: " . _code . "\n"} 122 #{print <- print: "HTTP response gave error! code was: " . _code . "\n"}
123 123
124 } 124 }
125 } 125 }
126 126
127 guessResponse <- :httpResp { 127 guessResponse <- :httpResp {
128 _code <- httpResp statusCode 128 _code <- httpResp statusCode
177 #{print <- print: "HTTP response gave error! code was: " . _code . "\n"} 177 #{print <- print: "HTTP response gave error! code was: " . _code . "\n"}
178 } 178 }
179 } 179 }
180 180
181 _problem <- :decoded { 181 _problem <- :decoded {
182 #{ 182 _id <- decoded get: "id" withDefault: -1
183 id <- decoded get: "id" withDefault: -1 183 _size <- decoded get: "size" withDefault: -1
184 size <- decoded get: "size" withDefault: -1 184 _ops <- decoded get: "operators" withDefault: #[]
185 operators <- decoded get: "operators" withDefault: #[] 185 _timeLeft <- decoded get: "timeLeft" withDefault: 301
186 _challenge <- decoded get: "challenge" withDefault: ""
187 #{
188 id <- { _id }
189 size <- { _size }
190 operators <- { _ops }
186 //solved <- decoded get: "solved" withDefault: false // todo: B ool up ean this son of a j 191 //solved <- decoded get: "solved" withDefault: false // todo: B ool up ean this son of a j
187 timeLeft <- decoded get: "timeLeft" withDefault: 301 192 timeLeft <- { _timeLeft }
188 // training problems have a challenge, real ones do not.: 193 // training problems have a challenge, real ones do not.:
189 challenge <- decoded get: "challenge" withDefault: "" 194 challenge <- { _challenge }
190 string <- { 195 string <- {
191 str <- "problem '" . id . "' has size '" . size . "' and operators:" 196 str <- "problem '" . id . "' has size '" . size . "' and operators:"
192 foreach: operators :idx val { 197 foreach: operators :idx val {
193 str <- str . "\n " . (string: idx) . ": " . val 198 str <- str . "\n " . (string: idx) . ": " . val
194 } 199 }
195 str . "\ntimeLeft: " . timeLeft 200 str . "\ntimeLeft: " . timeLeft
205 _problem: decoded 210 _problem: decoded
206 } 211 }
207 212
208 problems <- :bod { 213 problems <- :bod {
209 decoded <- json decode: bod 214 decoded <- json decode: bod
210 decoded map: :idx el{ 215 decoded map: :el{
211 _problem: el 216 _problem: el
212 } 217 }
213 } 218 }
214 219
215 main <- :args { 220 main <- :args {
221 226
222 //print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n" 227 //print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n"
223 //print: ((guess: "someId" "someProg") string) . "\n" 228 //print: ((guess: "someId" "someProg") string) . "\n"
224 //print: ((problem: someProblem) string) . "\n" 229 //print: ((problem: someProblem) string) . "\n"
225 230
226 file <- os open: "/home/wbm25/Desktop/icfp2013/data/myproblems.json" (os O_RDONLY) 231 file <- os open: "data/myproblems.json" (os O_RDONLY)
227 fstr <- (os read: file 400 * 1024) // file was 276k before bonus problems... 232 fstr <- (os read: file 400 * 1024) // file was 276k before bonus problems...
228 os close: file 233 os close: file
229 234
230 print: (((problems: fstr) get: 0) string ) 235 print: (((problems: fstr) get: 0) string )
231 236