comparison src/requests.tp @ 36:c42d3c8b1d75

problem response json is parsed, also works with training problems. tested.
author William Morgan <bill@mrgn.org>
date Sat, 10 Aug 2013 23:30:12 -0700
parents 9d5c3b078c78
children 4750da71cae6
comparison
equal deleted inserted replaced
35:9d5c3b078c78 36:c42d3c8b1d75
176 } else: { 176 } else: {
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 <- : str { 181 problem <- :bod {
182 182 decoded <- json decode: bod
183 #{
184 id <- decoded get: "id" withDefault: -1
185 size <- decoded get: "size" withDefault: -1
186 operators <- decoded get: "operators" withDefault: #[]
187 //solved <- decoded get: "solved" withDefault: false // todo: B ool up ean this son of a j
188 timeLeft <- decoded get: "timeLeft" withDefault: 301
189 // training problems have a challenge, real ones do not.:
190 challenge <- decoded get: "challenge" withDefault: ""
191 string <- {
192 str <- "problem '" . id . "' has size '" . size . "' and operators:"
193 foreach: operators :idx val {
194 str <- str . "\n " . (string: idx) . ": " . val
195 }
196 str . "\ntimeLeft: " . timeLeft
197 }
198 print <- {
199 print: string . "\n"
200 }
201 }
183 } 202 }
184 203
185 main <- :args { 204 main <- :args {
205 testId0 <- "wdThP1AgVrS2rp7q6qt9mLqp" // TRAINING PROGRAM ID! not real one. response in data folder.
206 testId1 <- "QwhG7ZpaVsfXiLRvbJfIfxl8" // TRAINING PROGRAM ID! not real one. response in data folder.
207 someProblem <- "{\"id\":\"QwhG7ZpaVsfXiLRvbJfIfxl8\",\"size\":15,\"operators\":[\"and\",\"if0\",\"shl1\",\"shr16\",\"tfold\"]}"
208 someProgram <- "(lambda (input) (shl1 input))"
209
186 //print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n" 210 //print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n"
187 //print: ((guess: "someId" "someProg") string) . "\n" 211 //print: ((guess: "someId" "someProg") string) . "\n"
212 print: ((problem: someProblem) string) . "\n"
188 213
189 if: (args length) > 1 { 214 if: (args length) > 1 {
190 key <- args get: 1 215 key <- args get: 1
191 testId <- "wdThP1AgVrS2rp7q6qt9mLqp" // my first training problem
192 someId <- "QwhG7ZpaVsfXiLRvbJfIfxl8" // TRAINING PROGRAM IDs!!! not real ones.
193
194 someProgram <- "(lambda (input) (shl1 input))"
195 216
196 //print: ((evalProgram: "(lambda (input) (shl1 input))" #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) 217 //print: ((evalProgram: "(lambda (input) (shl1 input))" #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key)
197 //print: ((evalId: testId #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) 218 //print: ((evalId: testId0 #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key)
198 print: ((guess: testId someProgram) sendWithKey: key) 219 print: ((guess: testId0 someProgram) sendWithKey: key)
199 220
200 } 221 }
201 } 222 }
202 } 223 }