소스 검색

don't force entry of prediction text every time, since prediction has unique ID

George C. Privon 6 년 전
부모
커밋
3b8fae716c
2개의 변경된 파일5개의 추가작업 그리고 6개의 파일을 삭제
  1. 1 1
      code/create_database.rkt
  2. 4 5
      code/update_predictions.rkt

+ 1 - 1
code/create_database.rkt

@@ -16,7 +16,7 @@
                                 #:mode 'create))
   (query-exec conn "CREATE TABLE predictions (ID INTEGER NOT NULL,
 date TEXT NOT NULL,
-prediction TEXT NOT NULL,
+prediction TEXT DEFAULT NULL,
 categories TEXT DEFAULT '',
 forecast float DEFAULT NULL,
 outcome int DEFAULT NULL,

+ 4 - 5
code/update_predictions.rkt

@@ -65,9 +65,9 @@
 ; 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 DESC LIMIT 1"
+    [(not (knownoutcome? ID)) (print (query-row conn "SELECT ID, prediction FROM predictions where ID=? ORDER BY date ASC LIMIT 1"
                                   ID))])
-  (display "\n"))
+  (display "\n")) ; TODO: need to remove this newline because it prints even if the outcome is known
 
 ; update a prediction
 (define (updatepred ID)
@@ -88,11 +88,10 @@
   (define outcome (string->number (getinput "What is the outcome (0 for didn't happen, 1 for happened)")))
   (define outcomedate (getinput "What was the date of the outcome (YYYY-MM-DD)"))
   (define comments (getinput "Comments on the outcome"))
-  (define prediction (query-value conn "SELECT prediction FROM predictions WHERE ID=? ORDER BY DATE DESC LIMIT 1" ID))
   (cond
     [(not (or (eq? outcome 0) (eq? outcome 1))) (error "Outcome must be 0 or 1.\n")])
-  (query-exec conn "INSERT INTO predictions (ID, date, prediction, outcome, comments) values (?, ?, ?, ?, ?)"
-              ID outcomedate prediction outcome comments))
+  (query-exec conn "INSERT INTO predictions (ID, date, outcome, comments) values (?, ?, ?, ?, ?)"
+              ID outcomedate outcome comments))
 
 ; enter an outcome for a prediction
 (define (showoutcome)