Skip to content

Instantly share code, notes, and snippets.

@bhenry
Created October 20, 2010 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhenry/8dbce1459f942b64c3a2 to your computer and use it in GitHub Desktop.
Save bhenry/8dbce1459f942b64c3a2 to your computer and use it in GitHub Desktop.
(defn spreadsheet
"takes a collection of scores and makes output for a *.xls"
[cards]
(str
(format "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n"
"Operator First"
"Operator Last"
"Operator Username"
"Client Account Number"
"Client Name"
"Evaluator First"
"Evaluator Last"
"Evaluator Username"
"Entry Time"
"Call Time"
"Scored"
"Possible"
"Percentage"
"ID")
(apply str
(for [sc cards]
(format "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n"
(:first-name (:operator sc))
(:last-name (:operator sc))
(:user-name (:operator sc))
(:account-number (:client sc))
(:account-name (:client sc))
(:first-name (:evaluator sc))
(:last-name (:evaluator sc))
(:user-name (:evaluator sc))
(html/display-date (:timestamp sc))
(html/display-date (:call-date sc))
(html/display-number (:scored (:grade sc)))
(html/display-number (:possible (:grade sc)))
(format "%.2f%%" (* 100.0 (:percentage (:grade sc))))
(str (:_id sc)))))))
(defn export
[cards]
{:status 200
:headers {"Content-Type" "application/octet-stream"
"Content-Disposition" (format
"attachment; filename=qa-%s.xls"
(html/display-date (date) false))
"Pragma" "no-cache"
"Expires" "0"}
:body (spreadsheet cards)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment