Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(defn counts-per-day [intent-tap]
(<- [!intent !bucket !count]
(intent-tap _ !intent !ped)
(g/extract-true-as-of !ped :> !ms)
(o/time-buckets ["d"] !ms :> !bucket)
(c/count !count)))
(defn avg-sd [counts-per-day-sq min-avg]
(<- [!intent !a !sd]
(counts-per-day-sq !intent !bucket !count)
(sample-variance !count :> !v)
(>= !a min-avg)
(sqrt !v :> !sd)
(c/avg !count :> !a)))
(defn last-day-count [counts-per-day-sq date]
(<- [!intent !count]
(counts-per-day-sq !intent !bucket !count)
(= !bucket (str "d" date))))
(defn intent-metrics [avg-sd-sq last-day-count-sq]
(<- [!intent !count !avg !sd !ad !z-score !percent-diff]
(avg-sd-sq !intent !avg !sd )
(last-day-count-sq !intent !count)
(- !count !avg :> !diff)
(abs-dev !count !avg :> !ad)
(div-or-zero !diff !avg :> !p-diff)
(div-or-zero !diff !sd :> !z-score)
(percentify !p-diff :> !percent-diff)))
(defn intent-trend-metrics-paged [psn lookback-window date min-avg
sort-field page-size intent-tap]
(let [counts-per-day-sq (counts-per-day intent-tap)
avg-sd-sq (avg-sd counts-per-day-sq min-avg)
last-day-count-sq (last-day-count counts-per-day-sq date)
metrics-sq (intent-metrics avg-sd-sq last-day-count-sq)]
(<- [!ser-key !ser-val]
(metrics-sq !intent !count !avg !sd !ad !z-score !percent-diff)
(:sort sort-field)
(:reverse true)
(o/paged-trend-metrics [psn lookback-window page-size date]
!intent !count !avg !sd !ad !z-score !percent-diff
:> !key !val)
(o/serialize-thrift !key !val :> !ser-key !ser-val))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment