diff options
| author | Nathan Perry <avaglir@gmail.com> | 2019-03-29 18:11:47 -0400 |
|---|---|---|
| committer | Nathan Perry <avaglir@gmail.com> | 2019-03-29 18:11:47 -0400 |
| commit | 4b57515192631b29c0e95847bab5667d70353435 (patch) | |
| tree | ceddc5713842e030f7fe2c14130e1e070cf06005 | |
| parent | 122e3e22330d961fc3f3f35c117f8c64d592bf36 (diff) | |
improved stats output
| -rw-r--r-- | Cargo.lock | 147 | ||||
| -rw-r--r-- | Cargo.toml | 5 | ||||
| -rw-r--r-- | src/commands/meme/history.rs | 28 | ||||
| -rw-r--r-- | src/db/mod.rs | 139 | ||||
| -rw-r--r-- | src/main.rs | 4 |
5 files changed, 317 insertions, 6 deletions
@@ -94,6 +94,15 @@ dependencies = [ [[package]] name = "base64" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "base64" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ @@ -245,6 +254,11 @@ dependencies = [ ] [[package]] +name = "constant_time_eq" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "core-foundation" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -317,6 +331,15 @@ dependencies = [ ] [[package]] +name = "crypto-mac" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "ctrlc" version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -469,6 +492,11 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "fallible-iterator" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "fern" version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -570,6 +598,20 @@ dependencies = [ ] [[package]] +name = "hex" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "hmac" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crypto-mac 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "http" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -799,6 +841,11 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "md5" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "memchr" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1201,6 +1248,49 @@ version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "postgres" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "fallible-iterator 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "postgres-protocol 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "postgres-shared 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "postgres-protocol" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "fallible-iterator 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hmac 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "md5 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "stringprep 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "postgres-shared" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "fallible-iterator 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)", + "postgres-protocol 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "pq-sys" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1274,6 +1364,16 @@ dependencies = [ ] [[package]] +name = "r2d2_postgres" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", + "postgres-shared 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "r2d2 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "rand" version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1670,6 +1770,17 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "sha2" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", + "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "siphasher" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1685,6 +1796,17 @@ version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "socket2" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "sodiumoxide" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1712,6 +1834,15 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "stringprep" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "strsim" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1854,6 +1985,8 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", + "r2d2_postgres 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2235,6 +2368,7 @@ dependencies = [ "checksum backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5a90e2b463010cd0e0ce9a11d4a9d5d58d9f41d4a6ba3dcaf9e68b466e88b4" "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" +"checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum base64 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c4a342b450b268e1be8036311e2c613d7f8a7ed31214dff1cc3b60852a3168d" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bindgen 0.37.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1b25ab82877ea8fe6ce1ce1f8ac54361f0218bad900af9eb11803994bf67c221" @@ -2252,6 +2386,7 @@ dependencies = [ "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum colored 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e9a455e156a4271e12fd0246238c380b1e223e3736663c7a18ed8b6362028a9" +"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" "checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980" "checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa" "checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" @@ -2260,6 +2395,7 @@ dependencies = [ "checksum crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04c9e3102cc2d69cd681412141b390abd55a362afc1540965dad0ad4d34280b4" "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" +"checksum crypto-mac 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0999b4ff4d3446d4ddb19a63e9e00c1876e75cd7000d20e57a693b4b3f08d958" "checksum ctrlc 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "630391922b1b893692c6334369ff528dcc3a9d8061ccf4c803aa8f83cb13db5e" "checksum diesel 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a2469cbcf1dfb9446e491cac4c493c2554133f87f7d041e892ac82e5cd36e863" "checksum diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62a27666098617d52c487a41f70de23d44a1dc1f3aa5877ceba2790fb1f1cab4" @@ -2276,6 +2412,7 @@ dependencies = [ "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +"checksum fallible-iterator 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eb7217124812dc5672b7476d0c2d20cfe9f7c0f1ba0904b674a9762a0212f72e" "checksum fern 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b48af88aaf938b11baef948a5599e66e709cf92854aa2b87c71f1bcf20f80a01" "checksum flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2291c165c8e703ee54ef3055ad6188e3d51108e2ded18e9f2476e774fc5ad3d4" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" @@ -2289,6 +2426,8 @@ dependencies = [ "checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum h2 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ddb2b25a33e231484694267af28fec74ac63b5ccf51ee2065a5e313b834d836e" +"checksum hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6a22814455d41612f41161581c2883c0c6a1c41852729b17d5ed88f01e153aa" +"checksum hmac 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44f3bdb08579d99d7dc761c0e266f13b5f2ab8c8c703b9fc9ef333cd8f48f55e" "checksum http 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "fe67e3678f2827030e89cc4b9e7ecd16d52f132c0b940ab5005f88e821500f6a" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" @@ -2315,6 +2454,7 @@ dependencies = [ "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +"checksum md5 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "79c56d6a0b07f9e19282511c83fc5b086364cbae4ba8c7d5f190c3d9b0425a48" "checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" @@ -2359,6 +2499,9 @@ dependencies = [ "checksum phf_generator 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662" "checksum phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" +"checksum postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "115dde90ef51af573580c035857badbece2aa5cde3de1dfb3c932969ca92a6c5" +"checksum postgres-protocol 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2487e66455bf88a1b247bf08a3ce7fe5197ac6d67228d920b0ee6a0e97fd7312" +"checksum postgres-shared 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ffac35b3e0029b404c24a3b82149b4e904f293e8ca4a327eefa24d3ca50df36f" "checksum pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda" "checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8" "checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a" @@ -2369,6 +2512,7 @@ dependencies = [ "checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8" "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" "checksum r2d2 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5d746fc8a0dab19ccea7ff73ad535854e90ddb3b4b8cdce953dd5cd0b2e7bd22" +"checksum r2d2_postgres 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "78c7fe9c0c3d2c298cf262bc3ce4b89cdf0eab620fd9fe759f65b34a1a00fb93" "checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" @@ -2411,13 +2555,16 @@ dependencies = [ "checksum sha-1 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "51b9d1f3b5de8a167ab06834a7c883bd197f2191e1dda1a22d9ccfeedbf9aded" "checksum sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc30b1e1e8c40c121ca33b86c23308a090d19974ef001b4bf6e61fd1a0fb095c" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" +"checksum sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0" "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" +"checksum socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d11a52082057d87cb5caa31ad812f4504b97ab44732cd8359df2e9ff9f48e7" "checksum sodiumoxide 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71c0682b4406fa25d621b19d2e70b5f6c8627e39b4b7ce0e24b2ef05d0fbe1ca" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum statrs 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "10102ac8d55e35db2b3fafc26f81ba8647da2e15879ab686a67e6d19af2685e8" "checksum string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b639411d0b9c738748b5397d5ceba08e648f4f1992231aa859af1a017f31f60b" +"checksum stringprep 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)" = "525bd55255f03c816e5d7f615587bd13030c7103354fadb104993dcee6a788ec" @@ -4,7 +4,8 @@ version = "0.1.6" authors = ["Nathan Perry <avaglir@gmail.com>"] [features] -default = ["diesel", "games"] +default = ["db", "games"] +db = ["diesel", "postgres", "r2d2_postgres"] games = [] [dependencies] @@ -33,6 +34,8 @@ statrs = "^0.10" fnv = "~1.0" pest = "~2.1" pest_derive = "~2.1" +postgres = { version = "^0.15", optional = true, features = ["with-chrono"] } +r2d2_postgres = { version = "^0.14", optional = true } [dependencies.serenity] default-features = false diff --git a/src/commands/meme/history.rs b/src/commands/meme/history.rs index 051040f..28e4aaa 100644 --- a/src/commands/meme/history.rs +++ b/src/commands/meme/history.rs @@ -141,12 +141,23 @@ pub fn history(_: &mut Context, msg: &Message, mut args: Args) -> Result<()> { pub fn stats(_: &mut Context, msg: &Message, _: Args) -> Result<()> { use db; use chrono; + use serenity::model::{ + id::UserId, + user::User, + }; + use crate::TARGET_GUILD_ID; let conn = connection()?; let stats = db::stats(&conn)?; debug!("reporting stats"); + let rand_user: User = UserId(stats.most_random_meme_user).to_user()?; + let direct_user: User = UserId(stats.most_directly_named_meme_user).to_user()?; + + let rand_user = rand_user.nick_in(*TARGET_GUILD_ID).unwrap_or(rand_user.name); + let direct_user = direct_user.nick_in(*TARGET_GUILD_ID).unwrap_or(direct_user.name); + let s = format!( r#" {} memes total @@ -156,7 +167,16 @@ pub fn stats(_: &mut Context, msg: &Message, _: Args) -> Result<()> { started recording meme invocations on {} ({}) {} total meme invocations recorded {} of which were random ({:0.1}%) -and {} were audio ({:0.1}%)"#, +and {} were audio ({:0.1}%) + +the most active day was {} with {} memes +and the loudest day was {} with {} audio memes + +{} has invoked the most random memes ({}) +{} has invoked the most memes by name ({}) + +{} was the meme most requested by name ({}) +and {} was the most-memed overall ({})"#, stats.memes_overall, stats.audio_memes, (stats.audio_memes as f64) / (stats.memes_overall as f64) * 100., @@ -169,6 +189,12 @@ and {} were audio ({:0.1}%)"#, (stats.random_meme_invocations as f64) / (stats.total_meme_invocations as f64) * 100., stats.audio_meme_invocations, (stats.audio_meme_invocations as f64) / (stats.total_meme_invocations as f64) * 100., + stats.most_active_day, stats.most_active_day_count, + stats.most_audio_active_day, stats.most_audio_active_count, + 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_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 191b9e9..cd71e9e 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -4,6 +4,7 @@ use std::{ }; use chrono::{ + Date, DateTime, Utc, }; @@ -12,6 +13,10 @@ use diesel::{ prelude::*, r2d2::{ConnectionManager, ManageConnection}, }; +use r2d2_postgres::{ + PostgresConnectionManager as RawPgConnMgr, + TlsMode, +}; use crate::{Error, Result}; @@ -24,6 +29,7 @@ mod models; lazy_static! { static ref DB_URL: String = env::var("DATABASE_URL").expect("no database url in environment").into(); static ref CONN_MGR: ConnectionManager<PgConnection> = ConnectionManager::new(DB_URL.clone()); + static ref RAW_CONN_MGR: RawPgConnMgr = RawPgConnMgr::new(DB_URL.clone(), TlsMode::None).unwrap(); } pub fn connection() -> Result<PgConnection> { @@ -179,7 +185,7 @@ pub fn rand_silent_meme(conn: &PgConnection) -> Result<Meme> { .map_err(Error::from) } -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Clone)] pub struct Stats { pub memes_overall: usize, pub audio_memes: usize, @@ -188,11 +194,41 @@ pub struct Stats { pub total_meme_invocations: usize, pub audio_meme_invocations: usize, pub random_meme_invocations: usize, + + pub most_active_day: Date<Utc>, + pub most_active_day_count: usize, + + pub most_audio_active_day: Date<Utc>, + pub most_audio_active_count: usize, + + pub most_random_meme_user: u64, + pub most_random_meme_user_count: usize, + pub most_directly_named_meme_user: u64, + pub most_directly_named_meme_count: usize, + + pub most_popular_named_meme: String, + pub most_popular_named_meme_count: usize, + + pub most_popular_meme_overall: String, + pub most_popular_meme_overall_count: usize, } pub fn stats(conn: &PgConnection) -> Result<Stats> { use diesel::dsl::{count_star, count}; - use chrono::NaiveDateTime; + use chrono::{ + NaiveDateTime, + NaiveDate, + }; + + #[inline] + fn to_utc(ndt: NaiveDateTime) -> DateTime<Utc> { + DateTime::from_utc(ndt, Utc{}) + } + + #[inline] + fn to_utc_date(nd: NaiveDate) -> Date<Utc> { + Date::from_utc(nd, Utc{}) + } let total_count: i64 = memes::table .select(count_star()) @@ -217,7 +253,7 @@ pub fn stats(conn: &PgConnection) -> Result<Stats> { .first(conn) .map_err(Error::from)?; - let started_recording = DateTime::from_utc(started_recording, Utc{}); + let started_recording = to_utc(started_recording); let total_meme_invocations: i64 = invocation_records::table .select(count_star()) @@ -237,6 +273,87 @@ pub fn stats(conn: &PgConnection) -> Result<Stats> { .first(conn) .map_err(Error::from)?; + let raw_conn = RAW_CONN_MGR.connect().map_err(Error::from)?; + + let rows = raw_conn.query(r#" + SELECT DATE(time) as dt, COUNT(*) FROM invocation_records + GROUP BY dt + ORDER BY COUNT(*) DESC + LIMIT 1; + "#, &[])?; + + let row = rows.get(0); + + let most_active_day = to_utc_date(row.get(0)); + let most_active_day_count: i64 = row.get(1); + + let rows = raw_conn.query(r#" + SELECT DATE(time) as dt, COUNT(*) FROM invocation_records + INNER JOIN memes ON invocation_records.meme_id = memes.id + WHERE memes.audio_id IS NOT NULL + GROUP BY dt + ORDER BY COUNT(*) DESC + LIMIT 1; + "#, &[])?; + + let row = rows.get(0); + + let most_active_audio_day = to_utc_date(row.get(0)); + let most_active_audio_day_count: i64 = row.get(1); + + let rows = raw_conn.query(r#" + SELECT user_id, COUNT(*) FROM invocation_records + WHERE random IS TRUE + GROUP BY user_id + ORDER BY COUNT(*) DESC + LIMIT 1; + "#, &[])?; + + let row = rows.get(0); + + let most_random_invoker: i64 = row.get(0); + let most_random_invoker_count: i64 = row.get(1); + + let rows = raw_conn.query(r#" + SELECT user_id, COUNT(*) FROM invocation_records + WHERE random IS FALSE + GROUP BY user_id + ORDER BY COUNT(*) DESC + LIMIT 1; + "#, &[])?; + + let row = rows.get(0); + + let most_specific_invoker: i64 = row.get(0); + let most_specific_invoker_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 + WHERE random IS FALSE + GROUP BY memes.title + ORDER BY COUNT(*) DESC + LIMIT 1; + "#, &[])?; + + let row = rows.get(0); + + let most_requested_meme = row.get(0); + let most_requested_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; + "#, &[])?; + + let row = rows.get(0); + + let most_invoked_meme = row.get(0); + let most_invoked_meme_count: i64 = row.get(1); + Ok(Stats { memes_overall: total_count as usize, image_memes: image_count as usize, @@ -245,5 +362,21 @@ pub fn stats(conn: &PgConnection) -> Result<Stats> { total_meme_invocations: total_meme_invocations as usize, audio_meme_invocations: audio_meme_invocations as usize, random_meme_invocations: random_meme_invocations as usize, + + most_active_day, + most_active_day_count: most_active_day_count as usize, + most_audio_active_day: most_active_audio_day, + most_audio_active_count: most_active_audio_day_count as usize, + + most_random_meme_user: most_random_invoker as u64, + most_random_meme_user_count: most_random_invoker_count as usize, + most_directly_named_meme_user: most_specific_invoker as u64, + most_directly_named_meme_count: most_specific_invoker_count as usize, + + most_popular_named_meme: most_requested_meme, + most_popular_named_meme_count: most_requested_meme_count as usize, + + most_popular_meme_overall: most_invoked_meme, + most_popular_meme_overall_count: most_invoked_meme_count as usize, }) } diff --git a/src/main.rs b/src/main.rs index 1d1c6dd..d3458b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ #![feature(box_syntax, box_patterns)] extern crate chrono; -#[cfg(feature = "diesel")] +#[cfg(feature = "db")] #[macro_use] extern crate diesel; extern crate dotenv; #[macro_use] extern crate dotenv_codegen; @@ -20,6 +20,8 @@ extern crate fnv; #[macro_use] extern crate log; extern crate pest; #[macro_use] extern crate pest_derive; +#[cfg(feature = "db")] extern crate postgres; +#[cfg(feature = "db")] extern crate r2d2_postgres; extern crate rand; extern crate regex; extern crate reqwest; |
