From 0d3f91a966a18f6b9305c51bb41bfdc2150b2f57 Mon Sep 17 00:00:00 2001 From: Eric Ihli Date: Mon, 28 Jun 2021 10:30:03 -0500 Subject: [PATCH] Wrap with js --- README_WGU.org | 35 +++++++ util/five-number-summary.awk | 15 +++ util/five-number-summary.sh | 7 ++ .../com/darklimericks/linguistics/core.clj | 25 ++++- web/src/com/darklimericks/server/handlers.clj | 12 +-- web/src/com/darklimericks/server/views.clj | 93 ++++++++++++++++++- 6 files changed, 177 insertions(+), 10 deletions(-) create mode 100644 util/five-number-summary.awk create mode 100755 util/five-number-summary.sh diff --git a/README_WGU.org b/README_WGU.org index 3a89755..644d226 100644 --- a/README_WGU.org +++ b/README_WGU.org @@ -1,5 +1,40 @@ #+TITLE: Capstone Documentation +* C + +Design and develop a fully functional data product that addresses your identified business problem or organizational need. Include each of the following attributes as they are the minimum required elements for the product: + +** one descriptive method and one non-descriptive (predictive or prescriptive) method + +*** Descriptive Method + +- 10 most common sentence structures +- Average lyric length +- 5-number analysis of lyric length + +** collected or available datasets + +** decision-support functionality + +** ability to support featurizing, parsing, cleaning, and wrangling datasets + +** methods and algorithms supporting data exploration and preparation + +** data visualization functionalities for data exploration and inspection + +** implementation of interactive queries + +** implementation of machine-learning methods and algorithms + +** functionalities to evaluate the accuracy of the data product + +** industry-appropriate security features + +** tools to monitor and maintain the product + +** a user-friendly, functional dashboard that includes at least three visualization types + + * Documentation D. Create each of the following forms of documentation for the product you have developed: diff --git a/util/five-number-summary.awk b/util/five-number-summary.awk new file mode 100644 index 0000000..8db5857 --- /dev/null +++ b/util/five-number-summary.awk @@ -0,0 +1,15 @@ +# find ~/src/prhyme/dark-corpus -type f -print0 | xargs -0 wc -l | grep -v '[0-9]\{4,\}.*total$' | sort -n + +BEGIN { +} +{ + a += $1; + b[++i] = $1; +} +END { + m = a/NR; + q1 = sprintf("%d", NR * 0.25); + q2 = sprintf("%d", NR * 0.5); + q3 = sprintf("%d", NR * 0.75); + print sprintf("Min: %d, Q1: %d, Median: %d, Q3: %d, Max: %d", b[0], b[q1], b[q2], b[q3], b[NR]); +} diff --git a/util/five-number-summary.sh b/util/five-number-summary.sh new file mode 100755 index 0000000..fbb06ed --- /dev/null +++ b/util/five-number-summary.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +find ~/src/prhyme/dark-corpus -type f -print0 | \ + xargs -0 wc -l | \ + grep -v '[0-9]\{4,\}.*total$' | \ + sort -n | \ + awk -f five-number-summary.awk diff --git a/web/src/com/darklimericks/linguistics/core.clj b/web/src/com/darklimericks/linguistics/core.clj index 603219a..d1f870f 100644 --- a/web/src/com/darklimericks/linguistics/core.clj +++ b/web/src/com/darklimericks/linguistics/core.clj @@ -135,7 +135,7 @@ perfect-sans-consonants? (if (perfect-rhyme-sans-consonants? phones1 phones2) 1 0) num-matching-stressed (number-of-matching-vowels-with-stress phones1 phones2) num-matching-any-stress (number-of-matching-vowels-any-stress phones1 phones2) - same-number-of-syllables (same-number-of-syllables? phones1 phones2)] + same-number-of-syllables (if (same-number-of-syllables? phones1 phones2) 1 0)] (+ perfect? perfect-sans-consonants? num-matching-stressed @@ -258,6 +258,25 @@ ;; ["bog" ["B" "AO1" "G"] 42 "log" ["L" "AO1" "G"] 4]) ) + +(defn distinct-by + "Returns a stateful transducer that removes elements by calling f on each step as a uniqueness key. + Returns a lazy sequence when provided with a collection." + ([f] + (fn [rf] + (let [seen (volatile! #{})] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (let [v (f input)] + (if (contains? @seen v) + result + (do (vswap! seen conj v) + (rf result input))))))))) + ([f xs] + (sequence (distinct-by f) xs))) + (defn rhymes-with-frequencies-and-rhyme-quality [target trie database] (let [rhymes- (rhymes target) @@ -266,7 +285,9 @@ (assoc-phrases-with-phones) (append-freqs models/database models/markov-trie [1 1 1]) (append-rhyme-quality target))] - (distinct + (into + [] + (distinct-by first) (sort-by (fn [[w1 p1 f w2 p2 q]] [(- q) (- f)]) diff --git a/web/src/com/darklimericks/server/handlers.clj b/web/src/com/darklimericks/server/handlers.clj index c94b94f..3840d05 100644 --- a/web/src/com/darklimericks/server/handlers.clj +++ b/web/src/com/darklimericks/server/handlers.clj @@ -258,21 +258,21 @@ (fn [request] {:status 200 :headers {"Content-Type" "text/html; charset=utf-8"} - :body (views/wrapper - db - request - {} + :body (views/wrap-with-js + {:db db + :request request + :opts {}} (views/wgu request))})) (defn show-rhyme-suggestion [db cache] (fn [request] - (let [suggestions (linguistics/rhymes-with-frequencies + (let [suggestions (linguistics/rhymes-with-frequencies-and-rhyme-quality (:rhyme-target (:params request)) models/markov-trie models/database)] {:status 201 :headers {"Content-Type" "text/html; charset=utf-8"} - :body (views/wrapper + :body (views/wrap-with-js db request {} diff --git a/web/src/com/darklimericks/server/views.clj b/web/src/com/darklimericks/server/views.clj index 1f3866f..554d56d 100644 --- a/web/src/com/darklimericks/server/views.clj +++ b/web/src/com/darklimericks/server/views.clj @@ -85,6 +85,95 @@ num-artists)] [:a.washed-yellow.pl1 {:href "#"} "LINKS"]]]])))) +(defn wrap-with-js + ([{db :db + request :request + {title :title + js :js + css :css + :or {title "DarkLimericks" + css ["/assets/tachyons.css"] + js ["/assets/wgu-main.js"]} + :as opts} :opts} + & body] + (println (keys request)) + (let [num-albums (db.albums/num-albums db) + num-artists (db.artists/num-artists db)] + (page/html5 + [:head + [:meta {:charset "utf-8"}] + [:meta {:name "viewport" :content "width=device-width, initial-scale=1.0"}] + (apply page/include-css css) + (apply page/include-js js) + [:title title] + [:link {:rel "shortcut icon" :href "/assets/favicon.ico"}]] + [:body.tc.washed-yellow.bg-near-black.avenir + [:h1 + [:a.link.dim.washed-yellow {:href "/"} "DarkLimericks.com"]] + [:div.w-50-ns.w-90.center.bg-dark-gray.pa2 + [:div.f6.lh-copy.flex.justify-between + [:a.washed-yellow.pl1 + {:href (util/route-name->path + request + :com.darklimericks.server.router/submit)} + "SUBMIT LIMERICKS"] + [:span.dark-yellow + (format + "METAL LIMERICKS - CURRENTLY %d ALBUMS FROM %d+ BANDS" + num-albums + num-artists)] + [:a.washed-yellow.pr1 {:href "#"} "LINKS"]] + [:div.flex.items-stretch.bg-near-black.flex-wrap.flex-nowrap-l.f6 + (let [letters (map (comp str char) (range 97 123))] + (for [letter letters] + [:a.link.washed-yellow.bg-mid-gray.pv2.w1.w-100-ns.flex-auto + {:href (format "/%s.html" letter) + :style "margin: 1px;"} + [:strong (string/upper-case letter)]]))] + [:div.flex.items-center.justify-center.pv2 + [:span.f6.ph2 "Search the darkness for limericks most heartless"] + [:form.ph2 + {:method "GET" :action "#"} + [:input.bg-white.w4.w5-ns + {:type "text" + :name "search" + :id "search" + :value ""}]]] + [:div.bg-near-black.br4.pa2 + body] + + [:div.flex.items-center.justify-center.pv2 + [:span.f6.ph2 "Search the darkness for limericks most heartless"] + [:form.ph2 + {:method "GET" :action "#"} + [:input.bg-white.w4.w5-ns + {:type "text" + :name "search" + :id "search" + :value ""}]]] + [:div.flex.items-stretch.bg-near-black.flex-wrap.flex-nowrap-l.f6 + (let [letters (map (comp str char) (range 97 123))] + (for [letter letters] + [:a.link.washed-yellow.bg-mid-gray.pv2.w1.w-100-ns.flex-auto + {:href (format "/%s.html" letter) + :style "margin: 1px;"} + [:strong (string/upper-case letter)]]))] + + [:div.f6.lh-copy.flex.justify-between + [:a.washed-yellow.pr1 + {:href (util/route-name->path + request + :com.darklimericks.server.router/submit)} + "SUBMIT LIMERICKS"] + [:span.dark-yellow + (format + "METAL LIMERICKS - CURRENTLY %d ALBUMS FROM %d+ BANDS" + num-albums + num-artists)] + [:a.washed-yellow.pl1 {:href "#"} "LINKS"]]]])))) + + + (defn home [db request recent-albums artists-by-album] (wrapper db @@ -210,5 +299,5 @@ [request suggestions] [:div (wgu request) - (for [[suggestion freq] suggestions] - [:div suggestion freq])]) + (for [[suggestion p1 freq _ p2 quality] suggestions] + [:div (string/join " - " [suggestion freq p1 p2])])])