瀏覽代碼

improved output of open predictions

George C. Privon 6 年之前
父節點
當前提交
59fd72bf5b
共有 1 個文件被更改,包括 12 次插入4 次删除
  1. 12 4
      code/update_predictions.rkt

+ 12 - 4
code/update_predictions.rkt

@@ -62,12 +62,20 @@
                         ID)))
 
 ; print a prediction without a known outcome
-; TODO: beautify output, add latest prediction to the output
 (define (printpred ID)
   (cond
-    [(not (knownoutcome? ID)) (print (query-row conn "SELECT ID, prediction FROM predictions where ID=? ORDER BY date ASC LIMIT 1"
-                                  ID))])
-  (display "\n")) ; TODO: need to remove this newline because it prints even if the outcome is known
+    [(not (knownoutcome? ID)) (write-string ((λ (myID)
+                                              (define prediction (query-value conn "SELECT prediction FROM predictions WHERE ID=? ORDER BY date ASC LIMIT 1" myID))
+                                              (define latest (query-row conn "SELECT date, forecast FROM predictions WHERE ID=? ORDER BY date DESC LIMIT 1" myID))
+                                              (string-append (number->string myID)
+                                                              "("
+                                                              (vector-ref latest 0)
+                                                              ") "
+                                                              prediction
+                                                              ": "
+                                                              (number->string (vector-ref latest 1))
+                                                              "\n"))
+                                             ID))]))
 
 ; update a prediction
 (define (updatepred ID)