From 24d3e0eaee0757f5b220ed371790dab6f20a71e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Delattre?= Date: Mon, 14 Aug 2017 01:11:27 +0200 Subject: [PATCH] Add torrents stats --- src/internal/admins/stats.go | 24 +++++++++++---- src/public/js/components/admins/stats.js | 37 ++++++++++++++++++++---- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/internal/admins/stats.go b/src/internal/admins/stats.go index 0897d2c..b33e735 100644 --- a/src/internal/admins/stats.go +++ b/src/internal/admins/stats.go @@ -9,9 +9,13 @@ import ( ) const ( - moviesCountQuery = `SELECT COUNT(*) FROM movies;` - showsCountQuery = `SELECT COUNT(*) FROM shows;` - episodesCountQuery = `SELECT COUNT(*) FROM episodes;` + moviesCountQuery = `SELECT COUNT(*) FROM movies;` + moviesTorrentsCountByIDQuery = `SELECT COUNT(*) FROM (SELECT DISTINCT(imdb_id) FROM movie_torrents) as TMP;` + moviesTorrentsCountQuery = `SELECT COUNT(*) FROM movie_torrents;` + showsCountQuery = `SELECT COUNT(*) FROM shows;` + episodesCountQuery = `SELECT COUNT(*) FROM episodes;` + episodesTorrentsCountByIDQuery = `SELECT COUNT(*) FROM (SELECT DISTINCT(imdb_id) FROM episode_torrents) as TMP;` + episodesTorrentsCountQuery = `SELECT COUNT(*) FROM episode_torrents;` ) // GetCount gets the count from a query @@ -33,9 +37,13 @@ func GetStatsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error log.Debug("getting stats") stats := struct { - MoviesCount int `json:"movies_count"` - ShowsCount int `json:"shows_count"` - EpisodesCount int `json:"episodes_count"` + MoviesCount int `json:"movies_count"` + MoviesTorrentsCount int `json:"movies_torrents_count"` + MoviesTorrentsCountByID int `json:"movies_torrents_count_by_id"` + ShowsCount int `json:"shows_count"` + EpisodesCount int `json:"episodes_count"` + EpisodesTorrentsCount int `json:"episodes_torrents_count"` + EpisodesTorrentsCountByID int `json:"episodes_torrents_count_by_id"` }{} for _, s := range []struct { @@ -43,8 +51,12 @@ func GetStatsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error ptr *int }{ {moviesCountQuery, &stats.MoviesCount}, + {moviesTorrentsCountQuery, &stats.MoviesTorrentsCount}, + {moviesTorrentsCountByIDQuery, &stats.MoviesTorrentsCountByID}, {showsCountQuery, &stats.ShowsCount}, {episodesCountQuery, &stats.EpisodesCount}, + {episodesTorrentsCountQuery, &stats.EpisodesTorrentsCount}, + {episodesTorrentsCountByIDQuery, &stats.EpisodesTorrentsCountByID}, } { var err error *s.ptr, err = GetCount(env.Database, s.query) diff --git a/src/public/js/components/admins/stats.js b/src/public/js/components/admins/stats.js index 3993dbb..4b0b145 100644 --- a/src/public/js/components/admins/stats.js +++ b/src/public/js/components/admins/stats.js @@ -4,9 +4,19 @@ export default function Stats(props) { return (

Stats

- - - + + +
); } @@ -16,12 +26,29 @@ function Stat(props) {
-

{props.name}

+

+ {props.name} + {props.count} +

- {props.value} +
); } + +function TorrentsStat(props) { + if (props.data.torrentCount === undefined) { + return (No torrents); + } + + const percentage = Math.floor((props.data.torrentCount * 100) / props.data.count); + return ( + + {percentage}% with torrents +   - {props.data.torrentCount} total + + ); +}