Răsfoiți Sursa

Merge branch '4_reuse_params'

George C. Privon 2 ani în urmă
părinte
comite
96b80a62e0
2 a modificat fișierele cu 44 adăugiri și 15 ștergeri
  1. 2 1
      create_database.rkt
  2. 42 14
      update_proposals.rkt

+ 2 - 1
create_database.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang typed/racket/base
 
 ;; This program creates a sqlite3 database and then creates an empty table
 ;; for information on proposals.
@@ -7,6 +7,7 @@
          "config.rkt") ; load configuration file
 
 ; create the database and create the table
+(: createdb (-> String))
 (define (createdb dbloc)
   (write-string (string-append "Creating database " dbloc "\n"))
   (define conn (sqlite3-connect #:database dbloc

+ 42 - 14
update_proposals.rkt

@@ -4,6 +4,7 @@
 
 (require racket/cmdline
          racket/date
+         racket/list
          db
          "config.rkt") ; load configuration file
 
@@ -17,6 +18,10 @@
 ; start and end date to sub-select proposals within a given range
 (define start-date (make-parameter #f))
 (define end-date (make-parameter #f))
+; if #t, use proposal type, submitting organiation, solicitation/call, and
+; telescope name from the most recently submitted (i.e., highest ID) proposal
+(define reuse-params (make-parameter #f))
+
 ; set up command line arguments
 (define mode (command-line
               #:program "update_proposals"
@@ -25,6 +30,8 @@
                                      (start-date sd)]
               [("-e" "--end-date") ed "End of date range (YYYY-MM-DD)"
                                    (end-date ed)]
+              [("-r" "--reuse-parameters") "Reuse/auto-fill proposal type, submitting organization, solicitation/call and telescope name from the most recently added proposal."
+                                           (reuse-params #t)]
               #:args ([updatetype "help"]) ; (add, update, list-open, list-closed, help)
               updatetype))
 
@@ -38,12 +45,12 @@
   (displayln " update\t\t - update a proposal with results.")
   (displayln " stats\t\t - print summary statistics.")
   (displayln " list-open\t - Show all submitted (but not resolved) proposals.")
-  (displayln " list-closed\t - Show all resolved proposals.")
+  (displayln " list-closed\t - Show all resolved (accepted and rejected) proposals.")
   (displayln " list-accepted\t - Show accepted proposals.")
   (displayln " list-rejected\t - Show rejected proposals.")
   (displayln " help\t\t - Show this help message.")
   (newline)
-  (displayln "Copyright 2019-2020, 2022 George C. Privon"))
+  (displayln "Copyright 2019-2020, 2022-2023 George C. Privon"))
 
 ; set up a condensed prompt for getting information
 (define (getinput prompt)
@@ -69,25 +76,46 @@
               (vector-ref entry 3)
               "\"")))
 
+(define (get-last-proposal-call conn)
+  (println "Adopting proposal information from last submission")
+  (last-proposal-call conn))
+
+; get information from the most recent proposal submission
+(define (last-proposal-call conn)
+  (vector->list (query-row conn "SELECT type, organization, solicitation, telescope FROM proposals ORDER BY id DESC LIMIT 1")))
+
 ; add a new proposal to the database
 (define (addnew conn)
+  ; full list of input fileds that we will need (these will be the prompts
+  ; to the user)
+  (define input-fields (list "Proposal type"
+                             "Submitting Organization"
+                             "Solicitation/Call"
+                             "Telescope"
+                             "Proposal Title"
+                             "PI"
+                             "CoIs"
+                             "Submit date (YYYY-MM-DD)"
+                             "Organization's propsal ID"))
   (displayln "Adding new proposal to database.")
-  ; user inputs proposal data
-  (define proptype (getinput "Proposal type"))
-  (define org (getinput "Submitting organization"))
-  (define solic (getinput "Solitation/call"))
-  (define tele (getinput "Telescope"))
-  (define title (getinput "Proposal title"))
-  (define pi (getinput "PI"))
-  (define coi (getinput "CoIs"))
   ; assume all these proposals are submitted, don't ask the user
   (define status "submitted")
-  (define submitdate (getinput "Submit date (YYYY-MM-DD)"))
-  (define oID (getinput "Organization's proposal ID"))
+
+  ; get the proposal information
+  (define propinfo
+    (cond
+      ; if we're re-using parameters, get info from the most recent submission
+      ; and append the user input for the remaining fields
+      [(reuse-params) (append (get-last-proposal-call conn)
+                              (map getinput (list-tail input-fields 4)))]
+      ; if not using previous information, ask the user for all inputs
+      [else (map getinput input-fields)]))
 
   ; do the INSERT into the Sqlite database
-  (query-exec conn "INSERT INTO proposals (type, organization, solicitation, telescope, PI, title, CoI, status, submitdate, orgpropID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
-              proptype org solic tele pi title coi status submitdate oID))
+  (let* ([add-proposal-info
+           (prepare conn "INSERT INTO proposals (type, organization, solicitation, telescope, title, PI, CoI, submitdate, orgpropID, status) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")])
+         (query-exec conn (bind-prepared-statement add-proposal-info
+                                                   (flatten (list propinfo status))))))
 
 ; update an entry with new status (accepted, rejected, etc.)
 (define (update conn ID)