Skip to content

Commit

Permalink
Add start-calculate-endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneenders committed Sep 1, 2024
1 parent 881bf7b commit 1463448
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
8 changes: 8 additions & 0 deletions infra/testApi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ const calculate = await (await fetch(makeEndpoint("/api/calculate"), {
})).json()
assertIdAndPath(calculate)
assert.deepEqual(calculate.points, [[[1], -1.4142135623730951]])
const calculateAsyncResult = await callAsyncAndWaitJSONResult("/api/start/calculate", {
method: 'POST', body: JSON.stringify({
formula: FPCoreFormula2, sample: eval_sample
})
})
assertIdAndPath(calculateAsyncResult)
assert.deepEqual(calculateAsyncResult.points, [[[1], -1.4142135623730951]])


// Cost endpoint
const cost = await (await fetch(makeEndpoint("/api/cost"), {
Expand Down
31 changes: 14 additions & 17 deletions src/api/demo.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
[("api" "start" "explanations") #:method "post" start-explanations-endpoint]
[("api" "start" "analyze") #:method "post" start-analyze-endpoint]
[("api" "start" "exacts") #:method "post" start-exacts-endpoint]
[("api" "start" "calculate") #:method "post" start-calculate-endpoint]
[("improve") #:method (or "post" "get" "put") improve]
[("check-status" (string-arg)) check-status]
[("timeline" (string-arg)) get-timeline]
Expand Down Expand Up @@ -456,23 +457,19 @@
(define exacts-endpoint (make-sync-endpoint exacts-common))
(define start-exacts-endpoint (make-async-endpoint exacts-common))

(define calculate-endpoint
(post-with-json-response (lambda (post-data)
(define formula
(read-syntax 'web (open-input-string (hash-ref post-data 'formula))))
(define sample (hash-ref post-data 'sample))
(define seed (hash-ref post-data 'seed #f))
(define test (parse-test formula))
(define pcontext (json->pcontext sample (test-context test)))
(define command
(create-job 'evaluate
test
#:seed seed
#:pcontext pcontext
#:profile? #f
#:timeline-disabled? #t))
(define id (start-job command))
(wait-for-job id))))
(define (calculate-common post-data)
(define formula (read-syntax 'web (open-input-string (hash-ref post-data 'formula))))
(define sample (hash-ref post-data 'sample))
(define seed (hash-ref post-data 'seed #f))
(define test (parse-test formula))
(define pcontext (json->pcontext sample (test-context test)))
(define command
(create-job 'evaluate test #:seed seed #:pcontext pcontext #:profile? #f #:timeline-disabled? #t))
(define job-id (start-job command))
(hasheq 'job job-id 'path (make-path job-id)))

(define calculate-endpoint (make-sync-endpoint calculate-common))
(define start-calculate-endpoint (make-async-endpoint calculate-common))

(define local-error-endpoint
(post-with-json-response (lambda (post-data)
Expand Down

0 comments on commit 1463448

Please sign in to comment.