From 23ebc7edf0e909d04180173081eca24e6ac55027 Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 29 Jun 2016 15:12:19 -0400 Subject: [PATCH] add foil card count to stats page --- src/mtgcoll/client/routes/stats.cljs | 4 +++- src/mtgcoll/views/core.clj | 3 ++- src/mtgcoll/views/functions/statistics.clj | 11 +++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/mtgcoll/client/routes/stats.cljs b/src/mtgcoll/client/routes/stats.cljs index 8c83150..0bf052e 100644 --- a/src/mtgcoll/client/routes/stats.cljs +++ b/src/mtgcoll/client/routes/stats.cljs @@ -208,6 +208,7 @@ [online? pricing-source & [{:keys [width] :as options}]] (let [agg-price-stats (view-cursor :stats/agg-price-stats online? pricing-source) owned-total (view-cursor :stats/owned-total online?) + owned-foil-total (view-cursor :stats/owned-foil-total online?) distinct-owned-total (view-cursor :stats/distinct-owned-total online?) total-sets-owned-from (view-cursor :stats/total-sets-owned-from online?) total-sets-owned-all-from (view-cursor :stats/total-sets-owned-all-from online?) @@ -223,7 +224,8 @@ [widget-row [big-currency-statistic "Median Card Value" (:median_price @agg-price-stats)]] [widget-row [big-number-statistic "Cards Owned Over $1 Value" @num-worth-over-1-dollar]] [widget-row [big-number-statistic "Partial Sets" @total-sets-owned-from]] - [widget-row [big-number-statistic "Complete Sets" @total-sets-owned-all-from]]])) + [widget-row [big-number-statistic "Complete Sets" @total-sets-owned-all-from]] + [widget-row [big-number-statistic "Owned Foil Cards" @owned-foil-total]]])) (defonce settings (r/atom {:online? false diff --git a/src/mtgcoll/views/core.clj b/src/mtgcoll/views/core.clj index ed5e382..8fcf392 100644 --- a/src/mtgcoll/views/core.clj +++ b/src/mtgcoll/views/core.clj @@ -37,7 +37,8 @@ (view :card-pricing get-db #'prices/card-pricing) (view :pricing-sources get-db #'prices/pricing-sources) - (view :stats/owned-total get-db #'statistics/owned-total {:row-fn :sum :result-set-fn first}) + (view :stats/owned-total get-db #'statistics/owned-total {:row-fn :total :result-set-fn first}) + (view :stats/owned-foil-total get-db #'statistics/owned-foil-total {:row-fn :total :result-set-fn first}) (view :stats/distinct-owned-total get-db #'statistics/distinct-owned-total {:row-fn :count :result-set-fn first}) (view :stats/color-totals get-db #'statistics/color-totals {:result-set-fn first}) (view :stats/basic-type-totals get-db #'statistics/basic-type-totals {:result-set-fn first}) diff --git a/src/mtgcoll/views/functions/statistics.clj b/src/mtgcoll/views/functions/statistics.clj index ff6e5e2..f07875c 100644 --- a/src/mtgcoll/views/functions/statistics.clj +++ b/src/mtgcoll/views/functions/statistics.clj @@ -2,19 +2,26 @@ (defn owned-total [online?] - ["select sum(quantity) + ["select coalesce(sum(quantity), 0) as total from collection where online = ?" (boolean online?)]) (defn distinct-owned-total [online?] - ["select count(*) + ["select count(distinct c.id) from cards c join collection cl on c.id = cl.card_id where cl.quantity > 0 and cl.online = ?" (boolean online?)]) +(defn owned-foil-total + [online?] + ["select coalesce(sum(quantity), 0) as total + from collection + where online = ? and foil = true" + (boolean online?)]) + (defn color-totals [online?] (let [online? (boolean online?)]