# HG changeset patch # User Mike Pavone # Date 1376213526 25200 # Node ID e9e01cd64993cf77c6afc0019af81b9334bd41b6 # Parent b90ccee0baceded95d2eca841b9bd1f17eb3aea9 Fix decoding of JSON problem array diff -r b90ccee0bace -r e9e01cd64993 src/requests.tp --- a/src/requests.tp Sun Aug 11 02:18:55 2013 -0700 +++ b/src/requests.tp Sun Aug 11 02:32:06 2013 -0700 @@ -120,7 +120,7 @@ } } else: { #{print <- print: "HTTP response gave error! code was: " . _code . "\n"} - + } } @@ -179,15 +179,20 @@ } _problem <- :decoded { + _id <- decoded get: "id" withDefault: -1 + _size <- decoded get: "size" withDefault: -1 + _ops <- decoded get: "operators" withDefault: #[] + _timeLeft <- decoded get: "timeLeft" withDefault: 301 + _challenge <- decoded get: "challenge" withDefault: "" #{ - id <- decoded get: "id" withDefault: -1 - size <- decoded get: "size" withDefault: -1 - operators <- decoded get: "operators" withDefault: #[] + id <- { _id } + size <- { _size } + operators <- { _ops } //solved <- decoded get: "solved" withDefault: false // todo: B ool up ean this son of a j - timeLeft <- decoded get: "timeLeft" withDefault: 301 + timeLeft <- { _timeLeft } // training problems have a challenge, real ones do not.: - challenge <- decoded get: "challenge" withDefault: "" - string <- { + challenge <- { _challenge } + string <- { str <- "problem '" . id . "' has size '" . size . "' and operators:" foreach: operators :idx val { str <- str . "\n " . (string: idx) . ": " . val @@ -207,7 +212,7 @@ problems <- :bod { decoded <- json decode: bod - decoded map: :idx el{ + decoded map: :el{ _problem: el } } @@ -223,7 +228,7 @@ //print: ((guess: "someId" "someProg") string) . "\n" //print: ((problem: someProblem) string) . "\n" - file <- os open: "/home/wbm25/Desktop/icfp2013/data/myproblems.json" (os O_RDONLY) + file <- os open: "data/myproblems.json" (os O_RDONLY) fstr <- (os read: file 400 * 1024) // file was 276k before bonus problems... os close: file