Add visualization

main
Eric Ihli 3 years ago
parent e611e71838
commit ae679954d2

@ -1,6 +1,7 @@
(ns user (ns user
(:require [clojure.string :as string] (:require [clojure.string :as string]
[clojure.tools.deps.alpha.repl :refer [add-lib]] [clojure.tools.deps.alpha.repl :refer [add-lib]]
[oz.core :as oz]
[clojure.tools.namespace.repl :refer [set-refresh-dirs]] [clojure.tools.namespace.repl :refer [set-refresh-dirs]]
[integrant.repl :as repl] [integrant.repl :as repl]
[taoensso.carmine :as car] [taoensso.carmine :as car]
@ -149,3 +150,15 @@
"/wgu/foo.html")) "/wgu/foo.html"))
) )
(comment
(require '[oz.core :as oz])
(oz/embed-for-html
[:vega-lite
{:data {:values [{:a 1 :b 2} {:a 3 :b 5} {:a 4 :b 2}]}
:mark :point
:encoding {:x {:field :a}
:y {:field :b}}}])
:done-comment)

@ -1,6 +1,7 @@
(ns com.darklimericks.server.views (ns com.darklimericks.server.views
(:require [hiccup.form :as form] (:require [hiccup.form :as form]
[hiccup.page :as page] [hiccup.page :as page]
[oz.core :as oz]
[clojure.string :as string] [clojure.string :as string]
[com.darklimericks.db.albums :as db.albums] [com.darklimericks.db.albums :as db.albums]
[com.darklimericks.db.artists :as db.artists] [com.darklimericks.db.artists :as db.artists]
@ -97,7 +98,9 @@
css :css css :css
:or {title "DarkLimericks" :or {title "DarkLimericks"
css ["/assets/tachyons.css"] css ["/assets/tachyons.css"]
js ["/assets/wgu/main.js"]} js ["/assets/vega.js"
"/assets/vega-lite.js"
"/assets/vega-embed.js" ]}
:as opts} :opts} :as opts} :opts}
& body] & body]
(println (keys request)) (println (keys request))
@ -287,6 +290,8 @@
[:div [:div
[:h2 "Generate Rhyme"] [:h2 "Generate Rhyme"]
(when rhymes
rhymes)
[:div [:div
[:p.tl "Use the input field below to enter a word or phrase and view a list [:p.tl "Use the input field below to enter a word or phrase and view a list
of words that rhyme. Rhyming words will be sorted by a quality score that represents of words that rhyme. Rhyming words will be sorted by a quality score that represents
@ -304,9 +309,7 @@ how well the rhyme matches your target."]]
"rhyme-target") "rhyme-target")
(form/submit-button (form/submit-button
{:class "ml2"} {:class "ml2"}
"Show rhyme suggestions")) "Show rhyme suggestions"))]
(when rhymes
rhymes)]
[:div [:div
[:h2 "Generate Rhyming Lyric"] [:h2 "Generate Rhyming Lyric"]
@ -319,8 +322,8 @@ then copy and paste that rhyming phrase into the Generate Lyric From Seed field
to generate many lines that all end with that specific phrase."] to generate many lines that all end with that specific phrase."]
(form/form-to (form/form-to
[:get (util/route-name->path [:get (util/route-name->path
request request
:com.darklimericks.server.router/lyric-from-seed)] :com.darklimericks.server.router/lyric-from-seed)]
(form/label (form/label
"lyric-from-seed" "lyric-from-seed"
"Target word or phrase for which to find a rhyming lyric") "Target word or phrase for which to find a rhyming lyric")
@ -346,8 +349,8 @@ field above to find a rhyming phrase that you like, then use this field to gener
prefixes to that rhyming phrase."] prefixes to that rhyming phrase."]
(form/form-to (form/form-to
[:get (util/route-name->path [:get (util/route-name->path
request request
:com.darklimericks.server.router/rhyming-lyric)] :com.darklimericks.server.router/rhyming-lyric)]
(form/label (form/label
"rhyming-lyric-target" "rhyming-lyric-target"
"Target word or phrase for which to generate prefixes") "Target word or phrase for which to generate prefixes")
@ -363,6 +366,12 @@ prefixes to that rhyming phrase."]
[:div#myChart] [:div#myChart]
[:br] [:br]
[:br] [:br]
(oz/embed-for-html
[:vega
{:data {:values [{:a 1 :b 2} {:a 3 :b 5} {:a 4 :b 2}]}
:mark :point
:encoding {:x {:field :a}
:y {:field :b}}}])
[:br] [:br]
[:iframe {:src "/assets/README_WGU.htm" [:iframe {:src "/assets/README_WGU.htm"
:style "background-color: white; width: 100%; height: 760px;"}]]) :style "background-color: white; width: 100%; height: 760px;"}]])
@ -420,6 +429,20 @@ prefixes to that rhyming phrase."]
request request
{:rhymes {:rhymes
[:div [:div
(oz/embed-for-html
[:vega-lite
{:name :rhyme-quality-popularity
:mark {:type :point :tooltip {:content :rhyme-quality-popularity}}
:encoding {:x {:field :freq :scale {:nice true :type :log}}
:y {:field :quality :sort :descending}}
:data {:values
(for [{:keys [word pronunciation rhyme-quality freq]} top-20-rhyme
i (range 1)]
{:word word
:quality rhyme-quality
:freq freq
:index i})}}])
[:table {:style "margin: auto;"} [:table {:style "margin: auto;"}
[:tr [:th "Rhyme"] [:th "Pronunciation"] [:th "Quality"] [:th "Frequency"]] [:tr [:th "Rhyme"] [:th "Pronunciation"] [:th "Quality"] [:th "Frequency"]]
(for [{:keys [word pronunciation rhyme-quality freq]} top-20-rhyme] (for [{:keys [word pronunciation rhyme-quality freq]} top-20-rhyme]

Loading…
Cancel
Save