Mercurial > repos > icfp2013
annotate src/requests.tp @ 59:3c8d8fdd32a1 default tip
mike's changes to solver
author | bill |
---|---|
date | Sun, 11 Aug 2013 15:24:22 -0700 |
parents | 8409af16d6e5 |
children |
rev | line source |
---|---|
10
79c1db5e7ebd
sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff
changeset
|
1 #{ |
18 | 2 |
20 | 3 strJoin <- :str arr { |
4 acc <- "" | |
5 arr foreach: :i el { | |
6 if: i = 0 { | |
7 acc <- (string: el) | |
8 } else: { | |
9 acc <- acc . ", " . (string: el) | |
10 } | |
11 } | |
12 acc | |
13 //arr fold: "" with: :acc el {acc . el} | |
14 } | |
15 | |
18 | 16 quote <- :str { |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
17 "\"" . str . "\"" |
18 | 18 } |
19 | |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
20 println <- :str { |
23 | 21 print: str . "\n" |
22 } | |
23 | |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
24 fixArgs <- :args { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
25 args map: :el { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
26 "\"0x" . (hex: el) . "\"" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
27 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
28 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
29 |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
30 |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
31 evalId <- :id args { |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
32 args <- fixArgs: args |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
33 #{ |
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
34 string <- { |
20 | 35 idStr <- (quote: "id") . ":" . (quote: id) |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
36 argsStr <- (quote: "arguments") . ":[" . (strJoin: "," args) . "]" |
18 | 37 "{" . idStr . "," . argsStr . "}" |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
38 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
39 sendWithKey <- :key { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
40 print: "Sending: " . string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
41 cli <- http client: "icfpc2013.cloudapp.net" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
42 resp <- cli post: string toPath: "/eval?auth=" . key withType: "application/json" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
43 evalResponse: resp |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
44 } |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
45 } |
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
46 } |
10
79c1db5e7ebd
sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff
changeset
|
47 |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
48 evalProgram <- :program args { |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
49 args <- fixArgs: args |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
50 #{ |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
51 string <- { |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
52 progStr <- (quote: "program") . ":" . (quote: program) |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
53 argsStr <- (quote: "arguments") . ":[" . (strJoin: "," args) . "]" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
54 "{" . progStr . "," . argsStr . "}" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
55 } |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
56 sendWithKey <- :key { |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
57 print: "Sending: " . string . "\n" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
58 cli <- http client: "icfpc2013.cloudapp.net" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
59 resp <- cli post: string toPath: "/eval?auth=" . key withType: "application/json" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
60 evalResponse: resp |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
61 } |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
62 } |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
63 } |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
64 |
31
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
65 guess <- :id :prog { |
15
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
66 #{ |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
67 string <- { |
17
566960135ea1
Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
68 idStr <- "\"id\":\"" . id . "\"" |
566960135ea1
Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
69 progStr <- "\"program\":\"" . prog . "\"" |
566960135ea1
Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
70 "{" . idStr . "," . progStr . "}" |
15
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
71 } |
31
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
72 sendWithKey <- :key { |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
73 print: "Sending: " . string . "\n" |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
74 cli <- http client: "icfpc2013.cloudapp.net" |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
75 resp <- cli post: string toPath: "/guess?auth=" . key withType: "application/json" |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
76 guessResponse: resp |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
77 } |
15
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
78 } |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
79 } |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
80 |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
81 evalResponse <- :httpResp { |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
82 _code <- httpResp statusCode |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
83 bod <- httpResp body |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
84 print: "Response code: " . (string: _code) . "\n" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
85 print: bod . "\n" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
86 decoded <- json decode: bod |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
87 _status <- "error" |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
88 if: _code = 200 { |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
89 _status <- decoded get: "status" withDefault: "error" |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
90 if: _status = "ok" { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
91 _outputs <- (decoded get: "outputs" withDefault: #[]) map: :num { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
92 (num from: 2) parseHex64 |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
93 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
94 #{ |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
95 status <- { "ok" } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
96 outputs <- { _outputs } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
97 string <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
98 str <- "OK:" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
99 foreach: _outputs :idx val { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
100 str <- str . "\n" . (string: idx) . ": 0x" . (hex: val) |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
101 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
102 str |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
103 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
104 print <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
105 print: string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
106 } |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
107 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
108 } else: { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
109 _message <- decoded get: "message" withDefault: "" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
110 #{ |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
111 status <- { "error" } |
49
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
112 httpCode <- { _code } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
113 message <- { _message } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
114 string <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
115 "Error: " . _message |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
116 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
117 print <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
118 print: string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
119 } |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
120 } |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
121 } |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
122 } else: { |
49
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
123 #{ |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
124 status <- { "error" } |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
125 httpCode <- { _code } |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
126 message <- { "HTTP response gave error! code was: " . _code . "\n" } |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
127 string <- { |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
128 "Error: " . message |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
129 } |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
130 print <- { |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
131 print: string . "\n" |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
132 } |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
133 } |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
134 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
135 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
136 |
26 | 137 guessResponse <- :httpResp { |
138 _code <- httpResp statusCode | |
139 bod <- httpResp body | |
140 print: "Response code: " . (string: _code) . "\n" | |
141 print: bod . "\n" | |
142 decoded <- json decode: bod | |
143 _status <- "error" | |
144 if: _code = 200 { | |
145 _status <- decoded get: "status" withDefault: "error" | |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
146 if: _status = "win" { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
147 #{ |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
148 status <- { "win" } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
149 string <- { "OK: win" } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
150 print <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
151 print: string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
152 } |
26 | 153 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
154 } else: { if: _status = "mismatch" { |
26 | 155 |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
156 _values <- (decoded get: "values" withDefault: #[]) map: :num { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
157 (num from: 2) parseHex64 |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
158 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
159 #{ |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
160 status <- { "mismatch" } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
161 values <- { _values } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
162 string <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
163 str <- "OK:" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
164 foreach: _values :idx val { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
165 str <- str . "\n" . (string: idx) . ": 0x" . (hex: val) |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
166 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
167 str |
26 | 168 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
169 print <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
170 print: string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
171 } |
26 | 172 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
173 } else: { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
174 _message <- decoded get: "message" withDefault: "" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
175 #{ |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
176 status <- { "error" } |
49
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
177 httpCode <- { _code } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
178 message <- { _message } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
179 string <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
180 "Error: " . _message |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
181 } |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
182 print <- { |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
183 print: string . "\n" |
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
184 } |
26 | 185 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
186 }} // end if |
26 | 187 } else: { |
49
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
188 #{ |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
189 status <- { "error" } |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
190 httpCode <- { _code } |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
191 message <- { "HTTP response gave error! code was: " . _code . "\n" } |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
192 string <- { |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
193 "Error: " . message |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
194 } |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
195 print <- { |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
196 print: string . "\n" |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
197 } |
8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
198 } |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
199 } |
26 | 200 } |
201 | |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
202 _problem <- :decoded { |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
203 _id <- decoded get: "id" withDefault: -1 |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
204 _size <- decoded get: "size" withDefault: -1 |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
205 _ops <- decoded get: "operators" withDefault: #[] |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
206 _timeLeft <- decoded get: "timeLeft" withDefault: 301 |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
207 _challenge <- decoded get: "challenge" withDefault: "" |
48
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
208 _solved <- decoded get: "solved" withDefault: false |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
209 #{ |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
210 id <- { _id } |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
211 size <- { _size } |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
212 operators <- { _ops } |
48
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
213 solved <- { _solved } |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
214 timeLeft <- { _timeLeft } |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
215 // training problems have a challenge, real ones do not.: |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
216 challenge <- { _challenge } |
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
217 string <- { |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
218 str <- "problem '" . id . "' has size '" . size . "' and operators:" |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
219 foreach: operators :idx val { |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
220 str <- str . "\n " . (string: idx) . ": " . val |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
221 } |
48
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
222 str <- str . "\nsolved?: " . (if: solved { "true" } else: { "false" }) |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
223 str . "\ntimeLeft: " . timeLeft |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
224 } |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
225 print <- { |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
226 print: string . "\n" |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
227 } |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
228 } |
35 | 229 } |
230 | |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
231 problem <- :bod { |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
232 decoded <- json decode: bod |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
233 _problem: decoded |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
234 } |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
235 |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
236 problems <- :bod { |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
237 decoded <- json decode: bod |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
238 decoded map: :el{ |
48
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
239 p <- _problem: el |
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
240 //print: p |
855c05c9cae1
Updated myproblems.json. Some solver fixes
Mike Pavone <pavone@retrodev.com>
parents:
46
diff
changeset
|
241 p |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
242 } |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
243 } |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
244 |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
245 main <- :args { |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
246 print: "Program Start." |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
247 testId0 <- "wdThP1AgVrS2rp7q6qt9mLqp" // TRAINING PROGRAM ID! not real one. response in data folder. |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
248 testId1 <- "QwhG7ZpaVsfXiLRvbJfIfxl8" // TRAINING PROGRAM ID! not real one. response in data folder. |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
249 someProblem <- "{\"id\":\"QwhG7ZpaVsfXiLRvbJfIfxl8\",\"size\":15,\"operators\":[\"and\",\"if0\",\"shl1\",\"shr16\",\"tfold\"]}" |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
250 someProgram <- "(lambda (input) (shl1 input))" |
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
251 |
31
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
252 //print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n" |
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
253 //print: ((guess: "someId" "someProg") string) . "\n" |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
254 //print: ((problem: someProblem) string) . "\n" |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
255 |
46
e9e01cd64993
Fix decoding of JSON problem array
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
256 file <- os open: "data/myproblems.json" (os O_RDONLY) |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
257 fstr <- (os read: file 400 * 1024) // file was 276k before bonus problems... |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
258 os close: file |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
259 |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
260 print: (((problems: fstr) get: 0) string ) |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
261 |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
262 |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
263 |
25
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
264 if: (args length) > 1 { |
bb80f86c5048
Added code for sending and decoding the responses of evalRequests
Mike Pavone <pavone@retrodev.com>
parents:
24
diff
changeset
|
265 key <- args get: 1 |
31
8a2925ab0d4a
working guess request and response.
William Morgan <bill@mrgn.org>
parents:
30
diff
changeset
|
266 |
30
a4bffcd381cd
eval(id) request fixed. Fail gracefully on non-200 http response.
William Morgan <bill@mrgn.org>
parents:
26
diff
changeset
|
267 //print: ((evalProgram: "(lambda (input) (shl1 input))" #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) |
36
c42d3c8b1d75
problem response json is parsed, also works with training problems. tested.
William Morgan <bill@mrgn.org>
parents:
35
diff
changeset
|
268 //print: ((evalId: testId0 #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) |
41
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
269 //print: ((guess: testId0 someProgram) sendWithKey: key) |
4750da71cae6
parsing myproblems.json, needs fix
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
270 println: "derp" |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
271 } |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
272 } |
10
79c1db5e7ebd
sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff
changeset
|
273 } |