aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Perry <avaglir@gmail.com>2019-04-09 02:05:07 -0400
committerNathan Perry <avaglir@gmail.com>2019-04-09 02:05:07 -0400
commit74bd3dfdd7c57beb2bc84b6abaabd514558cba5d (patch)
tree071bd0d4d59f9095d1565c32ad6f222121f2585a
parent0a1ce5c5bb1bd6174e12bba971ebd8b3bc451b41 (diff)
report most popular random meme in stats
-rw-r--r--src/commands/meme/history.rs2
-rw-r--r--src/db/mod.rs20
2 files changed, 22 insertions, 0 deletions
diff --git a/src/commands/meme/history.rs b/src/commands/meme/history.rs
index 3064fd5..43deee3 100644
--- a/src/commands/meme/history.rs
+++ b/src/commands/meme/history.rs
@@ -178,6 +178,7 @@ and the loudest day was *{}* with **{}** audio memes
**{}** has invoked the most memes by name ({})
*{}* was the meme specifically requested the most ({})
+*{}* was the meme randomly invoked the most ({})
and *{}* was the most-memed overall ({})"#,
stats.memes_overall,
stats.audio_memes,
@@ -196,6 +197,7 @@ and *{}* was the most-memed overall ({})"#,
rand_user, stats.most_random_meme_user_count,
direct_user, stats.most_directly_named_meme_count,
stats.most_popular_named_meme, stats.most_popular_named_meme_count,
+ stats.most_popular_random_meme, stats.most_popular_random_meme_count,
stats.most_popular_meme_overall, stats.most_popular_meme_overall_count,
);
send(msg.channel_id, s, msg.tts)
diff --git a/src/db/mod.rs b/src/db/mod.rs
index a331ead..6cc09b4 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -272,6 +272,9 @@ pub struct Stats {
pub most_popular_named_meme: String,
pub most_popular_named_meme_count: usize,
+ pub most_popular_random_meme: String,
+ pub most_popular_random_meme_count: usize,
+
pub most_popular_meme_overall: String,
pub most_popular_meme_overall_count: usize,
}
@@ -407,6 +410,20 @@ pub fn stats(conn: &PgConnection) -> Result<Stats> {
let rows = raw_conn.query(r#"
SELECT memes.title, COUNT(*) FROM invocation_records
INNER JOIN memes ON meme_id = memes.id
+ WHERE random IS TRUE
+ GROUP BY memes.title
+ ORDER BY COUNT(*) DESC
+ LIMIT 1;
+ "#, &[])?;
+
+ let row = rows.get(0);
+
+ let most_random_meme = row.get(0);
+ let most_random_meme_count: i64 = row.get(1);
+
+ let rows = raw_conn.query(r#"
+ SELECT memes.title, COUNT(*) FROM invocation_records
+ INNER JOIN memes ON meme_id = memes.id
GROUP BY memes.title
ORDER BY COUNT(*) DESC
LIMIT 1;
@@ -439,6 +456,9 @@ pub fn stats(conn: &PgConnection) -> Result<Stats> {
most_popular_named_meme: most_requested_meme,
most_popular_named_meme_count: most_requested_meme_count as usize,
+ most_popular_random_meme: most_random_meme,
+ most_popular_random_meme_count: most_random_meme_count as usize,
+
most_popular_meme_overall: most_invoked_meme,
most_popular_meme_overall_count: most_invoked_meme_count as usize,
})