-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
config.edn | ||
target/ | ||
jeopardy.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(ns com.tylerkindy.jeopardy.clues | ||
(:require [clojure.string :as str] | ||
[com.tylerkindy.jeopardy.answer :refer [char-pairs normalize-answer]] | ||
[next.jdbc :refer [execute! get-datasource]] | ||
[next.jdbc.result-set :refer [as-unqualified-kebab-maps]]) | ||
(:import [java.time LocalDate])) | ||
|
||
(def ds (get-datasource {:dbtype "sqlite" | ||
:dbname "jeopardy.db"})) | ||
|
||
(defn valid-answer? [answer] | ||
(seq (char-pairs answer))) | ||
|
||
(defn valid-clue? [{:keys [question value answer]}] | ||
(let [question (str/lower-case question)] | ||
(and value | ||
(not (str/includes? question "seen here")) | ||
(not (str/includes? question "shown here")) | ||
(not (str/includes? question "heard here")) | ||
(valid-answer? (normalize-answer answer))))) | ||
|
||
(defn clean-clue [clue] | ||
(-> clue | ||
(update :airdate #(LocalDate/parse %)))) | ||
|
||
(def random-clues-q | ||
(str/join "\n" ["select" | ||
" ca.name as category," | ||
" g.airdate," | ||
" cl.question," | ||
" cl.answer," | ||
" cl.value" | ||
"from clues as cl" | ||
"join categories as ca on cl.category_id = ca.id" | ||
"join games as g on cl.game_id = g.id" | ||
"order by random()" | ||
"limit ?"])) | ||
|
||
(defn random-clues [n] | ||
(->> (execute! ds [random-clues-q n] | ||
{:builder-fn as-unqualified-kebab-maps}) | ||
(filter valid-clue?) | ||
(map clean-clue))) | ||
|
||
(defn random-clue [] | ||
(first (random-clues 10))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.